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 / AddShowEmptyFieldsToNotifications.php

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

67 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 use IvyForms\Common\Exceptions\InvalidArgumentException;
6 use IvyForms\Services\InstallActions\DB\Notification\NotificationsTable;
7 use IvyForms\Services\Translations\BackendStrings;
8
9 class AddShowEmptyFieldsToNotifications
10 {
11 /**
12 * Run the migration
13 *
14 * @return bool
15 * @throws InvalidArgumentException
16 */
17 public static function run(): bool
18 {
19 global $wpdb;
20
21 $tableName = NotificationsTable::getTableName();
22
23 // Check if showEmptyFields column already exists
24 $columnExists = $wpdb->get_results(
25 "SHOW COLUMNS FROM `{$tableName}` LIKE 'showEmptyFields'"
26 );
27
28 if (!empty($columnExists)) {
29 return true; // Already migrated
30 }
31
32 // Add showEmptyFields column after message
33 $alterQuery = "ALTER TABLE `{$tableName}` ADD COLUMN `showEmptyFields` INT(1) NULL DEFAULT 0 AFTER `message`";
34
35 $result = $wpdb->query($alterQuery);
36
37 if ($result === false) {
38 error_log(sprintf(
39 BackendStrings::getExceptionStrings()['migration_error_add_column'],
40 'showEmptyFields',
41 $tableName
42 ));
43 return false;
44 }
45
46 return true;
47 }
48
49 /**
50 * Rollback the migration
51 *
52 * @return bool
53 */
54 public static function rollback(): bool
55 {
56 global $wpdb;
57
58 $tableName = NotificationsTable::getTableName();
59
60 $alterQuery = "ALTER TABLE `{$tableName}` DROP COLUMN `showEmptyFields`";
61
62 $result = $wpdb->query($alterQuery);
63
64 return $result !== false;
65 }
66 }
67