From 455d55d497a51d581fd2f6bdacb946a10d0f8c07 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 3 Feb 2014 09:45:33 -0600 Subject: [PATCH 1/4] [ticket/11716] Convert Soft Delete Mod to post/topic visibility PHPBB3-11716 --- .../data/v310/soft_delete_convert.php | 126 ++++++++++++++++++ .../data/v310/soft_delete_convert2.php | 60 +++++++++ 2 files changed, 186 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php create mode 100644 phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php new file mode 100644 index 0000000000..5edcfed052 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php @@ -0,0 +1,126 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_deleted'); + } + + public function update_data() + { + return array( + array('permission.remove', array('m_harddelete', true)), + array('permission.remove', array('m_harddelete', false)), + + array('custom', array(array($this, 'convert_posts'))), + array('custom', array(array($this, 'convert_topics'))), + ); + } + + public function convert_posts($start) + { + $content_visibility = $this->get_content_visibility(); + + $limit = 250; + $i = 0; + + $sql = 'SELECT p.*, t.topic_first_post_id, t.topic_last_post_id + FROM ' . $this->table_prefix . 'posts p, ' . $this->table_prefix . 'topics t + WHERE p.post_deleted > 0 + AND t.topic_id = p.topic_id'; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $content_visibility->set_post_visibility( + ITEM_DELETED, + $row['post_id'], + $row['topic_id'], + $row['forum_id'], + $row['post_deleted'], + $row['post_deleted_time'], + '', + ($row['post_id'] == $row['topic_first_post_id']) ? true : false, + ($row['post_id'] == $row['topic_last_post_id']) ? true : false + ); + + $i++; + } + + $this->db->sql_freeresult($result); + + if ($i == $limit) + { + return $start + $i; + } + } + + public function convert_topics($start) + { + $content_visibility = $this->get_content_visibility(); + + $limit = 100; + $i = 0; + + $sql = 'SELECT * + FROM ' . $this->table_prefix . 'topics + WHERE topic_deleted > 0'; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $content_visibility->set_topic_visibility( + ITEM_DELETED, + $row['topic_id'], + $row['forum_id'], + $row['topic_deleted'], + $row['topic_deleted_time'], + '' + ); + + $i++; + } + + $this->db->sql_freeresult($result); + + if ($i == $limit) + { + return $start + $i; + } + } + + protected function get_content_visibility() + { + return new \phpbb\content_visibility( + new \phpbb\auth\auth(), + $this->db, + new \phpbb\user(), + $this->phpbb_root_path, + $this->php_ext, + $this->table_prefix . 'forums', + $this->table_prefix . 'posts', + $this->table_prefix . 'topics', + $this->table_prefix . 'users' + ); + } +} diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php new file mode 100644 index 0000000000..57327f2536 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php @@ -0,0 +1,60 @@ +db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_deleted'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array('forum_deleted_topic_count', 'forum_deleted_reply_count'), + $this->table_prefix . 'posts' => array('post_deleted', 'post_deleted_time'), + $this->table_prefix . 'topics' => array('topic_deleted', 'topic_deleted_time', 'topic_deleted_reply_count'), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_deleted_topic_count' => array('UINT', 0), + 'forum_deleted_reply_count' => array('UINT', 0), + ), + $this->table_prefix . 'posts' => array( + 'post_deleted' => array('UINT', 0), + 'post_deleted_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'topics' => array( + 'topic_deleted' => array('UINT', 0), + 'topic_deleted_time' => array('TIMESTAMP', 0), + 'topic_deleted_reply_count' => array('UINT', 0), + ), + ), + ); + } +} From 68b5a2b6b29ee87c47d0404b63ebe98aaefe8267 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 3 Feb 2014 18:09:34 -0600 Subject: [PATCH 2/4] [ticket/11716] Rename migration files and add note that it's converting a MOD PHPBB3-11716 --- .../{soft_delete_convert.php => soft_delete_mod_convert.php} | 4 +++- ...{soft_delete_convert2.php => soft_delete_mod_convert2.php} | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) rename phpBB/phpbb/db/migration/data/v310/{soft_delete_convert.php => soft_delete_mod_convert.php} (95%) rename phpBB/phpbb/db/migration/data/v310/{soft_delete_convert2.php => soft_delete_mod_convert2.php} (92%) diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php similarity index 95% rename from phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php rename to phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php index 5edcfed052..3aac8d84f5 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php @@ -11,8 +11,10 @@ namespace phpbb\db\migration\data\v310; /** * Migration to convert the Soft Delete MOD for 3.0 + * + * https://www.phpbb.com/customise/db/mod/soft_delete/ */ -class soft_delete_convert extends \phpbb\db\migration\migration +class soft_delete_mod_convert extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php similarity index 92% rename from phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php rename to phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php index 57327f2536..cc8feb7525 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_convert2.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php @@ -11,8 +11,10 @@ namespace phpbb\db\migration\data\v310; /** * Migration to convert the Soft Delete MOD for 3.0 + * + * https://www.phpbb.com/customise/db/mod/soft_delete/ */ -class soft_delete_convert2 extends \phpbb\db\migration\migration +class soft_delete_mod_convert2 extends \phpbb\db\migration\migration { static public function depends_on() { From f75b98aa8b796b7135b4218dc54b3d7aafec69e3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 11 Mar 2014 18:34:35 -0500 Subject: [PATCH 3/4] [ticket/11716] Fix dependencies in migration files PHPBB3-11716 --- phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php | 2 +- phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php index 3aac8d84f5..5d9d38843e 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php @@ -19,7 +19,7 @@ class soft_delete_mod_convert extends \phpbb\db\migration\migration static public function depends_on() { return array( - '\phpbb\db\migration\data\v310\alpha2', + '\phpbb\db\migration\data\v310\alpha3', ); } diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php index cc8feb7525..95fa042f00 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php @@ -19,7 +19,7 @@ class soft_delete_mod_convert2 extends \phpbb\db\migration\migration static public function depends_on() { return array( - '\phpbb\db\migration\data\v310\soft_delete_convert', + '\phpbb\db\migration\data\v310\soft_delete_mod_convert', ); } From c14d2fb60ff1bda2f18cd58f713da548f2354185 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 11 Mar 2014 18:38:57 -0500 Subject: [PATCH 4/4] [ticket/11716] Correct license URL PHPBB3-11716 --- phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php | 2 +- phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php index 5d9d38843e..c9255d88ee 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert.php @@ -3,7 +3,7 @@ * * @package migration * @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php index 95fa042f00..ab4be269e6 100644 --- a/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php +++ b/phpBB/phpbb/db/migration/data/v310/soft_delete_mod_convert2.php @@ -3,7 +3,7 @@ * * @package migration * @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */