From 39ca212e17e80d14dbbd20cf5542ab37f27bd217 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:02:53 -0600 Subject: [ticket/11386] Use finder to find migration files PHPBB3-11386 --- phpBB/includes/db/migrator.php | 53 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'phpBB/includes/db') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ec0b6a87da..824bca5e70 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; @@ -69,11 +72,12 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; + $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -180,55 +184,26 @@ 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) + $finder = $this->extension_manager->get_finder(); + $migration_files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($migration_files as $migration) { - if ($file == '.' || $file == '..') - { - continue; - } + $migration_name = $migration['path'] . $migration['filename']; - // Recursion through subdirectories - if (is_dir($path . $file) && $recursive) + if (!in_array($migration_name, $this->migrations)) { - $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); - } - - if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) - { - // 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_name; } } -- cgit v1.2.1 From 1368470f7488b278cdc214745a7d4c9557d407e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:42:30 -0600 Subject: [ticket/11386] Forgot to get the migration classes PHPBB3-11386 --- phpBB/includes/db/migrator.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/db') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 824bca5e70..855e640554 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -193,17 +193,23 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } + $migrations = array(); + $finder = $this->extension_manager->get_finder(); - $migration_files = $finder + $files = $finder ->extension_directory("/") ->find_from_paths(array('/' => $path)); - foreach ($migration_files as $migration) + foreach ($files as $file) { - $migration_name = $migration['path'] . $migration['filename']; + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); - if (!in_array($migration_name, $this->migrations)) + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) { - $this->migrations[] = $migration_name; + $this->migrations[] = $migration; } } -- cgit v1.2.1 From a6f877c0d84ff102d3812246eae7469e191983e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 14:15:59 -0600 Subject: [ticket/11386] Fix circular reference error & serialize error PHPBB3-11386 --- phpBB/includes/db/migrator.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 855e640554..de9c06948c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -72,12 +72,11 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; - $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -94,6 +93,16 @@ class phpbb_db_migrator $this->load_migration_state(); } + /** + * 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. * -- cgit v1.2.1