/** * * @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)); } }
/** * * @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); } }
/** * * @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->itemKeys = new ArrayOf(); $this->name = ""; $databaseName = $projectModel->databaseName(); parent::__construct(self::mapper($databaseName), $id); }
/** * @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 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); }
/** * * @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); }
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($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; }
/** * 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); }
/** * @param string $projectId * @param array $textIds * @return int Total number of texts removed. */ public static function deleteTexts($projectId, $textIds) { $projectModel = new ProjectModel($projectId); $count = 0; foreach ($textIds as $textId) { TextModel::remove($projectModel->databaseName(), $textId); $count++; } return $count; }
public static function removeComment($projectId, $questionId, $answerId, $commentId) { $projectModel = new \Api\Model\ProjectModel($projectId); return QuestionModel::removeComment($projectModel->databaseName(), $questionId, $answerId, $commentId); }
/** * Creates / Updates a comment on the given answer. * @param string $projectId * @param string $questionId * @param string $answerId * @param array $comment * @param string $userId * @return array Dto */ public static function updateComment($projectId, $questionId, $answerId, $comment, $userId) { $projectModel = new ProjectModel($projectId); $questionModel = new QuestionModel($projectModel, $questionId); $authorId = $userId; if ($comment['id'] != '') { // update existing comment $oldComment = $questionModel->readComment($answerId, $comment['id']); $authorId = $oldComment->userRef->asString(); } $commentModel = new CommentModel(); JsonDecoder::decode($commentModel, $comment); $commentModel->userRef->id = $authorId; $commentId = QuestionModel::writeComment($projectModel->databaseName(), $questionId, $answerId, $commentModel); $questionModel->read($questionId); $newComment = $questionModel->readComment($answerId, $commentId); $commentDTO = QuestionCommentDto::encodeComment($newComment); if ($comment['id'] != '') { // TODO log the activity after we confirm that the comment was successfully updated ; cjh 2013-08 ActivityCommands::updateComment($projectModel, $questionId, $answerId, $newComment); } else { ActivityCommands::addComment($projectModel, $questionId, $answerId, $newComment); } $dto = array(); $dto[$commentId] = $commentDTO; return $dto; }
} } // drop the third database because it is used in a rename test $projectModel = new ProjectModel(); $projectModel->projectName = $constants['thirdProjectName']; $projectModel->projectCode = $constants['thirdProjectCode']; $db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName()); // drop the 'new' and 'empty' database because it is used in a 'create new project' test $projectModel = new ProjectModel(); $projectModel->projectName = $constants['newProjectName']; $projectModel->projectCode = $constants['newProjectCode']; $db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName()); $projectModel = new ProjectModel(); $projectModel->projectName = $constants['emptyProjectName']; $projectModel->projectCode = $constants['emptyProjectCode']; $db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName()); $adminUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['adminName'], 'email' => $constants['adminEmail'], 'username' => $constants['adminUsername'], 'password' => $constants['adminPassword'], 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $website); $managerUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['managerName'], 'email' => $constants['managerEmail'], 'username' => $constants['managerUsername'], 'password' => $constants['managerPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $memberUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['memberName'], 'email' => $constants['memberEmail'], 'username' => $constants['memberUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $expiredUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['expiredName'], 'email' => $constants['expiredEmail'], 'username' => $constants['expiredUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); $resetUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['resetName'], 'email' => $constants['resetEmail'], 'username' => $constants['resetUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website); // set forgot password with expired date $today = new DateTime(); $expiredUser = new UserModel($expiredUserId); $expiredUser->resetPasswordKey = $constants['expiredPasswordKey']; $expiredUser->resetPasswordExpirationDate = $today; $expiredUser->write(); // set forgot password with valid date $resetUser = new UserModel($resetUserId); $resetUser->resetPasswordKey = $constants['resetPasswordKey']; $resetUser->resetPasswordExpirationDate = $today->add(new DateInterval('P5D'));
public function testDatabaseName_Ok() { $project = new ProjectModel(); $project->projectCode = 'Some Project'; $result = $project->databaseName(); $this->assertEqual('sf_some_project', $result); }