PluginProbe
The Innovative Form Builder – IvyForms / 0.7
The Innovative Form Builder – IvyForms v0.7
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 0.7, at backend/src/Services/InstallActions/Migrations/AddReplyToToNotifications.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 // 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\Notification\NotificationsTable;
12 use IvyForms\Services\Translations\BackendStrings;
13
14 class AddReplyToToNotifications
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
26 $tableName = NotificationsTable::getTableName();
27
28 // Check if replyTo column already exists
29 $columnExists = $wpdb->get_results(
30 "SHOW COLUMNS FROM `{$tableName}` LIKE 'replyTo'"
31 );
32
33 if (!empty($columnExists)) {
34 return true; // Already migrated
35 }
36
37 // Add replyTo column
38 $alterQuery = "ALTER TABLE `{$tableName}` ADD COLUMN `replyTo` VARCHAR(255) NULL AFTER `sender`";
39
40 $result = $wpdb->query($alterQuery);
41
42 if ($result === false) {
43 error_log(sprintf(
44 BackendStrings::getExceptionStrings()['migration_error_add_column'],
45 'replyTo',
46 $tableName
47 ));
48 return false;
49 }
50
51 return true;
52 }
53
54 public static function rollback(): bool
55 {
56 global $wpdb;
57
58 $tableName = NotificationsTable::getTableName();
59
60 $alterQuery = "ALTER TABLE `{$tableName}` DROP COLUMN `replyTo`";
61
62 $result = $wpdb->query($alterQuery);
63
64 return $result !== false;
65 }
66 }
67