From 70319bb67a086d7e8e8f5cf3bc34355c7f7cb75f Mon Sep 17 00:00:00 2001 From: Merijn Schering Date: Tue, 12 Jan 2021 12:24:26 +0100 Subject: [PATCH] Fixed db check for core models --- www/controller/MaintenanceController.php | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/www/controller/MaintenanceController.php b/www/controller/MaintenanceController.php index 23559c1e71..1bc7ce5cfb 100644 --- a/www/controller/MaintenanceController.php +++ b/www/controller/MaintenanceController.php @@ -476,6 +476,36 @@ private function _checkCoreModels(){ $classes=\GO::findClasses('model'); foreach($classes as $model){ if($model->isSubclassOf('GO\Base\Db\ActiveRecord') && !$model->isAbstract()){ + + $m = \GO::getModel($model->getName()); + + if($m->hasColumn('user_id')) { + //correct missing user_id values + $stmt = go()->getDbConnection()->updateIgnore( + $m->tableName(), + ['user_id' => 1], + (new \go\core\orm\Query()) + ->where("user_id not in (select id from core_user)")); + $stmt->execute(); + if($stmt->rowCount()) { + echo "Changed " . $stmt->rowCount() . " missing user id's into the admin user\n"; + } + } + + if($m->hasColumn('acl_id')) { + //correct missing user_id values + $stmt = go()->getDbConnection()->update( + $m->tableName(), + ['acl_id' => 0], + (new \go\core\orm\Query()) + ->where("acl_id not in (select id from core_acl)")); + + $stmt->execute(); + + if($stmt->rowCount()) { + echo "Set " . $stmt->rowCount() . " missing ACL id's to zero\n"; + } + } echo "Processing ".$model->getName()."\n"; flush();