query($alterQuery); if ($result === false) { error_log(sprintf( BackendStrings::getExceptionStrings()['migration_error_add_column'], 'cc/bcc', $tableName )); return false; } return true; } public static function rollback(): bool { global $wpdb; $tableName = NotificationsTable::getTableName(); $ccExists = self::columnExists($wpdb, $tableName, 'cc'); if ($ccExists === null) { return false; } if ($ccExists && $wpdb->query("ALTER TABLE `{$tableName}` DROP COLUMN `cc`") === false) { return false; } $bccExists = self::columnExists($wpdb, $tableName, 'bcc'); if ($bccExists === null) { return false; } if ($bccExists && $wpdb->query("ALTER TABLE `{$tableName}` DROP COLUMN `bcc`") === false) { return false; } return true; } /** * @param \wpdb $wpdb * @return bool|null True when present, false when absent, null when lookup failed */ private static function columnExists($wpdb, string $tableName, string $column): ?bool { $results = $wpdb->get_results( "SHOW COLUMNS FROM `{$tableName}` LIKE '{$column}'" ); if ($results === null) { return null; } return !empty($results); } }