diff options
author | Marc Alexander <admin@m-a-styles.de> | 2014-04-06 14:50:22 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2014-04-06 14:50:22 +0200 |
commit | 904de5b39aa20e692e9b2d1dcda77736b5928dc2 (patch) | |
tree | d0a371db02dcad6fa3cb7608bbbd3cf0784b8286 /phpBB/phpbb/db/migration/schema_generator.php | |
parent | d0aa7c6455170396fd8b6c9add7cf2a19bb17426 (diff) | |
download | forums-904de5b39aa20e692e9b2d1dcda77736b5928dc2.tar forums-904de5b39aa20e692e9b2d1dcda77736b5928dc2.tar.gz forums-904de5b39aa20e692e9b2d1dcda77736b5928dc2.tar.bz2 forums-904de5b39aa20e692e9b2d1dcda77736b5928dc2.tar.xz forums-904de5b39aa20e692e9b2d1dcda77736b5928dc2.zip |
[ticket/12362] Throw exception in schema generator on unresolvable dependency
Make sure we throw an exception in the schema generator if we come across an
unresolvable dependency. Otherwise we'll get stuck in a infinite loop that
needs to be cancelled by the user or the maximum execution time.
PHPBB3-12362
Diffstat (limited to 'phpBB/phpbb/db/migration/schema_generator.php')
-rw-r--r-- | phpBB/phpbb/db/migration/schema_generator.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/migration/schema_generator.php b/phpBB/phpbb/db/migration/schema_generator.php index a7e2fa8f06..dbb50e80ca 100644 --- a/phpBB/phpbb/db/migration/schema_generator.php +++ b/phpBB/phpbb/db/migration/schema_generator.php @@ -40,6 +40,9 @@ class schema_generator /** @var array */ protected $tables; + /** @var array */ + protected $dependencies = array(); + /** * Constructor */ @@ -69,11 +72,13 @@ class schema_generator $migrations = $this->class_names; $tree = array(); + $check_dependencies = true; while (!empty($migrations)) { foreach ($migrations as $migration_class) { $open_dependencies = array_diff($migration_class::depends_on(), $tree); + if (empty($open_dependencies)) { $migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); @@ -170,10 +175,41 @@ class schema_generator } unset($migrations[$migration_key]); } + else if ($check_dependencies) + { + $this->dependencies = array_merge($this->dependencies, $open_dependencies); + } + } + + // Only run this check after the first run + if ($check_dependencies) + { + $this->check_dependencies(); + $check_dependencies = false; } } ksort($this->tables); return $this->tables; } + + /** + * Check if one of the migrations files' dependencies can't be resolved + * by the supplied list of migrations + * + * @throws UnexpectedValueException If a dependency can't be resolved + */ + protected function check_dependencies() + { + // Strip duplicate values from array + $this->dependencies = array_unique($this->dependencies); + + foreach ($this->dependencies as $dependency) + { + if (!in_array($dependency, $this->class_names)) + { + throw new \UnexpectedValueException("Unable to resolve the dependency '$dependency'"); + } + } + } } |