예제 #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return bool
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $filePath = $input->getArgument('file');
     if (!file_exists($filePath)) {
         throw new \Exception($filePath . ' not found.', 1);
     }
     if (!is_readable($filePath)) {
         throw new \Exception($filePath . ' is not readable.', 1);
     }
     $jsonManager = new JsonManager($filePath);
     $schema = file_get_contents(realpath(__DIR__ . FilesManager::SCHEMA_FILE_PATH));
     $json = $jsonManager->getJsonFromFile();
     if (!is_string($json)) {
         $output->writeln("<error>Can't read json from file.</error>");
         return false;
     }
     try {
         $jsonManager->validateSchema($json, $schema);
     } catch (JsonException $e) {
         $output->writeln('<comment>' . $e->getMessage() . '</comment>');
         foreach ((array) $e->getErrors() as $error) {
             $output->writeln('<error>' . $error . '</error>');
         }
         return false;
     }
     $output->writeln('<info>* Syntax of a JSON string is valid!</info>');
     $output->writeln('<info>* JSON validates against the schema!</info>');
     $packageSpec = json_decode($json, true);
     $output->writeln('<info>Package version:</info>        ' . $packageSpec['version']);
     $output->writeln('<info>Package description:</info>    ' . $packageSpec['description']);
     $output->writeln('<info>Package maintainer:</info>     ' . $packageSpec['maintainer']);
     $output->writeln('<info>Package changelog:</info>      ' . implode(', ', $packageSpec['changelog']));
     $output->writeln('<info>* All is valid!</info>');
     return true;
 }
예제 #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $tempDir = $input->getArgument('temp_dir');
     $targetDir = $input->getArgument('target');
     $packageDir = $input->getArgument('package_dir');
     $rollback = $input->getOption('rollback');
     $updater = new Updater();
     $jsonManager = new JsonManager($packageDir);
     $updater->setPackageService(new PackageService())->setTempDir($tempDir)->setWorkingDir($targetDir);
     $updateService = new UpdateService($updater);
     $packageService = $updater->getPackageService();
     $diffFile = $jsonManager->getJsonFromFile();
     $packageJson = json_decode($diffFile, true);
     $package = $packageService->fillPackage($packageJson);
     $package->setPackageDir(realpath($packageDir));
     $updateService->setPackage($package);
     if ($rollback) {
         $updateService->rollbackUpdate();
         $output->writeln('<info>Changes have been rollbacked.</info>');
         return true;
     }
     $isUpdated = $updateService->doUpdate();
     if ($isUpdated) {
         $output->writeln('<info>Your application has been successfully updated.</info>');
         return true;
     }
     $output->writeln('<error>Error occured. Your application was not updated. Rolling back changes.</error>');
     return false;
 }
예제 #3
0
 /**
  * Get packages dir and file name to get update.json content in array.
  *
  * @param string $packagesDir Directory with update packages
  * @param string $zipFileName Update package file name
  *
  * @return array Array witgh update packages definitions
  */
 public function getSpecFromZip($packagesDir, $zipFileName = null)
 {
     $jsonManager = new JsonManager($packagesDir);
     $packages = array();
     foreach (new \RecursiveDirectoryIterator($packagesDir) as $file) {
         if (!$file->isFile()) {
             continue;
         }
         if (!extension_loaded('zip')) {
             throw new \Exception('You need to have zip extension enabled');
         }
         if ($zipFileName !== null) {
             if ($file->getFilename() != $zipFileName) {
                 continue;
             }
         }
         $json = $jsonManager->getJsonFromFile($file->getPathname());
         if ($json === false) {
             continue;
         }
         if (!$jsonManager->validateJson($json)) {
             continue;
         }
         $packages[] = json_decode($json, true);
     }
     return $packages;
 }
예제 #4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return boolean
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!file_exists($file)) {
         throw new \Exception($file . ' not found.', 1);
     }
     if (!is_readable($file)) {
         throw new \Exception($file . ' is not readable.', 1);
     }
     $jsonManager = new JsonManager();
     $schema = file_get_contents(realpath(__DIR__ . '/../../../schema/') . '/updater-schema.json');
     $json = $jsonManager->getJsonFromFile('update.json', realpath($file));
     $validationResult = $jsonManager->validateJson($json);
     if (true !== $validationResult) {
         $output->writeln('<error>* JSON inside update package isn\'t valid!</error>');
         $output->writeln('<error>' . $validationResult->getMessage() . '<error>');
         return true;
     } else {
         $output->writeln('<info>* JSON inside update package is valid!</info>');
     }
     $schemaResult = $jsonManager->validateSchema($json, $schema);
     if (true !== $schemaResult) {
         $output->writeln('<error>* JSON does not validate!</error>');
     } else {
         $output->writeln('<info>* JSON validates against the schema!</info>');
     }
     $packageSpec = json_decode($json, true);
     $output->writeln('<info>Package version:</info>        ' . $packageSpec['version']);
     $output->writeln('<info>Package description:</info>    ' . $packageSpec['description']);
     $output->writeln('<info>Package maintainer:</info>     ' . $packageSpec['maintainer']);
     $output->writeln('<info>Package changelog:</info>      ' . implode(', ', $packageSpec['changelog']));
     $output->writeln('<info>* All valid!</info>');
     return true;
 }