From 17bbe4d9ffd4a52d459db14c7034863b9501f74b Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 22 Apr 2022 11:47:42 -0400 Subject: [PATCH] Add system update 20 which corrects an issue in the DB where some original/core system pages had an incorrect (though inconsequential) created_users_id that referred to the admin page rather than the original admin user. --- .../System/SystemUpdater/SystemUpdate20.php | 29 +++++++++++++++++++ .../System/SystemUpdater/SystemUpdater.module | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 wire/modules/System/SystemUpdater/SystemUpdate20.php diff --git a/wire/modules/System/SystemUpdater/SystemUpdate20.php b/wire/modules/System/SystemUpdater/SystemUpdate20.php new file mode 100644 index 00000000..9f2b8195 --- /dev/null +++ b/wire/modules/System/SystemUpdater/SystemUpdate20.php @@ -0,0 +1,29 @@ +wire()->addHookAfter('ProcessWire::ready', $this, 'executeAtReady'); + return 0; // indicates we will update system version ourselves when ready + } + public function executeAtReady() { + $database = $this->wire()->database; + $config = $this->wire()->config; + /** @var User $u */ + $u = $this->wire()->users->get($config->superUserPageID); + $superuserId = $u->id && $u->isSuperuser() ? $u->id : 0; + $sql = 'UPDATE pages SET created_users_id=:superuser_id WHERE created_users_id=:admin_page_id'; + $query = $database->prepare($sql); + $query->bindValue(':superuser_id', $superuserId, \PDO::PARAM_INT); + $query->bindValue(':admin_page_id', $config->adminRootPageID, \PDO::PARAM_INT); + $query->execute(); + $rowCount = $query->rowCount(); + if($rowCount) $this->message("Updated $rowCount page(s) for correct created_users_id"); + $this->updater->saveSystemVersion(20); + } +} + + diff --git a/wire/modules/System/SystemUpdater/SystemUpdater.module b/wire/modules/System/SystemUpdater/SystemUpdater.module index 9e3870da..9d37f1cf 100644 --- a/wire/modules/System/SystemUpdater/SystemUpdater.module +++ b/wire/modules/System/SystemUpdater/SystemUpdater.module @@ -26,7 +26,7 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule { * This version number is important, as this updater keeps the systemVersion up with this version * */ - 'version' => 19, + 'version' => 20, ); }