/** * @param array $projectIds * @return int Total number of projects removed. */ public static function deleteProjects($projectIds) { CodeGuard::checkTypeAndThrow($projectIds, 'array'); $count = 0; foreach ($projectIds as $projectId) { CodeGuard::checkTypeAndThrow($projectId, 'string'); $project = new \Api\Model\ProjectModel($projectId); $project->remove(); $count++; } // TODO BUG: this does not remove users from a project before the project is deleted // STEP 1: enumerate users in the project // STEP 2: remove the user from the project // STEP 3: delete the project return $count; }
// 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(); } } print "\nDropping other dbs on the server (like test dbs)\n"; if ($runForReal) {
public function testRemove_RemovesProject() { $e = new MongoTestEnvironment(); $project = new ProjectModel($this->_someProjectId); $this->assertTrue($project->exists($this->_someProjectId)); $project->remove(); $this->assertFalse($project->exists($this->_someProjectId)); }