aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2016-10-23 22:00:02 +0200
committerMarc Alexander <admin@m-a-styles.de>2016-10-23 22:00:02 +0200
commitc891277996872920f88ea7bb36b1e57e3674579f (patch)
treea80c549208e466109bf635e72cc0d4f8a1b35210
parent9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7 (diff)
downloadforums-c891277996872920f88ea7bb36b1e57e3674579f.tar
forums-c891277996872920f88ea7bb36b1e57e3674579f.tar.gz
forums-c891277996872920f88ea7bb36b1e57e3674579f.tar.bz2
forums-c891277996872920f88ea7bb36b1e57e3674579f.tar.xz
forums-c891277996872920f88ea7bb36b1e57e3674579f.zip
[ticket/14831] Add migration for deduplicating entries and fix typo
PHPBB3-14831
-rw-r--r--phpBB/phpbb/db/migration/data/v31x/migrations_deduplicate_entries.php78
-rw-r--r--phpBB/phpbb/db/migrator.php6
2 files changed, 81 insertions, 3 deletions
diff --git a/phpBB/phpbb/db/migration/data/v31x/migrations_deduplicate_entries.php b/phpBB/phpbb/db/migration/data/v31x/migrations_deduplicate_entries.php
new file mode 100644
index 0000000000..4e539cf36d
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v31x/migrations_deduplicate_entries.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @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\v31x;
+
+class migrations_deduplicate_entries extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('\phpbb\db\migration\data\v31x\v3110');
+ }
+
+ public function update_data()
+ {
+ return array(
+ array('custom', array(array($this, 'deduplicate_entries'))),
+ );
+ }
+
+ public function deduplicate_entries()
+ {
+ $migration_state = array();
+ $duplicate_migrations = array();
+
+ $sql = "SELECT *
+ FROM " . $this->table_prefix . 'migrations';
+ $result = $this->db->sql_query($sql);
+
+ if (!$this->db->get_sql_error_triggered())
+ {
+ while ($migration = $this->db->sql_fetchrow($result))
+ {
+ $migration_state[$migration['migration_name']] = $migration;
+
+ $migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']);
+ $migration_state[$migration['migration_name']]['migration_data_state'] = !empty($migration['migration_data_state']) ? unserialize($migration['migration_data_state']) : '';
+ }
+ }
+
+ $this->db->sql_freeresult($result);
+
+ foreach ($migration_state as $name => $migration)
+ {
+ $prepended_name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
+ $prefixless_name = preg_replace('#(^\\\)([^\\\].+)#', '$2', $name);
+
+ if ($prepended_name !== $name && isset($migration_state[$prepended_name]) && $migration_state[$prepended_name] === $migration_state[$name])
+ {
+ $duplicate_migrations[] = $name;
+ unset($migration_state[$prepended_name]);
+ }
+ else if ($prefixless_name !== $name && isset($migration_state[$prefixless_name]) && $migration_state[$prefixless_name] === $migration_state[$name])
+ {
+ $duplicate_migrations[] = $name;
+ unset($migration_state[$prefixless_name]);
+ }
+ }
+
+ if (count($duplicate_migrations))
+ {
+ $sql = 'DELETE *
+ FROM ' . $this->table_prefix . 'migrations
+ WHERE ' . $this->db->sql_in_set('migration_name', $duplicate_migrations);
+ $this->db->sql_query($sql);
+ }
+ }
+}
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index d84635f33d..30eafcc470 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -212,12 +212,12 @@ class migrator
// Try falling back to a valid migration name with or without leading backslash
if (!isset($this->migration_state[$name]))
{
- $appended_name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
+ $prepended_name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
$prefixless_name = preg_replace('#(^\\\)([^\\\].+)#', '$2', $name);
- if (isset($this->migration_state[$appended_name]))
+ if (isset($this->migration_state[$prepended_name]))
{
- $name = $appended_name;
+ $name = $prepended_name;
}
else if (isset($this->migration_state[$prefixless_name]))
{