Plugin Directory

Changeset 3463308


Ignore:
Timestamp:
02/17/2026 10:12:53 AM (6 weeks ago)
Author:
esaia
Message:

tagging 2.2.0

Location:
interactive-real-estate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • interactive-real-estate/tags/2.2.0/includes/migrations.php

    r3463284 r3463308  
    99{
    1010    global $wpdb;
     11   
    1112    // Check if $wpdb is an instance of an SQLite class
    1213    if (isset($wpdb) && is_object($wpdb)) {
     
    1516            return true;
    1617        }
     18    }
     19
     20    // Check for WordPress Playground SQLite integration
     21    if (defined('WP_SQLITE_DB_PATH') || class_exists('WP_SQLite_DB') || class_exists('WP_PDO_MySQL_On_SQLite')) {
     22        return true;
     23    }
     24
     25    // Check database name/type
     26    if (defined('DB_NAME') && (strpos(DB_NAME, '.sqlite') !== false || strpos(DB_NAME, '.db') !== false)) {
     27        return true;
    1728    }
    1829
     
    2940    }
    3041
     42    // Try to detect by querying database type
     43    if (isset($wpdb) && is_object($wpdb)) {
     44        try {
     45            $db_type = $wpdb->get_var("SELECT sqlite_version()");
     46            if ($db_type !== null) {
     47                return true;
     48            }
     49        } catch (Exception $e) {
     50            // Not SQLite, continue
     51        }
     52    }
     53
    3154    return false;
    3255}
     
    5679    $json_type = 'LONGTEXT';
    5780
     81    // For SQLite (WordPress Playground), use MySQL syntax but avoid ON UPDATE CURRENT_TIMESTAMP
     82    // WordPress Playground's SQLite integration expects MySQL syntax and translates it
     83    $updated_at_sql = $is_sqlite
     84        ? 'updated_at DATETIME DEFAULT CURRENT_TIMESTAMP'
     85        : 'updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP';
     86
    5887    // Projects table
    5988    $projects_sql = "CREATE TABLE $projects_table (
     
    6594        polygon_data $json_type,
    6695        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    67         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     96        $updated_at_sql,
    6897        PRIMARY KEY (id)
    6998    ) $charset_collate;";
    7099    dbDelta($projects_sql);
    71 
    72100    // Blocks table
    73101    $blocks_sql = "CREATE TABLE $blocks_table (
     
    80108        project_id BIGINT(20) UNSIGNED NOT NULL,
    81109        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    82         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     110        $updated_at_sql,
    83111        PRIMARY KEY (id)
    84112    ) $charset_collate;";
     
    97125        block_id BIGINT(20) UNSIGNED,
    98126        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    99         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     127        $updated_at_sql,
    100128        PRIMARY KEY (id),
    101129        UNIQUE KEY unique_floor (project_id, floor_number, block_id)
     
    116144        other $json_type,
    117145        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    118         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     146        $updated_at_sql,
    119147        PRIMARY KEY (id)
    120148    ) $charset_collate;";
     
    124152    $flats_sql = "CREATE TABLE $flats_table (
    125153        id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    126         is_active TINYINT(1) DEFAULT 1, 
     154        is_active TINYINT(1) DEFAULT 1,
    127155        block_id BIGINT(20) UNSIGNED,
    128156        floor_id BIGINT(20) UNSIGNED,
     
    140168        files $json_type,
    141169        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    142         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     170        $updated_at_sql,
    143171        PRIMARY KEY (id)
    144172    ) $charset_collate;";
     
    152180        meta_value TEXT NOT NULL,
    153181        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    154         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     182        $updated_at_sql,
    155183        PRIMARY KEY (id)
    156184    ) $charset_collate;";
     
    164192        data $json_type,
    165193        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    166         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     194        $updated_at_sql,
    167195        PRIMARY KEY (id)
    168196    ) $charset_collate;";
     
    178206        comment TEXT,
    179207        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    180         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     208        $updated_at_sql,
    181209        PRIMARY KEY (id)
    182210    ) $charset_collate;";
     
    261289    }
    262290
    263     // Enable foreign keys for SQLite
    264     if ($is_sqlite) {
    265         $wpdb->query('PRAGMA foreign_keys = ON;');
    266     }
     291    // Note: Foreign keys are handled by WordPress Playground's SQLite integration automatically
    267292}
  • interactive-real-estate/trunk/includes/migrations.php

    r3463284 r3463308  
    99{
    1010    global $wpdb;
     11   
    1112    // Check if $wpdb is an instance of an SQLite class
    1213    if (isset($wpdb) && is_object($wpdb)) {
     
    1516            return true;
    1617        }
     18    }
     19
     20    // Check for WordPress Playground SQLite integration
     21    if (defined('WP_SQLITE_DB_PATH') || class_exists('WP_SQLite_DB') || class_exists('WP_PDO_MySQL_On_SQLite')) {
     22        return true;
     23    }
     24
     25    // Check database name/type
     26    if (defined('DB_NAME') && (strpos(DB_NAME, '.sqlite') !== false || strpos(DB_NAME, '.db') !== false)) {
     27        return true;
    1728    }
    1829
     
    2940    }
    3041
     42    // Try to detect by querying database type
     43    if (isset($wpdb) && is_object($wpdb)) {
     44        try {
     45            $db_type = $wpdb->get_var("SELECT sqlite_version()");
     46            if ($db_type !== null) {
     47                return true;
     48            }
     49        } catch (Exception $e) {
     50            // Not SQLite, continue
     51        }
     52    }
     53
    3154    return false;
    3255}
     
    5679    $json_type = 'LONGTEXT';
    5780
     81    // For SQLite (WordPress Playground), use MySQL syntax but avoid ON UPDATE CURRENT_TIMESTAMP
     82    // WordPress Playground's SQLite integration expects MySQL syntax and translates it
     83    $updated_at_sql = $is_sqlite
     84        ? 'updated_at DATETIME DEFAULT CURRENT_TIMESTAMP'
     85        : 'updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP';
     86
    5887    // Projects table
    5988    $projects_sql = "CREATE TABLE $projects_table (
     
    6594        polygon_data $json_type,
    6695        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    67         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     96        $updated_at_sql,
    6897        PRIMARY KEY (id)
    6998    ) $charset_collate;";
    7099    dbDelta($projects_sql);
    71 
    72100    // Blocks table
    73101    $blocks_sql = "CREATE TABLE $blocks_table (
     
    80108        project_id BIGINT(20) UNSIGNED NOT NULL,
    81109        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    82         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     110        $updated_at_sql,
    83111        PRIMARY KEY (id)
    84112    ) $charset_collate;";
     
    97125        block_id BIGINT(20) UNSIGNED,
    98126        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    99         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     127        $updated_at_sql,
    100128        PRIMARY KEY (id),
    101129        UNIQUE KEY unique_floor (project_id, floor_number, block_id)
     
    116144        other $json_type,
    117145        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    118         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     146        $updated_at_sql,
    119147        PRIMARY KEY (id)
    120148    ) $charset_collate;";
     
    124152    $flats_sql = "CREATE TABLE $flats_table (
    125153        id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    126         is_active TINYINT(1) DEFAULT 1, 
     154        is_active TINYINT(1) DEFAULT 1,
    127155        block_id BIGINT(20) UNSIGNED,
    128156        floor_id BIGINT(20) UNSIGNED,
     
    140168        files $json_type,
    141169        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    142         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     170        $updated_at_sql,
    143171        PRIMARY KEY (id)
    144172    ) $charset_collate;";
     
    152180        meta_value TEXT NOT NULL,
    153181        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    154         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     182        $updated_at_sql,
    155183        PRIMARY KEY (id)
    156184    ) $charset_collate;";
     
    164192        data $json_type,
    165193        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    166         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     194        $updated_at_sql,
    167195        PRIMARY KEY (id)
    168196    ) $charset_collate;";
     
    178206        comment TEXT,
    179207        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    180         updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     208        $updated_at_sql,
    181209        PRIMARY KEY (id)
    182210    ) $charset_collate;";
     
    261289    }
    262290
    263     // Enable foreign keys for SQLite
    264     if ($is_sqlite) {
    265         $wpdb->query('PRAGMA foreign_keys = ON;');
    266     }
     291    // Note: Foreign keys are handled by WordPress Playground's SQLite integration automatically
    267292}
Note: See TracChangeset for help on using the changeset viewer.