Skip to content

Commit

Permalink
Fixed db check for core models
Browse files Browse the repository at this point in the history
  • Loading branch information
mschering committed Jan 12, 2021
1 parent 174fe46 commit 70319bb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions www/controller/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 70319bb

Please sign in to comment.