public function run() { $message = ''; $projectlist = new ProjectListModel(); $projectlist->read(); $projectIds = array_map(function ($e) { return $e['id']; }, $projectlist->entries); $emptyQuestionTitles = 0; foreach ($projectIds as $projectId) { $project = new ProjectModel($projectId); $activityEntries = ActivityListDto::getActivityForProject($project); foreach ($activityEntries as $activity) { if (key_exists('questionRef', $activity) && key_exists('question', $activity['content'])) { $questionId = $activity['questionRef']; $questionTitle = $activity['content']['question']; if ($questionTitle == '') { $emptyQuestionTitles++; $questionModel = new QuestionModel($project, $questionId); $activityModel = new ActivityModel($project, $activity['id']); $newTitle = $questionModel->getTitleForDisplay(); $activityModel->actionContent['question'] = $newTitle; $message .= "Fixing activity " . $activity['action'] . " with title '" . $newTitle . "'\n"; $activityModel->write(); } } } } if ($emptyQuestionTitles > 0) { $message .= "\n\nFixed up {$emptyQuestionTitles} empty question titles in the activity log\n\n"; } else { $message .= "\n\nNo empty question titles were found in the activity log \n\n"; } return $message; }
public function run($mode = 'test') { $testMode = $mode == 'test'; $message = ""; $projectlist = new ProjectListModel(); $projectlist->read(); $projectIds = array_map(function ($e) { return $e['id']; }, $projectlist->entries); $projectsChanged = 0; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); if ($project->siteName == '') { $sfproject = new SfchecksProjectModel($projectId); $sfproject->themeName = "jamaicanpsalms"; $message .= "Changed the " . $sfproject->projectName . " to be a sfchecks/scriptureforge project with jamaican psalms theme\n"; if (!$testMode) { $sfproject->write(); } $projectsChanged++; } } if ($projectsChanged > 0) { $message .= "\n\nChanged {$projectsChanged} projects to be of sfchecks type under scriptureforge and jamaicanpsalms theme \n\n"; } else { $message .= "\n\nNo projects were found/changed \n\n"; } return $message; }
public static function run($mode = 'test') { $testMode = $mode != 'run'; print "Change Site Name To Local\n\n"; $siteNameMap = array("languageforge.org" => "languageforge.local", "scriptureforge.org" => "scriptureforge.local", "jamaicanpsalms.com" => "scriptureforge.local"); $siteNameCount = array(); foreach ($siteNameMap as $from => $to) { $siteNameCount[$from] = 0; } // loop over every project $projectlist = new ProjectListModel(); $projectlist->read(); foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $siteName = $project->siteName; if (array_key_exists($siteName, $siteNameMap)) { $project->siteName = $siteNameMap[$siteName]; $siteNameCount[$siteName]++; if (!$testMode) { $project->write(); } } } foreach ($siteNameMap as $from => $to) { $count = $siteNameCount[$from]; if ($count > 0) { print "{$count} {$from} projects changed site to {$to}\n"; } else { print "No {$from} projects encountered\n"; } } print "\n"; }
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($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Fix Lexicon View Settings to default to visible\n\n"; $projectlist = new ProjectListModel(); $projectlist->read(); foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); if ($project->appName == 'lexicon') { $project = new LexiconProjectModel($projectId); $message .= "Inspecting project {$project->projectName}.\n"; $showFieldUpdated = 0; $roleShowFieldUpdated = 0; foreach ($project->config->roleViews as $role => $roleView) { foreach ($roleView->fields as $fieldName => $field) { if (!$field->show) { $field->show = true; $showFieldUpdated++; $roleShowFieldUpdated++; } } } $userShowFieldUpdated = 0; foreach ($project->config->userViews as $userId => $userView) { foreach ($userView->fields as $fieldName => $field) { if (!$field->show) { $field->show = true; $showFieldUpdated++; $userShowFieldUpdated++; } } } if ($showFieldUpdated > 0) { $message .= " Changed {$showFieldUpdated} View Settings fields to be visible. This comprised: \n"; $message .= " - Changed {$roleShowFieldUpdated} role-based View Settings fields to be visible.\n"; $message .= " - Changed {$userShowFieldUpdated} user-based View Settings fields to be visible.\n\n"; if (!$testMode) { $message .= " Saving changes to project {$project->projectName}.\n\n"; $project->write(); } } else { $message .= " No invisible View Settings fields found/changed.\n\n"; } } } return $message; }
public static function encode() { $data = array(); $listModel = new ProjectListModel(); $listModel->read(); $projects = array(); foreach ($listModel->entries as $p) { $project = new SemDomTransProjectModel($p["id"]); if ($project->appName == LfProjectModel::SEMDOMTRANS_APP && $project->languageIsoCode != "en") { $projects[] = array('name' => $project->languageIsoCode, 'id' => $p['id']); } } $data['languages'] = $projects; return $data; }
/** * Gets list of currently open projects for a user (excluding those he is part of are has submitted a join request for) * @param string $userId * @return multitype:\Api\Model\Languageforge\SemDomTransProjectModel */ public static function getOpenSemdomProjects($userId) { $projects = new ProjectListModel(); $projects->read(); $semdomProjects = []; foreach ($projects->entries as $p) { $project = new ProjectModel($p["id"]); if ($project->appName == LfProjectModel::SEMDOMTRANS_APP && !array_key_exists($userId, $project->users) && !array_key_exists($userId, $project->userJoinRequests)) { $sp = new SemDomTransProjectModel($p["id"]); if ($sp->languageIsoCode != "en") { $semdomProjects[] = $sp; } } } return $semdomProjects; }
public function run($mode = 'test') { $testMode = $mode != 'run'; $message = ""; $templateList = new GlobalQuestionTemplateListModel(); $templateList->read(); if (count($templateList->entries) > 0) { } else { $message .= "There are no global templates to migrate\n\n"; } $templatesMoved = 0; $projectlist = new ProjectListModel(); $projectlist->read(); $project = null; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $p = new SfchecksProjectModel($projectId); if ($p->databaseName() == 'sf_jamaican_psalms') { $project = $p; } } if (!is_null($project)) { $message .= "Migrating global templates to the '" . $project->projectName . "' project\n\n"; foreach ($templateList->entries as $globalTemplate) { $template = new QuestionTemplateModel($project); $template->title = $globalTemplate['title']; $template->description = $globalTemplate['description']; $message .= "Moving '" . $template->title . "'\n"; if (!$testMode) { $template->write(); $gt = new GlobalQuestionTemplateModel($globalTemplate['id']); $gt->remove(); } $templatesMoved++; } $message .= "\n\nMoved {$templatesMoved} global templates to the specified project\n\n"; } else { $message .= "Error: cound not find the Jamaican Psalms project on this server\n\n"; } return $message; }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Fix project site name integrity\n\n"; // loop over every project $projectlist = new ProjectListModel(); $projectlist->read(); $fixCount = 0; foreach ($projectlist->entries as $projectParams) { // foreach existing project $projectId = $projectParams['id']; $project = new ProjectModel($projectId); $hostname = $project->siteName; $website = Website::get($hostname); if (!$website) { // the website does not exist anymore $message .= "{$hostname} does not exist anymore..."; // see if there is a redirect $redirect = Website::getRawRedirect($hostname); if ($redirect) { $message .= "changed to {$redirect}\n"; $project->siteName = $redirect; $fixCount++; if (!$testMode) { $project->write(); } } else { $message .= "ERROR: dont know what to change it to since no redirect is available\n"; } } } if ($fixCount > 0) { $message .= "\n\nFixed siteNames in {$fixCount} project(s)\n\n"; } else { $message .= "\n\nNo non-existent siteNames were found in the projects collection\n\n"; } return $message; }
<?php require_once 'scriptsConfig.php'; use Api\Model\Shared\DbIntegrityHelper; use Api\Model\ProjectListModel; php_sapi_name() == 'cli' or die('this script must be run on the command-line'); $runForReal = false; if (count($argv) > 1 && $argv[1] == 'run') { $runForReal = true; } $helper = new DbIntegrityHelper($runForReal); $projectList = new ProjectListModel(); $projectList->read(); foreach ($projectList->entries as $p) { $helper->checkProject($p['id']); print $helper->flushOutput(); } print $helper->flushOutput(); // verify integrity of all users // verify integrity of all sites // list sites and which projects are in which sites
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 != 'run'; $message = ""; $projectlist = new ProjectListModel(); $projectlist->read(); $textsExamined = 0; $textsUpdated = 0; // foreach existing project foreach ($projectlist->entries as $projectParams) { $projectId = $projectParams['id']; if ($projectParams['projectName'] == 'Jamaican Psalms') { $project = new SfchecksProjectModel($projectId); $textlist = new TextListModel($project); $textlist->read(); // foreach text in project foreach ($textlist->entries as $textParams) { $textsExamined++; $textId = $textParams['id']; $legacyText = new TextModel_sf_v0_9_18($project, $textId); $fileName = ''; if ($legacyText->audioUrl) { $text = new TextModel($project, $textId); if (!$testMode) { if (!$text->audioFileName) { // legacy audioUrl format "assets/<projectId>/<textId>_<fileName>" $fileNamePrefix = $textId . '_'; $pos = strpos($legacyText->audioUrl, $fileNamePrefix); $text->audioFileName = substr($legacyText->audioUrl, $pos + strlen($fileNamePrefix)); } $text->write(); } $message .= "Changed text: {$text->title}\n"; $textsUpdated++; } } if (!$testMode) { TextModel_sf_v0_9_18::removeAudioProperty($project->databaseName()); $message .= "Removed 'audioUrl' property from project: {$project->projectName}\n"; } } } if ($textsUpdated > 0) { $message .= "\n\nChanged {$textsUpdated} legacy texts to only store audio filename\n\n"; } else { $message .= "\n\nNo legacy text audio were found/changed. {$textsExamined} texts examined.\n\n"; } // re-arrange assets folder // - remove <siteName> from path for LF // - add <appName> to path for SF and change <projectId> in path to <projectSlug (databaseName)> $message .= "\n\nRe-arrange assets folder\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n"; $project = new SfchecksProjectModel(); $assetsFolderPath = APPPATH . "assets"; $assetsSubfolders = glob($assetsFolderPath . '/*'); @mkdir($assetsFolderPath . '/lexicon'); @mkdir($assetsFolderPath . '/sfchecks'); foreach ($assetsSubfolders as $assetsSubfolder) { if (file_exists($assetsSubfolder) && is_dir($assetsSubfolder)) { $assetsSubfolderName = basename($assetsSubfolder); if (strpos($assetsSubfolderName, 'languageforge') !== false) { $message .= "Move into lexicon: {$assetsSubfolderName}\n"; $oldFolderPath = $assetsSubfolder . '/lexicon'; $newFolderPath = $assetsFolderPath . '/lexicon'; } elseif ($assetsSubfolderName == 'lexicon' || $assetsSubfolderName == 'sfchecks') { $message .= "No change: {$assetsSubfolderName}\n"; $oldFolderPath = ''; $newFolderPath = ''; $assetsSubfolder = ''; } elseif ($project->exists($assetsSubfolderName)) { $message .= "Move into sfchecks: {$assetsSubfolderName}\n"; $oldFolderPath = $assetsSubfolder; $project->read($assetsSubfolderName); $projectSlug = $project->databaseName(); $newFolderPath = $assetsFolderPath . "/sfchecks/{$projectSlug}"; if (!$testMode) { } } else { $message .= "Delete: {$assetsSubfolderName}\n"; $oldFolderPath = ''; $newFolderPath = ''; } if (!$testMode) { if (file_exists($oldFolderPath) && is_dir($oldFolderPath)) { if (!@rename($oldFolderPath, $newFolderPath)) { $oldFiles = glob($oldFolderPath . '/*'); foreach ($oldFiles as $oldFile) { $newFile = $newFolderPath . '/' . basename($oldFile); rename($oldFile, $newFile); } } } if (file_exists($assetsSubfolder) && is_dir($assetsSubfolder)) { $this->recursiveRemoveFolder($assetsSubfolder); } } } } 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; }