register(); class phpbb_extension_empty_manager extends \phpbb\extension\manager { public function __construct() { $this->extensions = array(); } } $finder = new \phpbb\extension\finder(new \phpbb_extension_empty_manager(), new \phpbb\filesystem(), $phpbb_root_path); $classes = $finder->core_path('phpbb/') ->directory('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); $schema_data = $schema_generator->get_schema(); $dbms_type_map = phpbb\db\tools::get_dbms_type_map(); $fp = fopen($schema_path . 'schema.json', 'wb'); fwrite($fp, json_encode($schema_data, JSON_PRETTY_PRINT)); fclose($fp); foreach ($supported_dbms as $dbms) { $fp = fopen($schema_path . $dbms . '_schema.sql', 'wb'); // Write Header switch ($dbms) { case 'mysql_40': case 'mysql_41': case 'firebird': case 'sqlite': fwrite($fp, "# DO NOT EDIT THIS FILE, IT IS GENERATED\n"); fwrite($fp, "#\n"); fwrite($fp, "# To change the contents of this file, edit\n"); fwrite($fp, "# phpBB/develop/create_schema_files.php and\n"); fwrite($fp, "# run it.\n"); break; case 'mssql': case 'oracle': case 'postgres': fwrite($fp, "/*\n"); fwrite($fp, " * DO NOT EDIT THIS FILE, IT IS GENERATED\n"); fwrite($fp, " *\n"); fwrite($fp, " * To change the contents of this file, edit\n"); fwrite($fp, " * phpBB/develop/create_schema_files.php and\n"); fwrite($fp, " * run it.\n"); fwrite($fp, " */\n\n"); break; } $line = ''; switch ($dbms) { case 'oracle': $line .= custom_data('oracle') . "\n"; break; case 'postgres': $line .= "BEGIN;\n\n"; $line .= custom_data('postgres') . "\n"; $line .= "COMMIT;\n\n"; break; } fwrite($fp, $line); fclose($fp); } /** * Data put into the header for various dbms */ function custom_data($dbms) { switch ($dbms) { case 'oracle': return << LOWER($2)' LANGUAGE SQL STRICT; CREATE FUNCTION _varchar_ci_greater_equals(varchar_ci, varchar_ci) RETURNS boolean AS 'SELECT LOWER($1) >= LOWER($2)' LANGUAGE SQL STRICT; /* Operators */ CREATE OPERATOR <( PROCEDURE = _varchar_ci_less_than, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = >, NEGATOR = >=, RESTRICT = scalarltsel, JOIN = scalarltjoinsel); CREATE OPERATOR <=( PROCEDURE = _varchar_ci_less_equal, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = >=, NEGATOR = >, RESTRICT = scalarltsel, JOIN = scalarltjoinsel); CREATE OPERATOR >( PROCEDURE = _varchar_ci_greater_than, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = <, NEGATOR = <=, RESTRICT = scalargtsel, JOIN = scalargtjoinsel); CREATE OPERATOR >=( PROCEDURE = _varchar_ci_greater_equals, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = <=, NEGATOR = <, RESTRICT = scalargtsel, JOIN = scalargtjoinsel); CREATE OPERATOR <>( PROCEDURE = _varchar_ci_not_equal, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = <>, NEGATOR = =, RESTRICT = neqsel, JOIN = neqjoinsel); CREATE OPERATOR =( PROCEDURE = _varchar_ci_equal, LEFTARG = varchar_ci, RIGHTARG = varchar_ci, COMMUTATOR = =, NEGATOR = <>, RESTRICT = eqsel, JOIN = eqjoinsel, HASHES, MERGES, SORT1= <); EOF; break; } return ''; } echo 'done';