diff options
author | rxu <rxu@mail.ru> | 2016-07-23 20:54:16 +0700 |
---|---|---|
committer | rxu <rxu@mail.ru> | 2016-07-23 21:34:05 +0700 |
commit | eaafb758ce5be55dd762c039fd7a746aa6c64b58 (patch) | |
tree | 65fe7faff196ac61a89d2f2039d1a0a56ba45fb1 | |
parent | 652e3da28d11157fe281c1252c74575798cf852f (diff) | |
download | forums-eaafb758ce5be55dd762c039fd7a746aa6c64b58.tar forums-eaafb758ce5be55dd762c039fd7a746aa6c64b58.tar.gz forums-eaafb758ce5be55dd762c039fd7a746aa6c64b58.tar.bz2 forums-eaafb758ce5be55dd762c039fd7a746aa6c64b58.tar.xz forums-eaafb758ce5be55dd762c039fd7a746aa6c64b58.zip |
[ticket/14703] Select the parent module id from the several found
PHPBB3-14703
-rw-r--r-- | phpBB/language/en/migrator.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/tool/module.php | 25 |
2 files changed, 23 insertions, 3 deletions
diff --git a/phpBB/language/en/migrator.php b/phpBB/language/en/migrator.php index f3f19f63c0..4b6a0241e5 100644 --- a/phpBB/language/en/migrator.php +++ b/phpBB/language/en/migrator.php @@ -65,6 +65,7 @@ $lang = array_merge($lang, array( 'MODULE_INFO_FILE_NOT_EXIST' => 'A required module info file is missing: %2$s', 'MODULE_NOT_EXIST' => 'A required module does not exist: %s', + 'PARENT_MODULE_FIND_ERROR' => 'Unable to determine the parent module identifier: %s', 'PERMISSION_NOT_EXIST' => 'The permission setting "%s" unexpectedly does not exist.', 'ROLE_NOT_EXIST' => 'The permission role "%s" unexpectedly does not exist.', diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index ed8162b81e..0869ce37d3 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -158,7 +158,7 @@ class module implements \phpbb\db\migration\tool\tool_interface $data = array('module_langname' => $data); } - $parent = $data['parent_id'] = $this->get_parent_module_id($parent); + $parent = $data['parent_id'] = $this->get_parent_module_id($parent, $data); if (!isset($data['module_langname'])) { @@ -463,10 +463,11 @@ class module implements \phpbb\db\migration\tool\tool_interface * Get parent module id * * @param string|int $parent_id The parent module_id|module_langname + * @param array $data The module data array * @return int The parent module_id * @throws \phpbb\db\migration\exception */ - public function get_parent_module_id($parent_id) + public function get_parent_module_id($parent_id, $data = array()) { // Allow '' to be sent as 0 $parent_id = $parent_id ?: 0; @@ -492,8 +493,26 @@ class module implements \phpbb\db\migration\tool\tool_interface break; // Several modules with the given module_langname were found + // Try to determine the parent_id by the neighbour module parent default: - throw new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id); + if (!empty($data) && (isset($data['before']) || isset($data['after']))) + { + $neighbour_module_langname = isset($data['before']) ? $data['before'] : $data['after']; + $sql = 'SELECT parent_id + FROM ' . MODULES_TABLE . ' + WHERE module_langname ' . $this->db->sql_escape($neighbour_module_langname) . ' + AND ' . $this->db->sql_in_set('parent_id', $ids); + $result = $this->db->sql_query($sql); + $parent_id = (int) $this->db->sql_fetchfield('parent_id'); + if (!$parent_id) + { + throw new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']); + } + } + else + { + throw new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id); + } break; } } |