| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/AIWEBSTATION/wp-content/plugins/fluent-crm/database/migrations/ |
Upload File : |
<?php
namespace FluentCrmMigrations;
class Meta
{
/**
* Migrate the table.
*
* @return void
*/
public static function migrate()
{
global $wpdb;
$charsetCollate = $wpdb->get_charset_collate();
$table = $wpdb->prefix .'fc_meta';
$indexPrefix = $wpdb->prefix .'fc_mt_';
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$sql = "CREATE TABLE $table (
`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`object_type` VARCHAR(50) NOT NULL,
`object_id` BIGINT NULL,
`key` VARCHAR(192) NOT NULL,
`value` LONGTEXT NULL,
`created_at` TIMESTAMP NULL,
`updated_at` TIMESTAMP NULL,
INDEX `{$indexPrefix}_mt_idx` (`object_type` ASC),
INDEX `{$indexPrefix}_mto_id_idx` (`object_id` ASC),
INDEX `{$indexPrefix}_mto_id_key` (`key` )
) $charsetCollate;";
dbDelta($sql);
} else {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$indexes = $wpdb->get_results("SHOW INDEX FROM $table");
$indexedColumns = [];
foreach ($indexes as $index) {
$indexedColumns[] = $index->Column_name;
}
if(!in_array('key', $indexedColumns)) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query("ALTER TABLE {$table} ADD INDEX `{$indexPrefix}_mto_id_key` (`key`);");
}
}
}
}