protected function execute(InputInterface $input, OutputInterface $output) { $identifier = $input->getArgument('identifier'); if (!$identifier) { $identifier = '1799-Auobj'; } $path = utils::normalize(__DIR__ . "/../data/{$identifier}.json"); $content = file_get_contents($path); $data = json_decode($content); $localFile = utils::normalize(__DIR__ . "/../tmp/{$data->name}"); $file = fopen($localFile, 'wb'); $http = new \ADN\Extract\HttpRequest($data->uri, [], null, null); $response = $http->get(function ($code, $chunk) use($file, $data, $path) { if ($code != 'data') { return false; } fwrite($file, $chunk); $data->bytesRead += strlen($chunk); file_put_contents($path, json_encode($data)); return true; }); fclose($file); if (!$response || $response->code != Response::HTTP_OK) { $output->writeln('oops'); $fs = new Filesystem(); $fs->remove($path); $fs->remove($localFile); return; } $data->size = utils::findKey($response->headers, 'Content-Length'); $data->bytesRead = $data->size; file_put_contents($path, json_encode($data)); utils::log('ok'); }
public function viewsDir($plus = '', $real = false) { if ($real) { return utils::realpath("{$this->rootDir}/views{$plus}"); } else { return utils::normalize("{$this->rootDir}/views{$plus}"); } }
protected function getChunkFilename($chunkNumber, $identifier) { // Clean up the identifier $identifier = $this->cleanIdentifier($identifier); // What would the file name be? $this->initConfig(); return utils::normalize($this->config->getTempDir() . "/flow-{$identifier}.{$chunkNumber}"); }
protected function PackItems($results) { // We got all d/l try { // We are done! Create a ZIP file $zip = new \ZipArchive(); $output = $this->lmv->extractDir("/{$this->identifier}.zip"); $zip->open($output, \ZipArchive::CREATE); $zip->addEmptyDir($this->identifier); $path = $this->lmv->dataDir("/{$this->identifier}"); $finder = new Finder(); $finder->files()->in($path); foreach ($finder as $file) { $zpath = utils::postStr('/data/', utils::normalize($file->getRealpath())); $zip->addFile($file->getRealpath(), $zpath); } $zip->close(); utils::log('PackItems ended successfully.'); } catch (Exception $err) { utils::log('PackItems exception'); throw $err; } }