diff --git a/core/_bootstrap.php b/core/_bootstrap.php deleted file mode 100644 index a561613f..00000000 --- a/core/_bootstrap.php +++ /dev/null @@ -1,26 +0,0 @@ -begin("Bootstrap"); -_load_core_files(); -$cache = new Cache(CACHE_DSN); -$database = new Database(DATABASE_DSN); -$config = new DatabaseConfig($database); -ExtensionInfo::load_all_extension_info(); -Extension::determine_enabled_extensions(); -require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); -_load_theme_files(); -$page = new Page(); -_load_event_listeners(); -$_tracer->end(); diff --git a/core/database.php b/core/database.php index 4018e588..2db27e42 100644 --- a/core/database.php +++ b/core/database.php @@ -64,7 +64,7 @@ class Database private function connect_engine(): void { - if (preg_match("/^([^:]*)/", DATABASE_DSN, $matches)) { + if (preg_match("/^([^:]*)/", $this->dsn, $matches)) { $db_proto=$matches[1]; } else { throw new SCoreException("Can't figure out database engine"); diff --git a/core/sys_config.php b/core/sys_config.php index e5778bc6..7055af3b 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -1,22 +1,15 @@ get_bool("in_upgrade")) { - return; - } - if (!is_numeric($config->get_string("db_version"))) { $this->set_version("db_version", 2); } @@ -32,19 +28,14 @@ class Upgrade extends Extension // now done again as v9 with PDO if ($this->get_version("db_version") < 8) { - $config->set_bool("in_upgrade", true); - $database->execute($database->scoreql_to_sql( "ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N" )); $this->set_version("db_version", 8); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 9) { - $config->set_bool("in_upgrade", true); - if ($database->get_driver_name() == DatabaseDriver::MYSQL) { $tables = $database->get_col("SHOW TABLES"); foreach ($tables as $table) { @@ -54,34 +45,25 @@ class Upgrade extends Extension } $this->set_version("db_version", 9); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 10) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Adding foreign keys to images"); $database->Execute("ALTER TABLE images ADD FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); $this->set_version("db_version", 10); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 11) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Converting user flags to classes"); $database->execute("ALTER TABLE users ADD COLUMN class VARCHAR(32) NOT NULL default :user", ["user" => "user"]); $database->execute("UPDATE users SET class = :name WHERE id=:id", ["name"=>"anonymous", "id"=>$config->get_int('anon_id')]); $database->execute("UPDATE users SET class = :name WHERE admin=:admin", ["name"=>"admin", "admin"=>'Y']); $this->set_version("db_version", 11); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 12) { - $config->set_bool("in_upgrade", true); - if ($database->get_driver_name() == DatabaseDriver::PGSQL) { log_info("upgrade", "Changing ext column to VARCHAR"); $database->execute("ALTER TABLE images ALTER COLUMN ext SET DATA TYPE VARCHAR(4)"); @@ -91,12 +73,9 @@ class Upgrade extends Extension $database->execute("UPDATE images SET ext = LOWER(ext)"); $this->set_version("db_version", 12); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 13) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Changing password column to VARCHAR(250)"); if ($database->get_driver_name() == DatabaseDriver::PGSQL) { $database->execute("ALTER TABLE users ALTER COLUMN pass SET DATA TYPE VARCHAR(250)"); @@ -105,12 +84,9 @@ class Upgrade extends Extension } $this->set_version("db_version", 13); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 14) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Changing tag column to VARCHAR(255)"); if ($database->get_driver_name() == DatabaseDriver::PGSQL) { $database->execute('ALTER TABLE tags ALTER COLUMN tag SET DATA TYPE VARCHAR(255)'); @@ -123,12 +99,9 @@ class Upgrade extends Extension } $this->set_version("db_version", 14); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 15) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Adding lower indexes for postgresql use"); if ($database->get_driver_name() == DatabaseDriver::PGSQL) { $database->execute('CREATE INDEX tags_lower_tag_idx ON tags ((lower(tag)))'); @@ -136,12 +109,9 @@ class Upgrade extends Extension } $this->set_version("db_version", 15); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 16) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Adding tag_id, image_id index to image_tags"); $database->execute('CREATE UNIQUE INDEX image_tags_tag_id_image_id_idx ON image_tags(tag_id,image_id) '); @@ -158,12 +128,9 @@ class Upgrade extends Extension // SQLite doesn't support altering existing columns? This seems like a problem? $this->set_version("db_version", 16); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 17) { - $config->set_bool("in_upgrade", true); - log_info("upgrade", "Adding media information columns to images table"); $database->execute($database->scoreql_to_sql( "ALTER TABLE images ADD COLUMN lossless SCORE_BOOL NULL" @@ -197,7 +164,6 @@ class Upgrade extends Extension $database->execute('CREATE INDEX images_ext_idx ON images(ext)'); $this->set_version("db_version", 17); - $config->set_bool("in_upgrade", false); } if ($this->get_version("db_version") < 18) { @@ -215,7 +181,6 @@ class Upgrade extends Extension $database->execute($database->scoreql_to_sql("UPDATE images SET audio = SCORE_BOOL_N WHERE ext IN ('webp')")); $database->execute($database->scoreql_to_sql("UPDATE images SET lossless = SCORE_BOOL_N, video = SCORE_BOOL_Y WHERE ext IN ('flv','mp4','m4v','ogv','webm')")); $this->set_version("db_version", 18); - $config->set_bool("in_upgrade", false); } } diff --git a/index.php b/index.php index c5155302..97d65540 100644 --- a/index.php +++ b/index.php @@ -43,6 +43,10 @@ * Each of these can be imported at the start of a function with eg "global $page, $user;" */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ +* Make sure that shimmie is correctly installed * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + if (!file_exists("data/config/shimmie.conf.php")) { require_once "core/_install.php"; exit; @@ -79,7 +83,39 @@ EOD; exit; } -require_once "core/_bootstrap.php"; +require_once "vendor/autoload.php"; + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ +* Load files * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +@include_once "data/config/shimmie.conf.php"; +@include_once "data/config/extensions.conf.php"; +require_once "core/sys_config.php"; +require_once "core/polyfills.php"; +require_once "core/util.php"; + +global $cache, $config, $database, $user, $page, $_tracer; +_sanitise_environment(); +$_tracer->begin("Bootstrap"); +_load_core_files(); +$cache = new Cache(CACHE_DSN); +$database = new Database(DATABASE_DSN); +$config = new DatabaseConfig($database); +ExtensionInfo::load_all_extension_info(); +Extension::determine_enabled_extensions(); +require_all(zglob("ext/{".Extension::get_enabled_extensions_as_string()."}/main.php")); +_load_theme_files(); +$page = new Page(); +_load_event_listeners(); +$_tracer->end(); + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ +* Send events, display output * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + //$_tracer->mark(@$_SERVER["REQUEST_URI"]); $_tracer->begin($_SERVER["REQUEST_URI"] ?? "No Request"); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 401f8857..8ba3b374 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,14 +1,29 @@