public function testRemove_RemovesProject() { new MongoTestEnvironment(); $project = new ProjectModel(self::$savedProjectId); $this->assertTrue($project->exists(self::$savedProjectId)); $project->remove(); $this->assertFalse($project->exists(self::$savedProjectId)); }
public function Run($argv) { $runForReal = false; if (count($argv) > 1 && $argv[1] == 'run') { $runForReal = true; } else { print "\nUsage: FactoryReset.php <run> <DIRECTORY>\n"; print "Run factory reset and restore mongodb and assets from DIRECTORY\n"; print "\nTest Mode - no data will be changed\n--------------------------------\n\n"; } $archivePath = count($argv) > 2 ? $argv[2] : ""; $projectList = new ProjectListModel(); $projectList->read(); // remove all existing projects print "\n{$projectList->count} projects will be deleted\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) { MongoStore::dropAllCollections(SF_DATABASE); } print "\nDropping other dbs on the server (like test dbs)\n"; $cmd = "mongo --quiet {$this->hostOption} --eval 'db.getMongo().getDBNames().forEach(function(i){ " . "if (i.indexOf(\"sf_\") == 0 || i.indexOf(\"scriptureforge\") == 0) { " . "print(\"Dropping \" + i); db.getSiblingDB(i).dropDatabase()}})'"; $this->Execute($runForReal, $cmd); if (is_dir($archivePath)) { print "\nExtracting archives...\n"; foreach (glob("{$archivePath}/*.tgz") as $filename) { print "Extracting {$filename}\n"; $cmd = "tar -xzf {$filename} -C {$archivePath}"; $this->Execute($runForReal, $cmd); } print "\nEnsure www-data has permissions...\n"; $cmd = "sudo chgrp -R www-data {$archivePath}/var/www"; $this->Execute($runForReal, $cmd); $cmd = "sudo chown -R www-data:fieldworks {$archivePath}/var/lib"; $this->Execute($runForReal, $cmd); print "\nRestoring mongodb...\n"; $mongodbBackup = $archivePath . "/mongo_backup"; $cmd = "mongorestore {$this->hostOption} {$mongodbBackup}"; $this->Execute($runForReal, $cmd); print "\nUpdating DB site names...\n"; $this->UpdateDBSiteName($runForReal); print "\nRestoring assets...\n"; $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "--exclude=sfchecks " . "{$archivePath}/var/www/languageforge.org/htdocs/assets/ " . "{$this->lfAssetsPath}/htdocs/assets/"; $this->Execute($runForReal, $cmd); $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "--exclude=lexicon --exclude=semdomtrans " . "{$archivePath}/var/www/scriptureforge.org/htdocs/assets/ " . "{$this->sfAssetsPath}/htdocs/assets/"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$this->lfmergeSendReceivePath}/state/*"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$this->lfmergeSendReceivePath}/webwork/*"; $this->Execute($runForReal, $cmd); $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "{$archivePath}{$this->lfmergeSendReceivePath} {$this->lfmergeSendReceivePath}"; $this->Execute($runForReal, $cmd); print "\nCleanup extracted files...\n"; $cmd = "sudo rm -R {$archivePath}/var"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$archivePath}/mongo_backup"; $this->Execute($runForReal, $cmd); } else { print "\nCreating local user: admin password: password\n"; if ($runForReal) { $scriptureforgeWebsite = Website::get('scriptureforge.org'); $languageforgeWebsite = Website::get('languageforge.org'); $adminUser = UserCommands::createUser(array('id' => '', 'name' => 'Admin', 'email' => '*****@*****.**', 'username' => 'admin', 'password' => 'password', 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $languageforgeWebsite); } } }