Beispiel #1
0
 /**
  * @param string $file Absolute path to our file
  *
  * @return bool|int
  */
 protected static function backupExistingFile($file)
 {
     static $_template = '{file}.{date}.save';
     if (!static::$makeBackups || !file_exists($file)) {
         return true;
     }
     if (!Disk::ensurePath($_path = dirname($file))) {
         throw new \RuntimeException('Unable to create file "' . $file . '"');
     }
     return file_put_contents(str_replace(['{file}', '{date}'], [basename($file), date('YmdHiS')], $_template), file_get_contents($file));
 }
Beispiel #2
0
 /**
  * @return bool
  */
 protected function _backupServiceUsers()
 {
     $_backupPath = base_path() . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'dfe';
     if (!Disk::ensurePath($_backupPath)) {
         $this->writeln('Unable to write to backup path <comment>' . $_backupPath . '</comment>. Aborting.', 'error');
         return false;
     }
     $_users = [];
     /** @type ServiceUser $_user */
     foreach (ServiceUser::all() as $_user) {
         $_users[] = $_user->toArray();
     }
     JsonFile::encodeFile($_backupPath . DIRECTORY_SEPARATOR . 'service-user.backup.' . date('YmdHis') . '.json', $_users);
     return true;
 }
 /**
  * Constructor
  *
  * @param Instance|string $instance        The instance or instance-id to encapsulate
  * @param string|null     $capsuleRootPath The root path of all capsules
  * @param bool            $selfDestruct    If true, encapsulated instances are destroyed when this class does
  */
 public function __construct($instance, $selfDestruct = true, $capsuleRootPath = null)
 {
     $this->instance = $this->findInstance($instance);
     $this->selfDestruct = $selfDestruct;
     $this->capsuleRootPath = Disk::path([$capsuleRootPath ?: config('capsule.root-path', CapsuleDefaults::DEFAULT_PATH), $this->instance->cluster->cluster_id_text]);
     if (!is_dir($this->capsuleRootPath) && !Disk::ensurePath($this->capsuleRootPath)) {
         throw new \RuntimeException('Cannot create, or write to, capsule.root-path "' . $this->capsuleRootPath . '".');
     }
     $this->id = $this->hashIds ? sha1($this->instance->cluster->cluster_id_text . '.' . $this->instance->instance_id_text) : $this->instance->instance_id_text;
 }