/** * Create the database and write system files * @throws \Exception */ public function up() { $function = 'function (doc) { var path = doc._id; var dirname = path.replace(/\\/[^\\/]*$/, ""); emit (dirname, doc); }'; $context = \lean\Registry::instance()->get('stack.context'); $context->getShell()->createIndex('stack', 'ls', $function); }
/** * Nuke database */ public function down() { $context = \lean\Registry::instance()->get('stack.context'); $context->pushSecurity(new \stack\security\PriviledgedSecurity()); $shell = $context->getShell(); try { $shell->nuke(); } catch (\stack\filesystem\Exception_FileNotFound $e) { // pass // might happen if a unit test crashes } }
/** * Remove file */ public function down() { $context = \lean\Registry::instance()->get('stack.context'); $shell = $context->getShell(); $context->pushSecurity(new \stack\security\PriviledgedSecurity()); /** * @var Context $context; */ try { $file = $shell->readFile(\stack\Root::ROOT_PATH); $shell->deleteFile($file, true); } catch (\stack\fileSystem\Exception_FileNotFound $e) { // pass // might happen if a unit test crashes } $context->pullSecurity(); }