PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / InstallActions / Migrations / AddStyleSettingsToForms.php

AddStyleSettingsToForms.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Services/InstallActions/Migrations/AddStyleSettingsToForms.php

56 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\InstallActions\Migrations;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\InvalidArgumentException;
11 use IvyForms\Services\InstallActions\DB\Form\FormsTable;
12 use IvyForms\Services\Translations\BackendStrings;
13
14 class AddStyleSettingsToForms
15 {
16 /**
17 * Run the migration
18 *
19 * @return bool
20 * @throws InvalidArgumentException
21 */
22 public static function run(): bool
23 {
24 global $wpdb;
25 $tableName = FormsTable::getTableName();
26 // Check if styleSettings column already exists
27 $columnExists = $wpdb->get_results(
28 "SHOW COLUMNS FROM `{$tableName}` LIKE 'styleSettings'"
29 );
30 if (!empty($columnExists)) {
31 return true; // Already migrated
32 }
33 // Add styleSettings column
34 $alterQuery = "ALTER TABLE `{$tableName}` ADD COLUMN `styleSettings` TEXT NULL AFTER `integrationSettings`";
35 $result = $wpdb->query($alterQuery);
36 if ($result === false) {
37 error_log(sprintf(
38 BackendStrings::getExceptionStrings()['migration_error_add_column'],
39 'styleSettings',
40 $tableName
41 ));
42 return false;
43 }
44 return true;
45 }
46
47 public static function rollback(): bool
48 {
49 global $wpdb;
50 $tableName = FormsTable::getTableName();
51 $alterQuery = "ALTER TABLE `{$tableName}` DROP COLUMN `styleSettings`";
52 $result = $wpdb->query($alterQuery);
53 return $result !== false;
54 }
55 }
56