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"; }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->itemKeys = new ArrayOf(); $this->name = ""; $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * * @param ProjectModel $projectModel * @param int $newerThanTimestamp */ public function __construct($projectModel, $newerThanTimestamp = null) { if (!is_null($newerThanTimestamp)) { $startDate = new \MongoDate($newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('dateModified' => array('$gte' => $startDate)), array(), array('name' => 1)); } else { parent::__construct(self::mapper($projectModel->databaseName()), array(), array(), array('name' => 1)); } }
/** * 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(); }
/** * @param \Api\Model\ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->items = new ArrayOf(function ($data) { return new LexiconOptionListItem(); }); $this->id = new Id(); $this->canDelete = true; $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * * @param ProjectModel $projectModel * @param int $newerThanTimestamp */ public function __construct($projectModel, $newerThanTimestamp = null) { $lexProject = new LexiconProjectModel($projectModel->id->asString()); if (!is_null($newerThanTimestamp)) { $startDate = new \MongoDate($newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => true, 'dateModified' => array('$gte' => $startDate)), array()); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => true), array()); } }
/** * * @param ProjectModel $projectModel * @param int $newerThanTimestamp * @param int $limit * @param int $skip */ public function __construct($projectModel, $newerThanTimestamp = null, $limit = 0, $skip = 0) { $lexProject = new LexiconProjectModel($projectModel->id->asString()); $this->_config = $lexProject->config; if (!is_null($newerThanTimestamp)) { $startDate = new \MongoDate($newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('dateModified' => array('$gte' => $startDate), 'isDeleted' => false), array(), array(), $limit, $skip); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false), array(), array(), $limit, $skip); } }
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; }
/** * * @param ProjectModel $projectModel * @param int $newerThanTimestamp * @param int $limit * @param int $skip */ public function __construct($projectModel, $newerThanTimestamp = null, $limit = 0, $skip = 0) { $this->entries = new ArrayOf(function ($data) use($projectModel) { return new LexCommentModel($projectModel); }); // sort ascending by creation date if (!is_null($newerThanTimestamp)) { $startDate = new \MongoDate($newerThanTimestamp); parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false, 'dateModified' => array('$gte' => $startDate)), array(), array('dateCreated' => 1), $limit, $skip); } else { parent::__construct(self::mapper($projectModel->databaseName()), array('isDeleted' => false), array(), array('dateCreated' => 1), $limit, $skip); } }
/** * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->key = ""; $this->name = new SemDomTransTranslatedForm(); $this->description = new SemDomTransTranslatedForm(); $this->searchKeys = new ArrayOf(function ($data) { return new SemDomTransTranslatedForm(); }); $this->questions = new ArrayOf(function ($data) { return new SemDomTransQuestion(); }); $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = "Import Other Language Semantic Domain Projects\n\n"; $languages = array('es', 'fa', 'hi', 'id', 'km', 'ko', 'ne', 'pt', 'ru', 'te', 'th', 'ur', 'zh-CN'); //$languages = array('es', 'fa'); $languageData = new LanguageData(); $languageData->read(); foreach ($languages as $lang) { $projectCode = SemDomTransProjectModel::projectCode($lang); $languageName = $languageData->getLanguage($lang)->name; $projectName = SemDomTransProjectModel::projectName($lang, $languageName); $existingProject = new SemDomTransProjectModel(); $existingProject->readByCode($lang); if ($existingProject->id->asString() != '') { $message .= "{$projectName} already exists! Removing...\n"; if (!$testMode) { $existingProject->remove(); } } if (!$testMode) { $projectId = self::_createEmptyProject($lang, $languageName, $userId); $projectModel = ProjectModel::getById($projectId); $xmlFilePath = APPPATH . "resources/languageforge/semdomtrans/LocalizedLists-{$lang}.xml"; $projectModel->importFromFile($xmlFilePath); } $message .= "Finished importing the {$projectName} \n"; } return $message; }
/** * @param string $projectId * @param string $userId * @param Website $website * @return array */ public static function getSessionData($projectId, $userId, $website) { $sessionData = array(); $sessionData['userId'] = (string) $userId; $sessionData['baseSite'] = $website->base; // Rights $user = new UserModel($userId); $sessionData['userSiteRights'] = $user->getRightsArray($website); if ($projectId) { $project = ProjectModel::getById($projectId); $sessionData['project'] = array(); $sessionData['project']['id'] = (string) $projectId; $sessionData['project']['projectName'] = $project->projectName; $sessionData['project']['appName'] = $project->appName; $sessionData['project']['appLink'] = "/app/{$project->appName}/{$projectId}/"; $sessionData['project']['ownerRef'] = $project->ownerRef->asString(); $sessionData['project']['slug'] = $project->databaseName(); $sessionData['userProjectRights'] = $project->getRightsArray($userId); $sessionData['projectSettings'] = $project->getPublicSettings($userId); } // File Size $postMax = self::fromValueWithSuffix(ini_get("post_max_size")); $uploadMax = self::fromValueWithSuffix(ini_get("upload_max_filesize")); $fileSizeMax = min(array($postMax, $uploadMax)); $sessionData['fileSizeMax'] = $fileSizeMax; //return JsonEncoder::encode($sessionData); // This is handled elsewhere return $sessionData; }
public function onAuthenticationSuccess(Request $request, TokenInterface $token) { $username = $token->getUser()->getUsername(); $user = new UserModel(); $website = Website::get(); if (!$user->readByUserName($username) or $user->role != SystemRoles::SYSTEM_ADMIN and !($user->siteRole->offsetExists($website->domain) and $user->siteRole[$website->domain] != SiteRoles::NONE)) { return $this->httpUtils->createRedirectResponse($request, '/app/logout'); } $request->getSession()->set('user_id', $user->id->asString()); $request->getSession()->set('user', array('username' => $username)); $projectId = $user->getDefaultProjectId($website->domain); if ($projectId) { $request->getSession()->set('projectId', $projectId); } $referer = $this->determineTargetUrl($request); if ($referer and strpos($referer, '/app/') !== false) { return $this->httpUtils->createRedirectResponse($request, $referer); } elseif ($projectId) { $project = ProjectModel::getById($projectId); $url = '/app/' . $project->appName . '/' . $projectId; return $this->httpUtils->createRedirectResponse($request, $url); } else { return $this->httpUtils->createRedirectResponse($request, '/'); } }
/** * * @param ProjectModel $projectModel * @param string $id */ public function __construct($projectModel, $id = '') { $this->id = new Id(); $this->projectRef = new IdReference($projectModel->id->asString()); $this->textRef = new IdReference(); $this->questionRef = new IdReference(); $this->userRef = new IdReference(); $this->userRef2 = new IdReference(); $this->entryRef = new IdReference(); $this->action = $this::UNKNOWN; $this->date = new \DateTime(); // set the timestamp to now $this->actionContent = new MapOf(); // strings $this->addContent($this::PROJECT, $projectModel->projectName); $databaseName = $projectModel->databaseName(); parent::__construct(ActivityModelMongoMapper::connect($databaseName), $id); }
/** * @param string $projectId * @param string $userId * @returns array - the DTO array */ public static function encode($projectId) { $projectModel = ProjectModel::getById($projectId); $list = $projectModel->listUsers(); $data = array(); $data['userCount'] = $list->count; $data['users'] = $list->entries; $data['project'] = array('roles' => $projectModel->getRolesList(), 'ownerRef' => $projectModel->ownerRef, 'name' => $projectModel->projectName, 'appLink' => "/app/{$projectModel->appName}/{$projectId}/"); return $data; }
public function testUserCanAccessMethod_projectPageDto_NotAMember_false() { $userId = $this->environ->createUser('user', 'user', '*****@*****.**', SystemRoles::USER); $project = $this->environ->createProject('projectForTest', 'projTestCode'); $project->appName = 'sfchecks'; $project->write(); $projectId = $project->id->asString(); $project = ProjectModel::getById($projectId); $rh = new RightsHelper($userId, $project, $this->environ->website); $result = $rh->userCanAccessMethod('project_pageDto', array()); $this->assertFalse($result); }
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 testInitializeNewProject_defaultPartOfSpeechOptionListExists() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $optionlists = new \Api\Model\Languageforge\Lexicon\LexOptionListListModel($project); $optionlists->read(); $this->assertEqual(count($optionlists->entries), 0); $project = \Api\Model\ProjectModel::getById($project->id->asString()); $project->initializeNewProject(); $optionlists->read(); $this->assertTrue(count($optionlists->entries) > 0); $this->assertEqual($optionlists->entries[0]['items'][0]['key'], 'adj'); }
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); }
public static function encode($projectId) { $dto = array(); $project = ProjectModel::getById($projectId); $methodPrefix = 'project_management_report_' . $project->appName . '_'; $reports = array(); foreach (get_class_methods('\\Api\\Service\\Sf') as $methodName) { if (strpos($methodName, $methodPrefix) !== FALSE) { $reportId = explode($methodPrefix, $methodName)[1]; $displayName = ucwords(preg_replace('/([A-Z])/', ' $1', $reportId)); $reportId = $project->appName . '_' . $reportId; array_push($reports, array('id' => $reportId, 'name' => $displayName)); } } $dto['reports'] = $reports; return $dto; }
public function __construct($id = '') { parent::__construct($id); }
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; }
/** * * @param int $right * @return bool */ public function userHasProjectRight($right) { return $this->_projectModel->hasRight($this->_userId, $right); }
/** * markUnreadForProjectMembers() is only intended to be called from a child class such as UnreadActivityModel * @param string $itemId * @param ProjectModel $project * @throws \Exception */ public static function markUnreadForProjectMembers($itemId, $project, $questionId = '', $exceptThisUserId = '') { $className = get_called_class(); if ($className == 'Api\\Model\\UserUnreadModel') { throw new \Exception("static method markUnreadForProject cannot be called from base class UserUnreadModel"); } $userList = $project->listUsers(); foreach ($userList->entries as $user) { if ($user['id'] == $exceptThisUserId) { continue; } // TODO: Review: This code is getting cumbersome with if statements for specific child classes. Maybe it's time to move this method to the child classes - cjh 2013/10 if ($questionId != '') { $unreadModel = new $className($user['id'], $project->id->asString(), $questionId); } else { $unreadModel = new $className($user['id'], $project->id->asString()); } $unreadModel->markUnread($itemId); $unreadModel->write(); } }
public function testRemoveUsers_ProjectOwner_NotRemovedFromProject_RestoreErrorDisplay() { // restore error display after last test $this->environ->restoreErrorDisplay(); // read from disk $sameProject = new ProjectModel($this->save['projectId']); $sameUser1 = new UserModel($this->save['user1Id']); $sameUser2 = new UserModel($this->save['user2Id']); // project still has project owner $this->assertEqual($sameProject->listUsers()->count, 1); $this->assertEqual($sameUser1->listProjects($this->environ->website->domain)->count, 0); $this->assertEqual($sameUser2->listProjects($this->environ->website->domain)->count, 1); }
public function setupNgView(Application $app, $appName, $projectId = '') { $siteFolder = NG_BASE_FOLDER . $this->website->base; $parentAppFolder = ''; $appFolder = $this->website->base . '/' . $appName; if ($projectId == 'new') { $parentAppFolder = $appFolder; $appFolder .= '/new-project'; $projectId = ''; $appName = $appName . '-new-project'; } elseif ($projectId == 'manage') { $parentAppFolder = $appFolder; $appFolder .= '/app-management'; $projectId = ''; $appName = $appName . '-app-management'; } if (!file_exists(NG_BASE_FOLDER . $appFolder)) { $appFolder = 'bellows/apps/' . $appName; if (!file_exists(NG_BASE_FOLDER . $appFolder)) { $app->abort(404, $this->website->base); // this terminates PHP } } if ($projectId == 'favicon.ico') { $projectId = ''; } $this->data['appName'] = $appName; $this->data['appFolder'] = $appFolder; $this->data['useMinifiedJs'] = USE_MINIFIED_JS; // update the projectId in the session if it is not empty $projectModel = new ProjectModel(); if ($projectId && $projectModel->exists($projectId)) { $projectModel = $projectModel->getById($projectId); if (!$projectModel->userIsMember((string) $app['session']->get('user_id'))) { $projectId = ''; } $app['session']->set('projectId', $projectId); } else { if (!$projectModel->userIsMember((string) $app['session']->get('user_id'))) { $projectId = ''; } else { $projectId = (string) $app['session']->get('projectId'); } } // Other session data $sessionData = SessionCommands::getSessionData($projectId, (string) $app['session']->get('user_id'), $this->website); $this->data['jsonSession'] = json_encode($sessionData); $this->addJavascriptFiles(NG_BASE_FOLDER . 'bellows/js', array('vendor/', 'assets/')); $this->addJavascriptFiles(NG_BASE_FOLDER . 'bellows/directive'); $this->addJavascriptFiles($siteFolder . '/js'); if (NG_BASE_FOLDER . $parentAppFolder) { $this->addJavascriptFiles(NG_BASE_FOLDER . $parentAppFolder, array('vendor/', 'assets/')); } $this->addJavascriptFiles(NG_BASE_FOLDER . $appFolder, array('vendor/', 'assets/')); if ($appName == 'semdomtrans' || $appName == 'semdomtrans-new-project') { // special case for semdomtrans app // add lexicon JS files since the semdomtrans app depends upon these JS files $this->addJavascriptFiles($siteFolder . '/lexicon', array('vendor/', 'assets/')); } $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . 'bellows/js/vendor'); $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . 'bellows/js/assets'); $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $appFolder . '/js/vendor'); $this->addJavascriptNotMinifiedFiles(NG_BASE_FOLDER . $appFolder . '/js/assets'); $this->addCssFiles(NG_BASE_FOLDER . 'bellows'); $this->addCssFiles(NG_BASE_FOLDER . $appFolder); }
use Api\Model\ProjectListModel; php_sapi_name() == 'cli' or die('this script must be run on the command-line'); $scriptureforgeWebsite = Website::get('scriptureforge.org'); $languageforgeWebsite = Website::get('languageforge.org'); // remove all existing projects $runForReal = false; if (count($argv) > 1 && $argv[1] == 'run') { $runForReal = true; } else { print "\nTest Mode - no data will be changed\n--------------------------------\n\n"; } $projectList = new ProjectListModel(); $projectList->read(); print "{$projectList->count} projects will be deleted\n\n"; foreach ($projectList->entries as $p) { $project = new ProjectModel($p['id']); print "Deleting Project " . $project->projectName . "\n"; if ($runForReal) { try { $project->remove(); } catch (\Exception $e) { // don't do anything } } } // start with a fresh database print "\nDropping main database...\n"; if ($runForReal) { $db = \Api\Model\Mapper\MongoStore::connect(SF_DATABASE); foreach ($db->listCollections() as $collection) { $collection->drop();
/** * Remove this LexEntry from the collection * @param ProjectModel $projectModel * @param string $id */ public static function remove($projectModel, $id) { $databaseName = $projectModel->databaseName(); self::mapper($databaseName)->remove($id); }