1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

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.

This commit is contained in:
Ryan Cramer
2022-04-22 11:47:42 -04:00
parent d24b942921
commit 17bbe4d9ff
2 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
<?php namespace ProcessWire;
/**
* Correct created_users_id on some pages from admin page ID to be default superuser ID
*
*/
class SystemUpdate20 extends SystemUpdate {
public function execute() {
$this->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);
}
}

View File

@@ -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,
);
}