Migration_20221028_105818.php
3 months ago
Migration_20221110_151621.php
3 years ago
Migration_20230111_120000.php
2 years ago
Migration_20230111_130000.php
3 years ago
Migration_20230215_050813.php
3 months ago
Migration_20230221_200520.php
3 years ago
Migration_20230421_135915.php
3 years ago
Migration_20230503_210945.php
3 years ago
Migration_20230605_174836.php
3 years ago
Migration_20230703_105957.php
3 years ago
Migration_20230716_130221_Db.php
2 years ago
Migration_20230824_054259_Db.php
2 years ago
Migration_20230831_124214_Db.php
2 years ago
Migration_20230831_143755_Db.php
1 year ago
Migration_20240119_113943_Db.php
2 years ago
Migration_20240617_122847_Db.php
2 years ago
Migration_20240725_182318_Db.php
2 years ago
Migration_20241007_170437_Db.php
1 year ago
Migration_20241108_103249_Db.php
3 months ago
Migration_20250903_151331_Db.php
11 months ago
Migration_20250926_153050_Db.php
10 months ago
Migration_20260415_090055_Db.php
3 months ago
Migration_20260427_100000.php
3 months ago
Migration_20260428_120000.php
3 months ago
Migration_20260430_103000_Db.php
3 months ago
Migration_20260430_120000.php
3 months ago
Migration_20260504_120000_Db.php
3 months ago
Migration_20260514_120000_Db.php
3 months ago
Migration_20260609_120000_Db.php
2 months ago
Migration_20260610_120000_Db.php
1 month ago
Migration_20260622_120000_Db.php
1 month ago
Migration_20260709_120000_Db.php
1 month ago
Migration_20260715_100000_Db.php
1 month ago
index.php
3 years ago
Migration_20250926_153050_Db.php
87 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\Db; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SettingEntity; |
| 9 | use MailPoet\Migrator\DbMigration; |
| 10 | |
| 11 | /** |
| 12 | * Updates the logging level to 'errors' if it is 'everything' |
| 13 | * and prunes the log table if needed. |
| 14 | * |
| 15 | * This is a one time fix for users who had logging level set to 'everything' and table was filled |
| 16 | * with email editor logs. |
| 17 | */ |
| 18 | class Migration_20250926_153050_Db extends DbMigration { |
| 19 | public function run(): void { |
| 20 | $this->updateLoggingLevel(); |
| 21 | $this->pruneLogTableIfNeeded(); |
| 22 | } |
| 23 | |
| 24 | private function updateLoggingLevel(): void { |
| 25 | $settingsTable = $this->getTableName(SettingEntity::class); |
| 26 | |
| 27 | if (!$this->tableExists($settingsTable)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | // Check if logging level is 'everything' |
| 32 | $loggingLevel = $this->connection->fetchOne(" |
| 33 | SELECT value |
| 34 | FROM {$settingsTable} |
| 35 | WHERE name = 'logging' |
| 36 | "); |
| 37 | |
| 38 | if ($loggingLevel !== 'everything') { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Update logging level from 'everything' to 'errors' |
| 43 | $this->connection->executeStatement(" |
| 44 | UPDATE {$settingsTable} |
| 45 | SET value = 'errors' |
| 46 | WHERE name = 'logging' AND value = 'everything' |
| 47 | "); |
| 48 | } |
| 49 | |
| 50 | private function pruneLogTableIfNeeded(): void { |
| 51 | $settingsTable = $this->getTableName(SettingEntity::class); |
| 52 | $logTable = $this->getTableName(\MailPoet\Entities\LogEntity::class); |
| 53 | |
| 54 | if (!$this->tableExists($settingsTable) || !$this->tableExists($logTable)) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // Check if pruning flag exists and is true |
| 59 | $flagResult = $this->connection->fetchOne(" |
| 60 | SELECT value |
| 61 | FROM {$settingsTable} |
| 62 | WHERE name = 'log_table_pruned_migration_20250926' |
| 63 | "); |
| 64 | |
| 65 | // If flag doesn't exist or is not '1', proceed with pruning |
| 66 | if ($flagResult !== '1') { |
| 67 | // Truncate the log table |
| 68 | try { |
| 69 | // Prefer fast path |
| 70 | $this->connection->executeStatement("TRUNCATE TABLE {$logTable}"); |
| 71 | } catch (\Throwable $e) { |
| 72 | // Fallback for environments without TRUNCATE privileges |
| 73 | $this->connection->executeStatement("DELETE FROM {$logTable}"); |
| 74 | } |
| 75 | |
| 76 | // Set the pruning flag to true |
| 77 | $this->connection->executeStatement(" |
| 78 | INSERT INTO {$settingsTable} (name, value, created_at, updated_at) |
| 79 | VALUES ('log_table_pruned_migration_20250926', '1', NOW(), NOW()) |
| 80 | ON DUPLICATE KEY UPDATE |
| 81 | value = '1', |
| 82 | updated_at = NOW() |
| 83 | "); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 |