Example #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;
 }
Example #2
0
 /**
  * Creates JSON file from schema
  *
  * @param string $schemaPath Schema path
  * @param array  $arguments  Array of arguments
  *
  * @return boolean
  */
 public function createJsonFileFromSchema($schemaPath, $arguments)
 {
     $jsonManager = new JsonManager();
     $fs = new Filesystem();
     $schema = file_get_contents($schemaPath);
     $validationResult = $jsonManager->validateJson($schema);
     if (true !== $validationResult) {
         throw new \Exception('JSON schema is not valid', 1);
     }
     $decodedSchema = json_decode($schema, true);
     $fileMapping = $this->getFileContent($arguments['version'] . '.txt', $arguments['target']);
     if (!empty($arguments['exclude'])) {
         $fileMapping = $this->exclude($fileMapping, $arguments['exclude']);
     }
     $decodedSchema['changelog'] = $this->getFileContent($arguments['version'] . '_commits.txt', $arguments['target']);
     $decodedSchema['filemapping'] = $fileMapping;
     foreach ($decodedSchema as $key => $value) {
         if (array_key_exists($key, $arguments)) {
             $decodedSchema[$key] = $arguments[$key];
         }
     }
     $filePath = realpath($arguments['target']) . '/' . self::DIFFFILENAME;
     file_put_contents($filePath, json_encode($decodedSchema, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0), LOCK_EX);
     $zipPath = realpath($arguments['target'] . $arguments['version'] . '.zip');
     if ($jsonManager->addJsonToFile($filePath, $zipPath)) {
         $fs->remove(array($filePath));
         return true;
     }
     return false;
 }
Example #3
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;
 }
Example #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;
 }
Example #5
0
 /**
  * Creates JSON file from schema.
  *
  * @param string $schemaPath Schema path
  * @param array  $arguments  Array of arguments
  *
  * @return bool
  */
 public function createJsonFileFromSchema($schemaPath, $arguments)
 {
     $zipPath = realpath($arguments['target'] . $arguments['version'] . '.zip');
     $jsonManager = new JsonManager($zipPath);
     $fileSystem = new Filesystem();
     $schema = file_get_contents($schemaPath);
     $validationResult = $jsonManager->validateJson($schema);
     if (true !== $validationResult) {
         throw new \Exception('JSON schema is not valid', 1);
     }
     $jsonContent = $this->createJsonContentFrom($schema, $arguments);
     $filePath = realpath($arguments['target']) . '/' . self::DIFF_FILENAME;
     file_put_contents($filePath, json_encode($jsonContent, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0), LOCK_EX);
     if ($jsonManager->addJsonToFile($filePath, $zipPath)) {
         $fileSystem->remove(array($filePath));
         return true;
     }
     return false;
 }