예제 #1
0
 public function run($userId, $mode = 'test')
 {
     $testMode = $mode != 'run';
     $message = '';
     $userlist = new UserListModel();
     $userlist->read();
     $badAvatarLinks = 0;
     foreach ($userlist->entries as $userParams) {
         // foreach existing user
         $userId = $userParams['id'];
         $user = new UserProfileModel($userId);
         if (strpos($user->avatar_ref, '/') !== FALSE or strpos($user->avatar_ref, '\\') !== FALSE) {
             if ($user->avatar_color != '' && $user->avatar_shape != '') {
                 $newRef = $user->avatar_color . '-' . $user->avatar_shape . '-128x128.png';
             } else {
                 $newRef = 'anonymoose.png';
             }
             $message .= "Changed user {$userId} 's avatar from " . $user->avatar_ref . " to {$newRef}\n";
             $user->avatar_ref = $newRef;
             $badAvatarLinks++;
             if (!$testMode) {
                 $user->write();
             }
         }
     }
     if ($badAvatarLinks > 0) {
         $message .= "\n\nFixed {$badAvatarLinks} bad avatar URLs\n\n";
     } else {
         $message .= "\n\nNo bad avatar URLs were found\n\n";
     }
     return $message;
 }
예제 #2
0
 public function run($mode = 'test')
 {
     $testMode = $mode == 'test';
     $message = "";
     $userlist = new UserListModel();
     $userlist->read();
     $badUserRoles = 0;
     foreach ($userlist->entries as $userParams) {
         // foreach existing user
         $userId = $userParams['id'];
         $user = new UserModel($userId);
         if (!$user->role) {
             $user->role = SystemRoles::USER;
             if (!$testMode) {
                 $user->write();
             }
             $badUserRoles++;
             $message .= "Fixed role of user {$userId}\n";
         }
     }
     if ($badUserRoles > 0) {
         $message .= "\n\nFixed {$badUserRoles} non-existent user roles from the users collection\n\n";
     } else {
         $message .= "\n\nNo non-existent user roles found in the users collection\n\n";
     }
     $projectlist = new ProjectListModel();
     $projectlist->read();
     $badProjectUserRoles = 0;
     foreach ($projectlist->entries as $projectParams) {
         // foreach existing project
         $projectId = $projectParams['id'];
         $project = new ProjectModel($projectId);
         $projectUserRefs = array_keys($project->users);
         foreach ($projectUserRefs as $ref) {
             // foreach user that is a member of this project
             if (!isset($project->users[$ref]->role)) {
                 $project->users[$ref]->role = ProjectRoles::CONTRIBUTOR;
                 $badProjectUserRoles++;
                 $message .= "Fixed role of user {$ref} for project {$projectId}\n";
             }
         }
         if (!$testMode) {
             $project->write();
         }
     }
     if ($badProjectUserRoles > 0) {
         $message .= "\n\nFixed {$badProjectUserRoles} non-existent user roles from the projects collection\n\n";
     } else {
         $message .= "\n\nNo non-existent user roles found in the projects collection\n\n";
     }
     return $message;
 }
 public function run($userId, $mode = 'test')
 {
     $testMode = $mode != 'run';
     $message = "Fix site roles integrity\n\n";
     // loop over every project
     $projectlist = new ProjectListModel();
     $projectlist->read();
     $fixCount = array();
     foreach ($projectlist->entries as $projectParams) {
         // foreach existing project
         $projectId = $projectParams['id'];
         $project = new ProjectModel($projectId);
         $hostname = $project->siteName;
         $website = Website::get($hostname);
         $fixCount[$hostname] = 0;
         $projectUserRefs = array_keys($project->users->getArrayCopy());
         $message .= "-------------  " . $project->projectName . "\n";
         foreach ($projectUserRefs as $userId) {
             // foreach user that is a member of this project
             $user = new UserModel($userId);
             if (!array_key_exists($hostname, $user->siteRole) && $user->username != '') {
                 $message .= "Fixed user '" . $user->username . "' who did not have a site role on " . $hostname . "\n";
                 $fixCount[$hostname]++;
                 $user->siteRole[$hostname] = $website->userDefaultSiteRole;
                 if (!$testMode) {
                     $user->write();
                 }
             }
         }
     }
     // loop over users who do not belong to any projects
     $userlist = new UserListModel();
     $userlist->read();
     foreach ($userlist->entries as $userParams) {
         // foreach existing user
         $userId = $userParams['id'];
         $user = new UserModel($userId);
         if (count($user->projects->refs) == 0 && count(array_keys($user->siteRole->getArrayCopy())) == 0) {
             $message .= "Warning: user '" . $user->username . "' has no projects and no siteRoles on any site!\n";
         }
     }
     foreach ($fixCount as $site => $count) {
         if ($count > 0) {
             $message .= "\n\n{$site} : Fixed {$count} non-existent site roles \n\n";
         } else {
             $message .= "\n\n{$site} : Nothing to do \n\n";
         }
     }
     return $message;
 }
 public function run($mode = 'test')
 {
     $testMode = $mode == 'test';
     $message = "";
     $userlist = new UserListModel();
     $userlist->read();
     $userIds = array_map(function ($e) {
         return $e['id'];
     }, $userlist->entries);
     $projectlist = new ProjectListModel();
     $projectlist->read();
     $projectIds = array_map(function ($e) {
         return $e['id'];
     }, $projectlist->entries);
     $deadCommentUserRefs = 0;
     $deadAnswerUserRefs = 0;
     foreach ($projectIds as $projectId) {
         $project = new ProjectModel($projectId);
         $textlist = new TextListModel($project);
         $textlist->read();
         $textIds = array_map(function ($e) {
             return $e['id'];
         }, $textlist->entries);
         foreach ($textIds as $textId) {
             $questionlist = new QuestionListModel($project, $textId);
             $questionlist->read();
             $questionIds = array_map(function ($e) {
                 return $e['id'];
             }, $questionlist->entries);
             foreach ($questionIds as $questionId) {
                 $question = new QuestionModel($project, $questionId);
                 foreach ($question->answers as $answerId => $answer) {
                     foreach ($answer->comments as $commentId => $comment) {
                         $ref = $comment->userRef;
                         if (!empty($ref->id) && !in_array($ref->asString(), $userIds)) {
                             $comment->userRef->id = '';
                             if (!$testMode) {
                                 $question->writeComment($project->databaseName(), $questionId, $answerId, $comment);
                             }
                             $deadCommentUserRefs++;
                             $message .= "Removed dead user-comment ref {$ref} from question {$questionId}, answer {$answerId}, comment {$commentId}\n";
                         }
                     }
                     $ref = $answer->userRef;
                     if (!empty($ref->id) && !in_array($ref->asString(), $userIds)) {
                         $answer->userRef->id = '';
                         if (!$testMode) {
                             $question->writeAnswer($answer);
                         }
                         $deadAnswerUserRefs++;
                         $message .= "Removed dead user-answer ref {$ref} from question {$questionId}, answer {$answerId}\n";
                     }
                 }
             }
         }
     }
     if ($deadAnswerUserRefs > 0) {
         $message .= "\n\nRemoved dead user references from {$deadAnswerUserRefs} answers\n\n";
     } else {
         $message .= "\n\nNo dead user references were found in answers\n\n";
     }
     if ($deadCommentUserRefs > 0) {
         $message .= "\n\nRemoved dead user references from {$deadCommentUserRefs} comments\n\n";
     } else {
         $message .= "\n\nNo dead user references were found in comments\n\n";
     }
     return $message;
 }
 public function run($mode = 'test')
 {
     $testMode = $mode == 'test';
     $message = "";
     $userlist = new UserListModel();
     $userlist->read();
     $userIds = array_map(function ($e) {
         return $e['id'];
     }, $userlist->entries);
     $projectlist = new ProjectListModel();
     $projectlist->read();
     $projectIds = array_map(function ($e) {
         return $e['id'];
     }, $projectlist->entries);
     $deadProjectLinks = 0;
     foreach ($userlist->entries as $userParams) {
         // foreach existing user
         $userId = $userParams['id'];
         $user = new UserModel($userId);
         $userProjectRefs = $user->projects->refs;
         foreach ($userProjectRefs as $ref) {
             // foreach project the user belongs to
             if (!in_array($ref, $projectIds)) {
                 $user->removeProject($ref);
                 // remove dead project link
                 $deadProjectLinks++;
                 $message .= "Removed dead project link {$ref} from user {$userId}\n";
             }
         }
         if (!$testMode) {
             $user->write();
         }
     }
     if ($deadProjectLinks > 0) {
         $message .= "\n\nRemoved {$deadProjectLinks} dead project links from the users collection\n\n";
     } else {
         $message .= "\n\nNo dead project links were found\n\n";
     }
     $deadUserLinks = 0;
     foreach ($projectlist->entries as $projectParams) {
         // foreach existing project
         $projectId = $projectParams['id'];
         $project = new ProjectModel($projectId);
         $projectUserRefs = array_keys($project->users);
         foreach ($projectUserRefs as $ref) {
             // foreach user that is a member of this project
             if (!in_array($ref, $userIds)) {
                 $project->removeUser($ref);
                 // remove dead user link
                 $deadUserLinks++;
                 $message .= "Removed dead user link {$ref} for project {$projectId}\n";
             }
         }
         if (!$testMode) {
             $project->write();
         }
     }
     if ($deadUserLinks > 0) {
         $message .= "\n\nRemoved {$deadUserLinks} dead user links from the projects collection\n\n";
     } else {
         $message .= "\n\nNo dead user links were found\n\n";
     }
     return $message;
 }