diff options
author | David King <imkingdavid@gmail.com> | 2013-03-02 17:12:43 -0500 |
---|---|---|
committer | David King <imkingdavid@gmail.com> | 2013-03-02 17:12:43 -0500 |
commit | e08edd36b9f18b9206ea327bcfb45e4331630d1b (patch) | |
tree | 4f3b5d9aca26191bb65695f1b800cf21be51075f /phpBB/includes/db | |
parent | 9fca8f88fa533c9f8cae80ec5d92f2961006e982 (diff) | |
parent | 91be99822312d9a83ae4f6849eef864dfd47e4a1 (diff) | |
download | forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.gz forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.bz2 forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.tar.xz forums-e08edd36b9f18b9206ea327bcfb45e4331630d1b.zip |
Merge remote-tracking branch 'EXreaction/ticket/11386' into develop
# By Nathaniel Guse
# Via Nathaniel Guse
* EXreaction/ticket/11386:
[ticket/11386] Fix failing tests from constructor changes
[ticket/11386] Fix circular reference error & serialize error
[ticket/11386] Remove tests that check if finder cache is working
[ticket/11386] Forgot to get the migration classes
[ticket/11386] Update tests with new constructors for ext.manager/migrator
[ticket/11386] Use finder to find migration files
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r-- | phpBB/includes/db/migrator.php | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ec0b6a87da..de9c06948c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -31,6 +31,9 @@ class phpbb_db_migrator /** @var phpbb_db_tools */ protected $db_tools; + /** @var phpbb_extension_manager */ + protected $extension_manager; + /** @var string */ protected $table_prefix; @@ -91,6 +94,16 @@ class phpbb_db_migrator } /** + * Set Extension Manager (required) + * + * Not in constructor to prevent circular reference error + */ + public function set_extension_manager(phpbb_extension_manager $extension_manager) + { + $this->extension_manager = $extension_manager; + } + + /** * Loads all migrations and their application state from the database. * * @return null @@ -180,55 +193,32 @@ class phpbb_db_migrator * If FALSE, we will not check. You SHOULD check at least once * to prevent errors (if including multiple directories, check * with the last call to prevent throwing errors unnecessarily). - * @param bool $recursive Set to true to also load data files from subdirectories * @return array Array of migration names */ - public function load_migrations($path, $check_fulfillable = true, $recursive = true) + public function load_migrations($path, $check_fulfillable = true) { if (!is_dir($path)) { throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } - $handle = opendir($path); - while (($file = readdir($handle)) !== false) - { - if ($file == '.' || $file == '..') - { - continue; - } + $migrations = array(); - // Recursion through subdirectories - if (is_dir($path . $file) && $recursive) - { - $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); - } + $finder = $this->extension_manager->get_finder(); + $files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($files as $file) + { + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); - if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) { - // We try to find what class existed by comparing the classes declared before and after including the file. - $declared_classes = get_declared_classes(); - - include ($path . $file); - - $added_classes = array_diff(get_declared_classes(), $declared_classes); - - if ( - // If two classes have been added and phpbb_db_migration is one of them, we've only added one real migration - !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && - // Otherwise there should only be one class added - sizeof($added_classes) != 1 - ) - { - throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file); - } - - $name = array_pop($added_classes); - - if (!in_array($name, $this->migrations)) - { - $this->migrations[] = $name; - } + $this->migrations[] = $migration; } } |