From 35fef8333ad1adf510ce7f414bdccc70849ae059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Jun 2018 14:56:08 +0200 Subject: [ticket/15663] Add migration PHPBB3-15663 --- .../data/v330/remove_attachment_flash.php | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php (limited to 'phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php') diff --git a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php new file mode 100644 index 0000000000..2150b5c1c9 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php @@ -0,0 +1,87 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v330; + + +class remove_attachment_flash extends \phpbb\db\migration\migration +{ + // Following constants were deprecated in 3.3 + // and moved from constants.php to compatibility_globals.php, + // thus define them as class constants + const ATTACHMENT_CATEGORY_FLASH = 5; + + protected $cat_id = array( + self::ATTACHMENT_CATEGORY_FLASH, + ); + + public function update_data() + { + return array( + array('custom', array(array($this, 'remove_flash_group'))), + ); + } + + public function remove_flash_group() + { + // select group ids of outdated media + $sql = 'SELECT group_id + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('cat_id', $this->cat_id); + $result = $this->db->sql_query($sql); + + $group_ids = array(); + while ($group_id = (int) $this->db->sql_fetchfield('group_id')) + { + $group_ids[] = $group_id; + } + $this->db->sql_freeresult($result); + + // nothing to do, admin has removed all the outdated media extension groups + if (empty($group_ids)) + { + return true; + } + + // get the group id of downloadable files + $sql = 'SELECT group_id + FROM ' . EXTENSION_GROUPS_TABLE . " + WHERE group_name = 'DOWNLOADABLE_FILES'"; + $result = $this->db->sql_query($sql); + $download_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (empty($download_id)) + { + $sql = 'UPDATE ' . EXTENSIONS_TABLE . ' + SET group_id = 0 + WHERE ' . $this->db->sql_in_set('group_id', $group_ids); + } + else + { + // move outdated media extensions to downloadable files + $sql = 'UPDATE ' . EXTENSIONS_TABLE . " + SET group_id = $download_id" . ' + WHERE ' . $this->db->sql_in_set('group_id', $group_ids); + } + + $result = $this->db->sql_query($sql); + $this->db->sql_freeresult($result); + + // delete the now empty, outdated media extension groups + $sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('group_id', $group_ids); + $result = $this->db->sql_query($sql); + $this->db->sql_freeresult($result); + } +} -- cgit v1.2.1 From 0fe4cbc17f9f544ea1d6b793819b243657b6bcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Jun 2018 15:07:00 +0200 Subject: [ticket/15663] Remove empty line PHPBB3-15663 --- phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php') diff --git a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php index 2150b5c1c9..90c2fe7400 100644 --- a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php +++ b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php @@ -13,7 +13,6 @@ namespace phpbb\db\migration\data\v330; - class remove_attachment_flash extends \phpbb\db\migration\migration { // Following constants were deprecated in 3.3 -- cgit v1.2.1 From 30303647f06300ea9bea31abf66bad651e92b722 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 6 Sep 2018 14:11:51 +0200 Subject: [ticket/15744] Remove useless sql_freeresults PHPBB3-15744 --- phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php') diff --git a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php index 90c2fe7400..11dc43483b 100644 --- a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php +++ b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php @@ -74,13 +74,11 @@ class remove_attachment_flash extends \phpbb\db\migration\migration WHERE ' . $this->db->sql_in_set('group_id', $group_ids); } - $result = $this->db->sql_query($sql); - $this->db->sql_freeresult($result); + $this->db->sql_query($sql); // delete the now empty, outdated media extension groups $sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . ' WHERE ' . $this->db->sql_in_set('group_id', $group_ids); - $result = $this->db->sql_query($sql); - $this->db->sql_freeresult($result); + $this->db->sql_query($sql); } } -- cgit v1.2.1 From 79287abd7b3b6e837774bda6971061c923050d45 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 1 Jan 2020 16:23:23 +0100 Subject: [ticket/16285] Add sanity checks to migrations for 3.3 PHPBB3-16285 --- phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php') diff --git a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php index 11dc43483b..c136960905 100644 --- a/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php +++ b/phpBB/phpbb/db/migration/data/v330/remove_attachment_flash.php @@ -21,8 +21,13 @@ class remove_attachment_flash extends \phpbb\db\migration\migration const ATTACHMENT_CATEGORY_FLASH = 5; protected $cat_id = array( - self::ATTACHMENT_CATEGORY_FLASH, - ); + self::ATTACHMENT_CATEGORY_FLASH, + ); + + public static function depends_on() + { + return ['\phpbb\db\migration\data\v330\dev',]; + } public function update_data() { -- cgit v1.2.1