| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Migrations\Versions; |
| 4 |
|
| 5 |
use SyncBasalam\Migrations\MigrationInterface; |
| 6 |
|
| 7 |
defined('ABSPATH') || exit; |
| 8 |
|
| 9 |
class Migration_1_6_2 implements MigrationInterface |
| 10 |
{ |
| 11 |
public function up() |
| 12 |
{ |
| 13 |
global $wpdb; |
| 14 |
$tableName = $wpdb->prefix . 'sync_basalam_category_mappings'; |
| 15 |
|
| 16 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom plugin table; identifier from $wpdb->prefix, not user input. |
| 17 |
$oldDataExists = $wpdb->get_var("SHOW COLUMNS FROM $tableName LIKE 'basalam_category_id'"); |
| 18 |
|
| 19 |
if (!$oldDataExists) return; |
| 20 |
|
| 21 |
$this->addNewColumns($wpdb, $tableName); |
| 22 |
|
| 23 |
$this->removeOldColumn($wpdb, $tableName); |
| 24 |
} |
| 25 |
|
| 26 |
private function addNewColumns($wpdb, $tableName) |
| 27 |
{ |
| 28 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Migration schema change on own plugin table; identifier from $wpdb->prefix, not user input. |
| 29 |
$wpdb->query("ALTER TABLE $tableName |
| 30 |
ADD COLUMN basalam_category_level1 INT(11) DEFAULT NULL AFTER woo_category_name, |
| 31 |
ADD COLUMN basalam_category_level2 INT(11) DEFAULT NULL AFTER basalam_category_level1, |
| 32 |
ADD COLUMN basalam_category_level3 INT(11) DEFAULT NULL AFTER basalam_category_level2 |
| 33 |
"); |
| 34 |
|
| 35 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Migration schema change on own plugin table; identifier from $wpdb->prefix, not user input. |
| 36 |
$wpdb->query("ALTER TABLE $tableName |
| 37 |
ADD INDEX basalam_category_level1_idx (basalam_category_level1) |
| 38 |
"); |
| 39 |
} |
| 40 |
|
| 41 |
private function removeOldColumn($wpdb, $tableName) |
| 42 |
{ |
| 43 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Migration schema change on own plugin table; identifier from $wpdb->prefix, not user input. |
| 44 |
$wpdb->query("ALTER TABLE $tableName DROP INDEX basalam_category_idx"); |
| 45 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Migration schema change on own plugin table; identifier from $wpdb->prefix, not user input. |
| 46 |
$wpdb->query("ALTER TABLE $tableName DROP COLUMN basalam_category_id"); |
| 47 |
} |
| 48 |
} |
| 49 |
|