/**
  * Compile the correct schema filename (as per create_schema_files) and
  * load it into the database.
  */
 protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db)
 {
     $schema = $this->dbms['SCHEMA'];
     if ($this->config['dbms'] == 'phpbb\\db\\driver\\mysql') {
         $sth = $this->pdo->query('SELECT VERSION() AS version');
         $row = $sth->fetch(PDO::FETCH_ASSOC);
         if (version_compare($row['version'], '4.1.3', '>=')) {
             $schema .= '_41';
         } else {
             $schema .= '_40';
         }
     }
     $filename = $directory . $schema . '_schema.sql';
     if (file_exists($filename)) {
         global $phpbb_root_path;
         $queries = file_get_contents($filename);
         $db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
         $sql = $db_helper->remove_comments($queries);
         $sql = $db_helper->split_sql_file($sql, $this->dbms['DELIM']);
         foreach ($sql as $query) {
             $this->pdo->exec($query);
         }
     }
     // 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 = json_decode($db_table_schema, true);
     } else {
         global $phpbb_root_path, $phpEx, $table_prefix;
         $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
         $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $db = new \phpbb\db\driver\sqlite3();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db, true);
     foreach ($db_table_schema as $table_name => $table_data) {
         $queries = $db_tools->sql_create_table($table_name, $table_data);
         foreach ($queries as $query) {
             if ($query === 'begin') {
                 $this->pdo->beginTransaction();
             } else {
                 if ($query === 'commit') {
                     $this->pdo->commit();
                 } else {
                     $this->pdo->exec($query);
                 }
             }
         }
     }
 }
 /**
  * @param bool|array	$expected
  * @param string		$test_string
  *
  * @dataProvider	prefix_test_case_provider
  */
 public function test_validate_table_prefix($expected, $test_string)
 {
     $this->assertEquals($expected, $this->database_helper->validate_table_prefix('sqlite3', $test_string));
 }
 /**
  * @param array		$expected
  * @param string	$sql
  * @param string	$delimiter
  *
  * @dataProvider	sql_file_string_provider
  */
 public function test_split_sql($expected, $sql, $delimiter)
 {
     $this->assertEquals($expected, $this->database_helper->split_sql_file($sql, $delimiter));
 }