Moved user config stuff into an extension
This commit is contained in:
parent
40be8f045a
commit
91b46d6598
5 changed files with 75 additions and 27 deletions
|
@ -52,11 +52,6 @@ unset($themelet);
|
|||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||
$_tracer->end();
|
||||
|
||||
$_shm_ctx->log_start("Loading user information");
|
||||
$user = _get_user();
|
||||
$user_config = new DatabaseConfig($database, "user_config","user_id", $user->id);
|
||||
$_shm_ctx->log_endok();
|
||||
|
||||
// hook up event handlers
|
||||
$_tracer->begin("Loading extensions");
|
||||
_load_event_listeners();
|
||||
|
|
|
@ -40,7 +40,7 @@ _d("SEARCH_ACCEL", false); // boolean use search accelerator
|
|||
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
|
||||
_d("VERSION", '2.7-beta'); // string shimmie version
|
||||
_d("TIMEZONE", null); // string timezone
|
||||
_d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,handle_static,comment,tag_list,index,tag_edit,alias_editor,media,help_pages,system"); // extensions to always enable
|
||||
_d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,handle_static,comment,tag_list,index,tag_edit,alias_editor,media,help_pages,system,user_config"); // extensions to always enable
|
||||
_d("EXTRA_EXTS", ""); // string optional extra extensions
|
||||
_d("BASE_URL", null); // string force a specific base URL (default is auto-detect)
|
||||
_d("MIN_PHP_VERSION", '7.1');// string minimum supported PHP version
|
||||
|
|
|
@ -224,29 +224,11 @@ class Upgrade extends Extension
|
|||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
|
||||
|
||||
if ($config->get_int("db_version") < 18) {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 18);
|
||||
|
||||
log_info("upgrade", "Adding user config table");
|
||||
|
||||
$database->create_table("user_config", "
|
||||
user_id INTEGER NOT NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
value TEXT,
|
||||
PRIMARY KEY (user_id, name),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
");
|
||||
$database->execute("CREATE INDEX user_config_user_id_idx ON user_config(user_id)");
|
||||
|
||||
log_info("upgrade", "Database at version 18");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
|
||||
if ($config->get_int("db_version") < 19) {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 19);
|
||||
|
||||
log_info("upgrade", "Updating to new unrated code");
|
||||
|
||||
if ($database->get_driver_name()==DatabaseDriver::PGSQL) { // These updates can take a little bit
|
||||
|
@ -255,11 +237,10 @@ class Upgrade extends Extension
|
|||
$database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new"=>'?', "old"=>'u' ]);
|
||||
|
||||
|
||||
log_info("upgrade", "Database at version 19");
|
||||
log_info("upgrade", "Database at version 18");
|
||||
$config->set_bool("in_upgrade", false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function get_priority(): int
|
||||
|
|
69
ext/user_config/main.php
Normal file
69
ext/user_config/main.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/*
|
||||
* Name: User-specific settings
|
||||
* Author: Matthew Barbour <matthew@darkholme.net>
|
||||
* Description: Provides system-wide support for user-specific settings
|
||||
* Visibility: admin
|
||||
*/
|
||||
|
||||
// The user object doesn't exist until after database setup operations and the first wave of InitExtEvents,
|
||||
// so we can't reliably access this data until then. This event is triggered by the system after all of that is done.
|
||||
class InitUserConfigEvent extends Event
|
||||
{
|
||||
public $user;
|
||||
public $user_config;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
class UserConfig extends Extension
|
||||
{
|
||||
private const VERSION = "ext_user_config_version";
|
||||
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ($config->get_int(self::VERSION,0)<1) {
|
||||
$this->install();
|
||||
}
|
||||
}
|
||||
|
||||
public function onInitUserConfig(InitUserConfigEvent $event) {
|
||||
global $database, $user_config;
|
||||
|
||||
$user_config = new DatabaseConfig($database, "user_config", "user_id", $event->user->id);
|
||||
$event->user_config = $user_config;
|
||||
}
|
||||
|
||||
private function install(): void
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
if ($config->get_int(self::VERSION,0) < 1) {
|
||||
|
||||
log_info("upgrade", "Adding user config table");
|
||||
|
||||
$database->create_table("user_config", "
|
||||
user_id INTEGER NOT NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
value TEXT,
|
||||
PRIMARY KEY (user_id, name),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
");
|
||||
$database->execute("CREATE INDEX user_config_user_id_idx ON user_config(user_id)");
|
||||
|
||||
$config->set_int(self::VERSION, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This needs to happen before any other events, but after db upgrade
|
||||
public function get_priority(): int
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
}
|
|
@ -89,7 +89,10 @@ $_tracer->begin($_SERVER["REQUEST_URI"] ?? "No Request");
|
|||
|
||||
try {
|
||||
|
||||
|
||||
// start the page generation waterfall
|
||||
$user = _get_user();
|
||||
send_event(new InitUserConfigEvent($user));
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') {
|
||||
send_event(new CommandEvent($argv));
|
||||
} else {
|
||||
|
|
Reference in a new issue