Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
$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) {
    $cmd = "mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){  if (i.indexOf(\"sf_\") == 0 || i.indexOf(\"scriptureforge\") == 0) { print(\"Dropping \" + i); db.getSiblingDB(i).dropDatabase()}})'";
    system($cmd);
}
print "\nCreating user: admin password: password\n";
if ($runForReal) {
    $adminUser = UserCommands::createUser(array('id' => '', 'name' => 'Admin', 'email' => '*****@*****.**', 'username' => 'admin', 'password' => 'password', 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $languageforgeWebsite);
}
print "\n\n";
if (is_null($website)) {
    exit("Error: {$hostname} is not a registered website hostname!\n\n");
}
$site = $website->base;
// start with a fresh database
$db = MongoStore::connect(SF_DATABASE);
foreach ($db->listCollections() as $collection) {
    $collection->drop();
}
// Also empty out databases for the test projects
$projectArrays = array($constants['testProjectName'] => $constants['testProjectCode'], $constants['otherProjectName'] => $constants['otherProjectCode']);
foreach ($projectArrays as $projectName => $projectCode) {
    $projectModel = new ProjectModel();
    $projectModel->projectName = $projectName;
    $projectModel->projectCode = $projectCode;
    $db = \Api\Model\Mapper\MongoStore::connect($projectModel->databaseName());
    foreach ($db->listCollections() as $collection) {
        $collection->drop();
    }
}
// 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();
 protected function cleanProjectEnvironment($projectModel)
 {
     // clean out old db if it is present
     $projectDb = \Api\Model\Mapper\MongoStore::connect($projectModel->databaseName());
     foreach ($projectDb->listCollections() as $collection) {
         $collection->drop();
     }
     // clean up assets folder
     $folderPath = $projectModel->getAssetsFolderPath();
     $cleanupFiles = glob($folderPath . '/*');
     foreach ($cleanupFiles as $cleanupFile) {
         @unlink($cleanupFile);
     }
     @rmdir($folderPath);
 }
Ejemplo n.º 5
0
 /**
  * @param string $database
  * @param string $collection
  * @param string $idKey defaults to id
  */
 public function __construct($database, $collection, $idKey = 'id')
 {
     $this->_db = MongoStore::connect($database);
     $this->_collection = $this->_db->{$collection};
     $this->_idKey = $idKey;
 }