/**
  * @param ProjectModel $projectModel
  * @param int $newerThanTimestamp
  */
 public function __construct($projectModel, $newerThanTimestamp = null)
 {
     if (!is_null($newerThanTimestamp)) {
         $startDate = new UTCDateTime(1000 * $newerThanTimestamp);
         parent::__construct(self::mapper($projectModel->databaseName()), array('dateModified' => array('$gte' => $startDate)), array(), array('key' => 1));
     } else {
         parent::__construct(self::mapper($projectModel->databaseName()), array(), array(), array('key' => 1));
     }
 }
 /**
  * @param ProjectModel $projectModel
  * @param int $newerThanTimestamp
  */
 public function __construct($projectModel, $newerThanTimestamp = null)
 {
     new LexProjectModel($projectModel->id->asString());
     if (!is_null($newerThanTimestamp)) {
         $startDate = new UTCDateTime(1000 * $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)
 {
     $this->entries = new ArrayOf(function () use($projectModel) {
         return new LexCommentModel($projectModel);
     });
     // sort ascending by creation date
     if (!is_null($newerThanTimestamp)) {
         $startDate = new UTCDateTime($newerThanTimestamp * 1000);
         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 int $newerThanTimestamp
  * @param int $limit
  * @param int $skip
  */
 public function __construct($projectModel, $newerThanTimestamp = null, $limit = 0, $skip = 0)
 {
     // for use with readAsModels()
     $this->entries = new ArrayOf(function () use($projectModel) {
         return new LexEntryModel($projectModel);
     });
     $lexProject = new LexProjectModel($projectModel->id->asString());
     $this->_config = $lexProject->config;
     if (!is_null($newerThanTimestamp)) {
         $startDate = new UTCDateTime(1000 * $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 string $id
  */
 public function __construct($projectModel, $id = '')
 {
     $this->id = new Id();
     $this->_projectModel = $projectModel;
     $databaseName = $projectModel->databaseName();
     parent::__construct(MessageModelMongoMapper::connect($databaseName), $id);
 }
 /**
  * @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 string $id
  */
 public function __construct($projectModel, $id = '')
 {
     $this->id = new Id();
     $this->content = '';
     $this->regarding = new SemDomTransFieldReference();
     $this->entryRef = new Id();
     $databaseName = $projectModel->databaseName();
     parent::__construct(self::mapper($databaseName), $id);
 }
 /**
  * @param ProjectModel $projectModel
  * @param string $id
  */
 public function __construct($projectModel, $id = '')
 {
     $this->items = new ArrayOf(function () {
         return new LexOptionListItem();
     });
     $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->workflowState = "open";
     // default workflow state
     $this->description = '';
     $this->title = '';
     $this->textRef = new IdReference();
     $this->answers = new MapOf(function () {
         return new AnswerModel();
     });
     $databaseName = $projectModel->databaseName();
     parent::__construct(QuestionModelMongoMapper::connect($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 () {
         return new SemDomTransTranslatedForm();
     });
     $this->questions = new ArrayOf(function () {
         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);
 }
 /**
  * @param ProjectModel|LexProjectModel $projectModel
  * @param string       $id
  */
 public function __construct($projectModel, $id = '')
 {
     $this->setReadOnlyProp('authorInfo');
     $this->setReadOnlyProp('replies');
     $this->setReadOnlyProp('score');
     $this->setReadOnlyProp('status');
     $this->setPrivateProp('isDeleted');
     $this->id = new Id();
     $this->entryRef = new IdReference();
     $this->isDeleted = false;
     $this->replies = new ArrayOf(function () {
         return new LexCommentReply();
     });
     $this->status = self::STATUS_OPEN;
     $this->score = 0;
     $this->authorInfo = new LexAuthorInfo();
     $this->regarding = new LexCommentFieldReference();
     $databaseName = $projectModel->databaseName();
     parent::__construct(self::mapper($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();
     }
 }
 /**
  * TextListModel constructor.
  * @param ProjectModel $project
  */
 public function __construct($project)
 {
     parent::__construct(TextModelMongoMapper::connect($project->databaseName()), array('title' => array('$regex' => '')), array('title'));
 }
 /**
  * @param ProjectModel $project
  */
 protected function cleanProjectEnvironment($project)
 {
     // clean out old db if it is present
     $projectDb = MongoStore::connect($project->databaseName());
     foreach ($projectDb->listCollections() as $collectionInfo) {
         if ($collectionInfo->getName() != 'system.indexes') {
             $collection = $projectDb->selectCollection($collectionInfo->getName());
             $collection->drop();
         }
     }
     // clean up assets folder
     $folderPath = $project->getAssetsFolderPath();
     $cleanupFiles = glob($folderPath . '/*');
     foreach ($cleanupFiles as $cleanupFile) {
         @unlink($cleanupFile);
     }
     @rmdir($folderPath);
 }
 public function testDatabaseName_Ok()
 {
     $project = new ProjectModel();
     $project->projectCode = 'Some Project';
     $result = $project->databaseName();
     $this->assertEquals('sf_some_project', $result);
 }
 /**
  * ActivityListModel constructor.
  * @param ProjectModel $projectModel
  */
 public function __construct($projectModel)
 {
     // hardcoded to limit 100.  TODO implement paging
     $this->entries = new MapOf(function () use($projectModel) {
         return new ActivityModel($projectModel);
     });
     parent::__construct(ActivityModelMongoMapper::connect($projectModel->databaseName()), array('action' => array('$regex' => '')), array(), array('dateCreated' => -1), 100);
 }
 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) {
                         /** @var IdReference $ref */
                         $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 remove()
 {
     $result = self::mapper($this->_projectModel->databaseName())->remove($this->id->asString());
     return $result;
 }
 /**
  * @param string $projectId
  * @param string $questionId
  * @param string $answerId
  * @return int modified count
  */
 public static function removeAnswer($projectId, $questionId, $answerId)
 {
     $projectModel = new ProjectModel($projectId);
     return QuestionModel::removeAnswer($projectModel->databaseName(), $questionId, $answerId);
 }
 /**
  * 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);
 }
 /**
  * QuestionTemplateListModel constructor.
  * @param ProjectModel $projectModel
  */
 public function __construct($projectModel)
 {
     $databaseName = $projectModel->databaseName();
     parent::__construct(self::mapper($databaseName), array(), array('title', 'description'));
 }
    MongoStore::dropAllCollections($projectModel->databaseName());
}
// drop the third database because it is used in a rename test
$projectModel = new ProjectModel();
$projectModel->projectName = $constants['thirdProjectName'];
$projectModel->projectCode = $constants['thirdProjectCode'];
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'];
MongoStore::dropDB($projectModel->databaseName());
$projectModel = new ProjectModel();
$projectModel->projectName = $constants['emptyProjectName'];
$projectModel->projectCode = $constants['emptyProjectCode'];
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);
$observerUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['observerName'], 'email' => $constants['observerEmail'], 'username' => $constants['observerUsername'], 'password' => $constants['observerPassword'], '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'];
 /**
  * @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;
 }
 /**
  * @param ProjectModel $projectModel
  * @param string $textId
  */
 public function __construct($projectModel, $textId)
 {
     parent::__construct(QuestionModelMongoMapper::connect($projectModel->databaseName()), array('description' => array('$regex' => ''), 'textRef' => MongoMapper::mongoID($textId)), array('description'));
 }