PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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 / AddReplyToToNotifications.php

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

62 lines 1.5 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 AddReplyToToNotifications
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 replyTo column already exists
24 $columnExists = $wpdb->get_results(
25 "SHOW COLUMNS FROM `{$tableName}` LIKE 'replyTo'"
26 );
27
28 if (!empty($columnExists)) {
29 return true; // Already migrated
30 }
31
32 // Add replyTo column
33 $alterQuery = "ALTER TABLE `{$tableName}` ADD COLUMN `replyTo` VARCHAR(255) NULL AFTER `sender`";
34
35 $result = $wpdb->query($alterQuery);
36
37 if ($result === false) {
38 error_log(sprintf(
39 BackendStrings::getExceptionStrings()['migration_error_add_column'],
40 'replyTo',
41 $tableName
42 ));
43 return false;
44 }
45
46 return true;
47 }
48
49 public static function rollback(): bool
50 {
51 global $wpdb;
52
53 $tableName = NotificationsTable::getTableName();
54
55 $alterQuery = "ALTER TABLE `{$tableName}` DROP COLUMN `replyTo`";
56
57 $result = $wpdb->query($alterQuery);
58
59 return $result !== false;
60 }
61 }
62