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_20241007_170437_Db.php
65 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\Db; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Migrator\DbMigration; |
| 9 | |
| 10 | /** |
| 11 | * In https://github.com/mailpoet/mailpoet/pull/5628 we removed Google+ social icons |
| 12 | * but they were still used in templates. This migration removes them from the templates. |
| 13 | */ |
| 14 | class Migration_20241007_170437_Db extends DbMigration { |
| 15 | public function run(): void { |
| 16 | global $wpdb; |
| 17 | $templatesTable = esc_sql($wpdb->prefix . 'mailpoet_newsletter_templates'); |
| 18 | |
| 19 | if (!$this->tableExists($templatesTable)) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | $templatesWithGooglePlus = $this->connection->fetchAllAssociative( |
| 24 | "SELECT id, body FROM $templatesTable WHERE body LIKE '%\"iconType\":\"google-plus\"%'" |
| 25 | ); |
| 26 | foreach ($templatesWithGooglePlus as $template) { |
| 27 | if (!is_string($template['body'])) { |
| 28 | continue; |
| 29 | } |
| 30 | $body = json_decode($template['body'], true); |
| 31 | $error = json_last_error(); |
| 32 | if ($error || !is_array($body)) { |
| 33 | continue; |
| 34 | } |
| 35 | $content = &$body['content']; |
| 36 | $this->removeGooglePlusIcons($content); |
| 37 | $updatedBody = json_encode($body); |
| 38 | if ($updatedBody === false) { |
| 39 | continue; |
| 40 | } |
| 41 | $this->connection->update( |
| 42 | $templatesTable, |
| 43 | ['body' => $updatedBody], |
| 44 | ['id' => $template['id']] |
| 45 | ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private function removeGooglePlusIcons(&$array) { |
| 50 | if (!isset($array['blocks']) || !is_array($array['blocks'])) { |
| 51 | return; |
| 52 | } |
| 53 | foreach ($array['blocks'] as &$block) { |
| 54 | $this->removeGooglePlusIcons($block); |
| 55 | if (!isset($block['type']) || $block['type'] !== 'social') { |
| 56 | continue; |
| 57 | } |
| 58 | $filteredIcons = array_filter($block['icons'], function($icon) { |
| 59 | return $icon['iconType'] !== 'google-plus'; |
| 60 | }); |
| 61 | $block['icons'] = array_values($filteredIcons); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 |