/** @inheritdoc */
 public function fire()
 {
     parent::fire();
     $this->setOutputPrefix('[' . $this->name . ']');
     if ($this->option('all')) {
         $this->info('Migrating <comment>all</comment> instances');
         $_results = $this->migrateAllInstances();
     } elseif (null !== ($_instanceId = $this->argument('instance-id'))) {
         $this->info('Migrating instance "<comment>' . $_instanceId . '</comment>"');
         $_results = [$_instanceId => $this->migrateSingleInstance($_instanceId)];
     } else {
         $this->error('You must specify an <instance-id> or use the "--all" option.');
         return 1;
     }
     $_file = storage_path(date('YmdHis') . '-migrate-instance.json');
     if (false === JsonFile::encodeFile($_file, $_results)) {
         $this->error('Error storing results to file.');
     }
     return 0;
 }
 /**
  * Refreshes the cache with fresh values
  */
 protected function freshenCache()
 {
     $_cacheFile = Disk::path($this->getCachePath(), true, 0775) . DIRECTORY_SEPARATOR . $this->getCacheKey();
     $this->config['.expires'] = time() + static::CACHE_TTL * 60;
     $this->config['.middleware'] = $this->middleware;
     $this->config['.route-middleware'] = $this->routeMiddleware;
     return JsonFile::encodeFile($_cacheFile, $this->config);
 }
 /**
  * Writes the manifest to disk
  *
  * @param bool $overwrite Overwrite any existing manifest
  *
  * @return bool
  */
 public function write($overwrite = true)
 {
     if (empty($this->_contents)) {
         return false;
     }
     $_filename = $this->getFullFilename();
     if (!$overwrite && file_exists($_filename)) {
         throw new FileException('A manifest already exists and $overwrite is set to "FALSE".');
     }
     JsonFile::encodeFile($_filename, $this->_contents);
     return true;
 }
Exemple #4
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;
 }
 /**
  * Commits a blueprint to the repo
  *
  * @param string $instanceId
  * @param array  $blueprint
  *
  * @return bool
  */
 protected function commitBlueprint($instanceId, $blueprint)
 {
     //  Create/update the file
     $_file = Disk::path([$this->repoPath, $instanceId . '.json']);
     JsonFile::encodeFile($_file, $blueprint, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     //  Commit it
     $_commitMessage = 'Blueprint for instance "' . $instanceId . '" created on ' . date('Y-m-d H:i:s');
     $_response = \Event::fire('dfe.blueprint.pre-commit', ['instance-id' => $instanceId, 'blueprint' => $blueprint, 'repository-path' => $this->repoPath, 'commit-message' => $_commitMessage]);
     //  See if the commit message has changed...
     if (!empty($_response) && null !== ($_message = array_get($_response, 'commit-message'))) {
         $_commitMessage = $_message;
     }
     if (0 !== $this->git->commitChange($_file, $_commitMessage)) {
         \Log::error('Error committing blueprint file "' . $_file . '".');
         return false;
     }
     \Event::fire('dfe.blueprint.post-commit', ['instance-id' => $instanceId, 'blueprint' => $blueprint, 'repository-path' => $this->repoPath]);
     return true;
 }