Beispiel #1
0
 /**
  * Returns the mount to the snapshot itself if it exists here otherwise returns mount to user's snapshot path
  *
  * @return \League\Flysystem\Filesystem|null
  */
 public function getMount()
 {
     if ($this->user) {
         if (!is_dir($_path = $this->user->getSnapshotPath())) {
             return $this->user->getSnapshotMount();
         }
         if (file_exists($_file = Disk::segment([$_path, $this->snapshot_id_text . '.snapshot.zip'], true))) {
             return new Filesystem(new ZipArchiveAdapter($_file));
         }
     }
     return null;
 }
 /** @inheritdoc */
 public function import($request)
 {
     /** @type \ZipArchive $_archive */
     $_archive = null;
     $_from = null;
     $_instance = $request->getInstance();
     $this->info('[provisioning:database:import] instance "' . $_instance->instance_id_text . '" begin');
     //  Grab the target (zip archive) and pull out the target of the import
     $_zip = $request->getTarget();
     /** @noinspection PhpUndefinedMethodInspection */
     $_archive = $_zip->getAdapter()->getArchive();
     foreach ($_zip->listContents() as $_file) {
         if ('dir' != $_file['type'] && false !== strpos($_file['path'], '.database.sql')) {
             $_path = Disk::segment([sys_get_temp_dir(), 'dfe', 'import', sha1($_file['path'])], true);
             if (!$_archive->extractTo($_path, $_file['path'])) {
                 throw new \RuntimeException('Unable to unzip archive file "' . $_file['path'] . '" from snapshot.');
             }
             $_from = Disk::path([$_path, $_file['path']], false);
             if (!$_from || !file_exists($_from)) {
                 throw new \InvalidArgumentException('$from file "' . $_file['path'] . '" missing or unreadable.');
             }
             break;
         }
     }
     /** @type Connection $_db */
     list($_db, $_rootConfig, $_rootServer) = $this->getRootDatabaseConnection($_instance);
     $this->dropDatabase($_db, $_instance->db_name_text);
     $this->createDatabase($_db, ['database' => $_instance->db_name_text]);
     $_results = $this->loadSqlDump($_instance, $_from, $_rootConfig);
     //  Clean up temp space...
     unlink($_from);
     //  Fire off a "database.imported" event...
     \Event::fire('dfe.database.imported', [$this, $request]);
     $this->info('[provisioning:database:import] instance "' . $_instance->instance_id_text . '" complete');
     return $_results;
 }
 /**
  * @param bool   $leading   If true, a leading $separator is pre-pended to result
  * @param string $separator The separator between map parts
  *
  * @return array
  */
 protected function resolvePathFromMap($leading = true, $separator = DIRECTORY_SEPARATOR)
 {
     return Disk::segment(array_only($this->map, ['zone', 'partition', 'root-hash']), $leading, $separator);
 }
 /** @inheritdoc */
 public function import($request)
 {
     $_from = null;
     $_instance = $request->getInstance();
     $_mount = $_instance->getStorageMount();
     $this->info('[provisioning:storage:import] instance "' . $_instance->instance_id_text . '" begin');
     //  Grab the target (zip archive) and pull out the target of the import
     $_zip = $request->getTarget();
     /** @var \ZipArchive $_archive */
     /** @noinspection PhpUndefinedMethodInspection */
     $_archive = $_zip->getAdapter()->getArchive();
     $_path = null;
     foreach ($_zip->listContents() as $_file) {
         if ('dir' != $_file['type'] && false !== strpos($_file['path'], '.storage.zip')) {
             $_from = Disk::segment([sys_get_temp_dir(), 'dfe', 'import', sha1($_file['path'])], true);
             if (!$_archive->extractTo($_from, $_file['path'])) {
                 throw new \RuntimeException('Unable to unzip archive file "' . $_file['path'] . '" from snapshot.');
             }
             $_path = Disk::path([$_from, $_file['path']], false);
             if (!$_path || !file_exists($_path)) {
                 throw new \InvalidArgumentException('$from file "' . $_file['path'] . '" missing or unreadable.');
             }
             $_from = new Filesystem(new ZipArchiveAdapter($_path));
             break;
         }
     }
     if (!$_mount instanceof Filesystem) {
         $_mount = new Filesystem(new ZipArchiveAdapter($_mount));
     }
     //  If "clean" == true, storage is wiped clean before restore
     if (true === $request->get('clean', false)) {
         $_mount->deleteDir('./');
     }
     //  Extract the files
     $_restored = [];
     /** @type Filesystem $_archive */
     foreach ($_from->listContents() as $_file) {
         $_filename = $_file['path'];
         if ('dir' == array_get($_file, 'type')) {
             $_mount->createDir($_filename);
         } else {
             $_mount->writeStream($_filename, $_archive->readStream($_filename));
         }
         $_restored[] = $_file;
     }
     unset($_from);
     $_path && is_dir(dirname($_path)) && Disk::deleteTree(dirname($_path));
     //  Fire off a "storage.imported" event...
     \Event::fire('dfe.storage.imported', [$this, $request]);
     $this->info('[provisioning:storage:import] instance "' . $_instance->instance_id_text . '" complete');
     return $_restored;
 }