mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13137] Generate the schema when the schema.json file is not available
PHPBB3-13137
This commit is contained in:
parent
943f2e1a7b
commit
4fe95d6870
3 changed files with 64 additions and 27 deletions
|
@ -1175,8 +1175,31 @@ class install_install extends module
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok we have the db info go ahead and work on building the table
|
// Ok we have the db info go ahead and work on building the table
|
||||||
|
if (file_exists('schemas/schema.json'))
|
||||||
|
{
|
||||||
$db_table_schema = @file_get_contents('schemas/schema.json');
|
$db_table_schema = @file_get_contents('schemas/schema.json');
|
||||||
$db_table_schema = json_decode($db_table_schema, true);
|
$db_table_schema = json_decode($db_table_schema, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||||
|
$table_prefix = 'phpbb_';
|
||||||
|
|
||||||
|
if (!defined('CONFIG_TABLE'))
|
||||||
|
{
|
||||||
|
// We need to include the constants file for the table constants
|
||||||
|
// when we generate the schema from the migration files.
|
||||||
|
include($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
|
||||||
|
$classes = $finder->core_path('phpbb/db/migration/data/')
|
||||||
|
->get_classes();
|
||||||
|
|
||||||
|
$sqlite_db = new \phpbb\db\driver\sqlite();
|
||||||
|
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, new \phpbb\db\tools($sqlite_db, true), $phpbb_root_path, $phpEx, $table_prefix);
|
||||||
|
$db_table_schema = $schema_generator->get_schema();
|
||||||
|
}
|
||||||
|
|
||||||
if (!defined('CONFIG_TABLE'))
|
if (!defined('CONFIG_TABLE'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,25 +55,31 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
static public function setUpBeforeClass()
|
static public function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
$setup_extensions = static::setup_extensions();
|
$setup_extensions = static::setup_extensions();
|
||||||
self::$schema_file = '';
|
|
||||||
if (!empty($setup_extensions))
|
|
||||||
{
|
|
||||||
$schema_md5 = md5(serialize($setup_extensions));
|
|
||||||
|
|
||||||
|
$schema_md5 = md5(serialize($setup_extensions));
|
||||||
self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json';
|
self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json';
|
||||||
self::$phpbb_schema_copy = __DIR__ . '/../tmp/schema_phpbb_copy.json';
|
|
||||||
self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
|
self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
|
||||||
|
|
||||||
if (!file_exists(self::$schema_file))
|
if (!file_exists(self::$schema_file))
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx, $table_prefix;
|
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||||
|
|
||||||
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
|
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
|
||||||
|
|
||||||
|
if (!empty($setup_extensions))
|
||||||
|
{
|
||||||
$classes = $finder->core_path('phpbb/db/migration/data/')
|
$classes = $finder->core_path('phpbb/db/migration/data/')
|
||||||
->set_extensions($setup_extensions)
|
->set_extensions($setup_extensions)
|
||||||
->extension_directory('/migrations')
|
->extension_directory('/migrations')
|
||||||
->get_classes();
|
->get_classes();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$classes = $finder->core_path('phpbb/db/migration/data/')
|
||||||
|
->get_classes();
|
||||||
|
}
|
||||||
|
|
||||||
$db = new \phpbb\db\driver\sqlite();
|
$db = new \phpbb\db\driver\sqlite();
|
||||||
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
|
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
|
||||||
$schema_data = $schema_generator->get_schema();
|
$schema_data = $schema_generator->get_schema();
|
||||||
|
@ -81,21 +87,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
file_put_contents(self::$schema_file, json_encode($schema_data));
|
file_put_contents(self::$schema_file, json_encode($schema_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(self::$install_schema_file, self::$phpbb_schema_copy);
|
|
||||||
copy(self::$schema_file, self::$install_schema_file);
|
copy(self::$schema_file, self::$install_schema_file);
|
||||||
}
|
|
||||||
|
|
||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function tearDownAfterClass()
|
static public function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
if (self::$schema_file !== '')
|
unlink(self::$install_schema_file);
|
||||||
{
|
|
||||||
copy(self::$phpbb_schema_copy, self::$install_schema_file);
|
|
||||||
unlink(self::$schema_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -356,8 +356,23 @@ class phpbb_database_test_connection_manager
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok we have the db info go ahead and work on building the table
|
// Ok we have the db info go ahead and work on building the table
|
||||||
|
if (file_exists($directory . 'schema.json'))
|
||||||
|
{
|
||||||
$db_table_schema = file_get_contents($directory . 'schema.json');
|
$db_table_schema = file_get_contents($directory . 'schema.json');
|
||||||
$db_table_schema = json_decode($db_table_schema, true);
|
$db_table_schema = json_decode($db_table_schema, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||||
|
|
||||||
|
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
|
||||||
|
$classes = $finder->core_path('phpbb/db/migration/data/')
|
||||||
|
->get_classes();
|
||||||
|
|
||||||
|
$db = new \phpbb\db\driver\sqlite();
|
||||||
|
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
|
||||||
|
$db_table_schema = $schema_generator->get_schema();
|
||||||
|
}
|
||||||
|
|
||||||
$db_tools = new \phpbb\db\tools($db, true);
|
$db_tools = new \phpbb\db\tools($db, true);
|
||||||
foreach ($db_table_schema as $table_name => $table_data)
|
foreach ($db_table_schema as $table_name => $table_data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue