1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge remote-tracking branch 'Marc/ticket/12362' into develop-ascraeus

* Marc/ticket/12362:
  [ticket/12362] Do not use database test case as it's not needed
  [ticket/12362] Add tests for schema generator
  [ticket/12362] Throw exception in schema generator on unresolvable dependency
This commit is contained in:
Joas Schilling
2014-04-07 22:42:42 +02:00
2 changed files with 85 additions and 0 deletions

View File

@@ -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'");
}
}
}
}