Пример #1
0
 /**
  * @throws \RuntimeException
  */
 public static function loadConfig()
 {
     if (!file_exists(GITIFY_WORKING_DIR . '.gitify')) {
         throw new \RuntimeException("Directory is not a Gitify directory: " . GITIFY_WORKING_DIR);
     }
     $config = Gitify::fromYAML(file_get_contents(GITIFY_WORKING_DIR . '.gitify'));
     if (!$config || !is_array($config)) {
         throw new \RuntimeException("Error: " . GITIFY_WORKING_DIR . ".gitify file is not valid YAML, or is empty.");
     }
     return $config;
 }
Пример #2
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->modx->setLogTarget('ECHO');
     $this->modx->setLogLevel(\modX::LOG_LEVEL_INFO);
     if ($input->getOption('all')) {
         // check list and run install for each
         $packages = isset($this->config['packages']) ? $this->config['packages'] : array();
         foreach ($packages as $provider_name => $provider_data) {
             // Try to load the provider from the database
             $provider = $this->modx->getObject('transport.modTransportProvider', array("name" => $provider_name));
             // If no provider found, then we'll create it
             if (!$provider) {
                 $credentials = array('username' => isset($provider_data['username']) ? $provider_data['username'] : '', 'api_key' => '');
                 // Try to look for a file with the API Key from a file within the gitify working directory
                 if (!empty($provider_data['api_key']) && file_exists(GITIFY_WORKING_DIR . '/' . $provider_data['api_key'])) {
                     $credentials['api_key'] = trim(file_get_contents(GITIFY_WORKING_DIR . '/' . $provider_data['api_key']));
                 }
                 // load provider credentials from file
                 if (!empty($provider_data['credential_file']) && file_exists(GITIFY_WORKING_DIR . '/' . $provider_data['credential_file'])) {
                     $credentials_content = trim(file_get_contents(GITIFY_WORKING_DIR . '/' . $provider_data['credential_file']));
                     $credentials = Gitify::fromYAML($credentials_content);
                 }
                 /** @var \modTransportProvider $provider */
                 $provider = $this->modx->newObject('transport.modTransportProvider');
                 $provider->fromArray(array('name' => $provider_name, 'service_url' => $provider_data['service_url'], 'description' => isset($provider_data['description']) ? $provider_data['description'] : '', 'username' => $credentials['username'], 'api_key' => $credentials['api_key']));
                 $provider->save();
             }
             foreach ($provider_data['packages'] as $package) {
                 if (!$input->getOption('interactive')) {
                     $this->setInteractive(false);
                 }
                 $this->install($package, $provider);
             }
         }
         $this->output->writeln("<info>Done!</info>");
         return 0;
     }
     // install defined package
     $this->install($this->input->getArgument('package_name'));
     return 0;
 }
Пример #3
0
 /**
  * Loops over an object folder and parses the files to pass to buildSingleObject
  *
  * @param $folder
  * @param $type
  */
 public function buildObjects($folder, $type)
 {
     if (!file_exists(GITIFY_WORKING_DIR . $folder)) {
         $this->output->writeln('> Skipping ' . $type['class'] . ', ' . $folder . ' does not exist.');
         return;
     }
     $criteria = $this->getPartitionCriteria($type['folder']);
     if (is_null($criteria)) {
         $criteria = array();
     }
     if ($this->isForce) {
         $this->modx->removeCollection($type['class'], $criteria);
         if (isset($type['truncate_on_force'])) {
             foreach ($type['truncate_on_force'] as $class) {
                 $this->output->writeln('> Truncating ' . $class . ' before force building ' . $type['class'] . '...');
                 $this->modx->removeCollection($class, array());
             }
         }
         /**
          * @deprecated 2015-03-30
          *
          * Deprecated in favour of specifying truncate_on_force in the .gitify file.
          */
         switch ($type['class']) {
             // $modx->removeCollection does not automatically remove related objects, which in the case
             // of modCategory results in orphaned modCategoryClosure objects. Normally, this is okay, because
             // Gitify recreates the objects with the same ID. But Categories automatically add the closure on
             // save, which then throws a bunch of errors about duplicate IDs. Worst of all, it _removes_ the
             // category object if it can't save the closure, causing the IDs to go all over the place.
             // So in this case, we make sure all category closures are wiped too.
             case 'modCategory':
                 $this->modx->removeCollection('modCategoryClosure', array());
                 break;
         }
     }
     $directory = new \DirectoryIterator(GITIFY_WORKING_DIR . $folder);
     // Reset the conflicts so we're good to go on new ones
     $this->resetConflicts();
     $this->getExistingObjects($type['class'], $criteria);
     foreach ($directory as $file) {
         /** @var \SplFileInfo $file */
         $name = $file->getBasename();
         // Ignore dotfiles/folders
         if (substr($name, 0, 1) == '.') {
             continue;
         }
         if (!$file->isFile()) {
             $this->output->writeln('- Skipping ' . $file->getType() . ': ' . $name);
             continue;
         }
         // Load the file contents
         $file = file_get_contents($file->getRealPath());
         // Normalize line-endings to \n to ensure consistency
         $file = str_replace("\r\n", "\n", $file);
         $file = str_replace("\r", "\n", $file);
         // Get the raw data, and the content
         list($rawData, $content) = explode(Gitify::$contentSeparator, $file);
         // Turn the raw YAML data into an array
         $data = Gitify::fromYAML($rawData);
         if (!empty($content)) {
             $data['content'] = $content;
         }
         $this->buildSingleObject($data, $type);
     }
     $this->removeOrphans($type);
     $this->resolveConflicts($folder, $type);
 }