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"; }
/** * Removes a user from the collection * Project references to this user are also removed */ public function remove() { foreach ($this->projects->refs as $id) { $project = new ProjectModel($id->asString()); $project->removeUser($this->id->asString()); $project->write(); } parent::remove(); }
public function getProjectMember($projectId, $userName) { $userId = $this->e->createUser($userName, $userName, '*****@*****.**'); $user = new UserModel($userId); $user->addProject($projectId); $user->write(); $project = new ProjectModel($projectId); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); return $userId; }
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 testWrite_ReadBackSame() { $model = new ProjectModel(); $model->language = "SomeLanguage"; $model->projectName = "SomeProject"; $model->projectCode = 'project_code'; //$model->users->refs = array('1234'); $id = $model->write(); $this->assertNotNull($id); $this->assertIsA($id, 'string'); $this->assertEqual($id, $model->id->asString()); $otherModel = new ProjectModel($id); $this->assertEqual($id, $otherModel->id->asString()); $this->assertEqual('SomeLanguage', $otherModel->language); $this->assertEqual('SomeProject', $otherModel->projectName); //$this->assertEqual(array('1234'), $otherModel->users->refs); $this->_someProjectId = $id; }
public function checkProject($projectId) { $project = new ProjectModel($projectId); $this->projectsChecked++; $this->info("Checking {$project->projectName}"); if ($project->projectName == '') { $this->warn("{$projectId} has an empty projectName"); } if ($project->projectCode == '') { $this->warn("{$project->projectName} has an empty projectCode. This will certainly cause failures"); } // check that a database exists for this project try { $databaseName = $project->databaseName(); } catch (\Exception $e) { $databaseName = ""; } if (!MongoStore::hasDB($databaseName)) { $newProjectCode = str_replace(' ', '_', strtolower($project->projectName)); $newDatabaseName = 'sf_' . $newProjectCode; if (MongoStore::hasDB($newDatabaseName)) { $this->warn("projectCode does not correspond to an existing MongoDb but projectName does (db migration required)"); $this->fix("Changed projectCode to {$newProjectCode}"); $this->projectsFixed++; $project->projectCode = $newProjectCode; } else { $this->warn("{$project->projectName} has no corresponding database. (could indicate a brand new project with no data"); } } if ($project->siteName == '') { $this->warn("{$project->projectName} has no corresponding website (will not appear on any site)"); } if ($project->appName == '') { $this->warn("{$project->projectName} has no app associated with it"); } if ($this->makeChanges) { $project->write(); } }
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; }
public function testWrite_TwoModels_ReadBackBothModelsOk() { $model = new UserModel(); $model->email = "*****@*****.**"; $model->username = "******"; $id = $model->write(); $this->assertNotNull($id); $this->assertIsA($id, 'string'); $otherModel = new UserModel($id); $this->assertEqual($id, $otherModel->id->asString()); $this->assertEqual('*****@*****.**', $otherModel->email); $this->assertEqual('SomeUser', $otherModel->username); $model = new ProjectModel(); $model->language = "SomeLanguage"; $model->projectName = "SomeProject"; $id = $model->write(); $this->assertNotNull($id); $this->assertIsA($id, 'string'); $otherModel = new ProjectModel($id); $this->assertEqual($id, $otherModel->id->asString()); $this->assertEqual('SomeLanguage', $otherModel->language); $this->assertEqual('SomeProject', $otherModel->projectName); }
/** * @param $projectId * @return int Total number of projects archived. * @throws UserUnauthorizedException */ public static function archiveProject($projectId) { CodeGuard::checkTypeAndThrow($projectId, 'string'); $project = new \Api\Model\ProjectModel($projectId); $project->isArchived = true; return $project->write(); }
/** * Removes users from the project (two-way unlink) * @param Id $projectId * @param array $userIds array<string> */ public static function removeJoinRequest($projectId, $joinRequestId) { $project = new ProjectModel($projectId); $project->removeUserJoinRequest($joinRequestId); $project->write(); }
/** * Sends an email to request joining of the project * @param string $projectId * @param string $inviterUserId * @param Website $website * @param string $toEmail * @param DeliveryInterface $delivery * @throws \Exception * @return string $userId */ public static function sendJoinRequest($projectId, $userId, $website, DeliveryInterface $delivery = null) { $newUser = new UserModel($userId); $project = new ProjectModel(); $project->read($projectId['id']); // Make sure the user exists on the site if (!$newUser->hasRoleOnSite($website)) { $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole; } // Determine if user is already a member of the project if ($project->userIsMember($newUser->id->asString())) { return $newUser->id; } // Add the user to the project $project->createUserJoinRequest($userId, ProjectRoles::CONTRIBUTOR); $project->write(); $admin = new UserModel($project->ownerRef->asString()); if ($admin->email != '') { Communicate::sendJoinRequest($newUser, $admin, $project, $website, $delivery); Communicate::sendJoinRequestConfirmation($newUser, $project, $website, $delivery); } return $admin; }
$projectType = SfProjectModel::SFCHECKS_APP; } else { if ($site == 'languageforge') { $projectType = LfProjectModel::LEXICON_APP; } } $testProject = ProjectCommands::createProject($constants['testProjectName'], $constants['testProjectCode'], $projectType, $adminUserId, $website); $testProjectModel = new ProjectModel($testProject); $testProjectModel->projectCode = $constants['testProjectCode']; $testProjectModel->allowInviteAFriend = $constants['testProjectAllowInvites']; $testProjectModel->write(); $otherProject = ProjectCommands::createProject($constants['otherProjectName'], $constants['otherProjectCode'], $projectType, $managerUserId, $website); $otherProjectModel = new ProjectModel($otherProject); $otherProjectModel->projectCode = $constants['otherProjectCode']; $otherProjectModel->allowInviteAFriend = $constants['otherProjectAllowInvites']; $otherProjectModel->write(); ProjectCommands::updateUserRole($testProject, $managerUserId, ProjectRoles::MANAGER); ProjectCommands::updateUserRole($testProject, $memberUserId, ProjectRoles::CONTRIBUTOR); ProjectCommands::updateUserRole($testProject, $resetUserId, ProjectRoles::CONTRIBUTOR); ProjectCommands::updateUserRole($otherProject, $adminUserId, ProjectRoles::MANAGER); if ($site == 'scriptureforge') { $text1 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText1Title'], 'content' => $constants['testText1Content'])); $text2 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText2Title'], 'content' => $constants['testText2Content'])); $question1 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question1Title'], 'description' => $constants['testText1Question1Content'])); $question2 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question2Title'], 'description' => $constants['testText1Question2Content'])); $template1 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'first template', 'description' => 'not particularly interesting')); $template2 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'second template', 'description' => 'not entirely interesting')); $answer1 = QuestionCommands::updateAnswer($testProject, $question1, array('id' => '', 'content' => $constants['testText1Question1Answer']), $managerUserId); $answer1Id = array_keys($answer1)[0]; $answer2 = QuestionCommands::updateAnswer($testProject, $question2, array('id' => '', 'content' => $constants['testText1Question2Answer']), $managerUserId); $answer2Id = array_keys($answer2)[0];
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; }