/** * Handle the command * * @return mixed */ public function fire() { parent::fire(); $_request = PortableServiceRequest::makeImport($this->argument('instance-id'), $this->argument('snapshot'), array_merge(['owner-id' => $this->argument('owner-id')], $this->getOptions())); $_job = new ImportJob($_request); $_result = $this->dispatch($_job); return [$_result, $_job]; }
/** * Restore portable snapshot data to an instance. If instance does not exist, it is created. * * @param ImportJob $job * * @return array an array keyed by provisioner with the results up each ones import */ public function import(ImportJob $job) { // Validate instance $_instanceId = $job->getInstanceId(); // Validate import file $_snapshotId = $job->getTarget(); $_target = $this->validateImportTarget($_snapshotId); try { // Find instance if it exists... $_instance = $this->_findInstance($_instanceId); } catch (ModelNotFoundException $_ex) { try { $_result = \Artisan::call('dfe:provision', ['owner-id' => $job->getOwner()->id, 'instance-id' => $_instanceId]); if (0 == $_result) { $_instance = $this->_findInstance($_instanceId); } else { throw new ModelNotFoundException(); } } catch (ModelNotFoundException $_ex) { throw new \RuntimeException('The instance could not be provisioned.', Response::HTTP_PRECONDITION_FAILED); } } // Get the services and options $_services = $this->getPortableServices(array_get($_options = $job->getOptions(false), 'guest-location')); // Are we done yet? if (empty($_services)) { $job->setResult(new PortableServiceResponse('Your instance "' . $_instanceId . '" has been created. However, no portable services are available for instance\'s "guest-location".', Response::HTTP_PARTIAL_CONTENT)); return true; } $_imports = []; // Allow each service to import individually, collecting the output $_request = PortableServiceRequest::makeImport($_instance, $_target, array_merge(['snapshot-id' => $_snapshotId], $job->getOptions(false))); foreach ($_services as $_type => $_service) { $_imports[$_type] = $_service->import($_request); } $job->setResult(new PortableServiceResponse($_imports)); return $_imports; }