public function testUpdateThenRemove_NewProject_CreatesThenRemovesProjectDatabase()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $databaseName = $project->databaseName();
     $project->remove();
     $db = MongoStore::connect($databaseName);
     $this->assertEqual(count($db->listCollections()), 0);
     $text = new TextModel($project);
     $text->title = 'Some Title';
     $text->write();
     $this->assertTrue(MongoStore::hasDB($databaseName));
     $this->assertEqual(count($db->listCollections()), 1);
     $project->remove();
     $this->assertEqual(count($db->listCollections()), 0);
 }
 /**
  * Create or update project
  * @param string $projectId
  * @param string $userId
  * @param array<projectModel> $object
  * @throws UserUnauthorizedException
  * @throws \Exception
  * @return string projectId
  */
 public static function updateProject($projectId, $userId, $object)
 {
     $project = new LexiconProjectModel($projectId);
     if (!$project->hasRight($userId, Domain::USERS + Operation::EDIT)) {
         throw new UserUnauthorizedException("Insufficient privileges to update project in method 'updateProject'");
     }
     $oldDBName = $project->databaseName();
     $object['id'] = $projectId;
     JsonDecoder::decode($project, $object);
     $newDBName = $project->databaseName();
     if ($oldDBName != '' && $oldDBName != $newDBName) {
         if (MongoStore::hasDB($newDBName)) {
             throw new \Exception("Cannot rename '{$oldDBName}' to ' {$newDBName}' . New project name {$newDBName} already exists.  Not renaming.");
         }
         MongoStore::renameDB($oldDBName, $newDBName);
     }
     $projectId = $project->write();
     return $projectId;
 }
 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();
     }
 }