PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.20
ووسلام – همگام سازی ووکامرس و باسلام v1.10.20
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Migrations / Versions / Migration_1_6_2.php

Migration_1_6_2.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.20, at includes/Migrations/Versions/Migration_1_6_2.php

49 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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