예제 #1
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Make sure we're not overwriting existing configuration by checking for existing .gitify files
     if (file_exists(GITIFY_WORKING_DIR . '.gitify')) {
         // If the overwrite option is set we'll warn the user but continue anyway
         if ($input->getOption('overwrite')) {
             $output->writeln('<comment>A Gitify project already exists in this directory. If you continue, this will be overwritten.</comment>');
         } else {
             $output->writeln('<error>Error: a Gitify project already exists in this directory.</error> If you wish to continue anyway, specify the --overwrite flag.');
             return 1;
         }
     }
     $helper = $this->getHelper('question');
     // Where we'll store the configuration
     $data = array();
     /**
      * Ask the user for the data directory to store object files in
      */
     $question = new Question('Please enter the name of the data directory (defaults to _data/): ', '_data');
     $directory = $helper->ask($input, $output, $question);
     if (empty($directory)) {
         $directory = '_data/';
     }
     $directory = trim($directory, '/') . '/';
     $data['data_directory'] = $directory;
     if (!file_exists($directory)) {
         mkdir($directory);
     }
     /**
      * Ask the user for a backup directory to store database backups in
      */
     $question = new Question('Please enter the name of the backup directory (defaults to _backup/): ', '_backup');
     $directory = $helper->ask($input, $output, $question);
     if (empty($directory)) {
         $directory = '_backup/';
     }
     $directory = trim($directory, '/') . '/';
     $data['backup_directory'] = $directory;
     if (!file_exists($directory)) {
         mkdir($directory);
     }
     /**
      * Ask if we want to include some default data types
      */
     $dataTypes = array();
     $question = new ConfirmationQuestion('Would you like to include <info>Contexts</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['contexts'] = array('class' => 'modContext', 'primary' => 'key');
         $dataTypes['context_settings'] = array('class' => 'modContextSetting', 'primary' => array('context_key', 'key'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Template Variables</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['template_variables'] = array('class' => 'modTemplateVar', 'primary' => 'name');
         $dataTypes['template_variables_access'] = array('class' => 'modTemplateVarTemplate', 'primary' => array('tmplvarid', 'templateid'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Content</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['content'] = array('type' => 'content', 'exclude_keys' => array('editedby', 'editedon'), 'truncate_on_force' => array('modTemplateVarResource'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Categories</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['categories'] = array('class' => 'modCategory', 'primary' => 'category', 'truncate_on_force' => array('modCategoryClosure'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Templates</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['templates'] = array('class' => 'modTemplate', 'primary' => 'templatename', 'extension' => '.html');
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Chunks</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['chunks'] = array('class' => 'modChunk', 'primary' => 'name', 'extension' => '.html');
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Snippets</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['snippets'] = array('class' => 'modSnippet', 'primary' => 'name', 'extension' => '.php');
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Plugins</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['plugins'] = array('class' => 'modPlugin', 'primary' => 'name', 'extension' => '.php');
         $dataTypes['plugin_events'] = array('class' => 'modPluginEvent', 'primary' => array('pluginid', 'event'));
         $dataTypes['events'] = array('class' => 'modEvent', 'primary' => 'name');
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Namespaces</info>, <info>Extension Packages</info> and <info>System Settings</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['namespaces'] = array('class' => 'modNamespace', 'primary' => 'name');
         $dataTypes['system_settings'] = array('class' => 'modSystemSetting', 'primary' => 'key', 'exclude_keys' => array('editedon'));
         $dataTypes['extension_packages'] = array('class' => 'modExtensionPackage', 'primary' => 'namespace', 'exclude_keys' => array('created_at', 'updated_at'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Form Customization</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['fc_sets'] = array('class' => 'modFormCustomizationSet', 'primary' => 'id');
         $dataTypes['fc_profiles'] = array('class' => 'modFormCustomizationProfile', 'primary' => 'id');
         $dataTypes['fc_profile_usergroups'] = array('class' => 'modFormCustomizationProfileUserGroup', 'primary' => array('usergroup', 'profile'));
         $dataTypes['fc_action_dom'] = array('class' => 'modActionDom', 'primary' => array('set', 'name'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Media Sources</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['mediasources'] = array('class' => 'modMediaSource', 'primary' => 'id');
         $dataTypes['mediasource_elements'] = array('class' => 'sources.modMediaSourceElement', 'primary' => array('source', 'object_class', 'object', 'context_key'));
     }
     $question = new ConfirmationQuestion('Would you like to include <info>Dashboards</info>? <comment>(Y/N)</comment> ', true);
     if ($helper->ask($input, $output, $question)) {
         $dataTypes['dashboards'] = array('class' => 'modDashboard', 'primary' => array('id', 'name'));
         $dataTypes['dashboard_widgets'] = array('class' => 'modDashboardWidget', 'primary' => 'id');
         $dataTypes['dashboard_widget_placement'] = array('class' => 'modDashboardWidgetPlacement', 'primary' => array('dashboard', 'widget'));
     }
     $data['data'] = $dataTypes;
     if (file_exists(GITIFY_WORKING_DIR . 'config.core.php')) {
         $question = new ConfirmationQuestion('Would you like to include a list of <info>Currently Installed Packages</info>? <comment>(Y/N)</comment> ', true);
         if ($helper->ask($input, $output, $question)) {
             $modx = false;
             try {
                 $modx = Gitify::loadMODX();
             } catch (\RuntimeException $e) {
                 $output->writeln('<error>Could not get a list of packages because MODX could not be loaded: ' . $e->getMessage() . '</error>');
             }
             if ($modx) {
                 $providers = array();
                 foreach ($modx->getIterator('transport.modTransportProvider') as $provider) {
                     /** @var \modTransportProvider $provider */
                     $name = $provider->get('name');
                     $providers[$name] = array('service_url' => $provider->get('service_url'));
                     if ($provider->get('description')) {
                         $providers[$name]['description'] = $provider->get('description');
                     }
                     if ($provider->get('username')) {
                         $providers[$name]['username'] = $provider->get('username');
                     }
                     if ($provider->get('api_key')) {
                         $key = $provider->get('api_key');
                         file_put_contents(GITIFY_WORKING_DIR . '.' . $name . '.key', $key);
                         $providers[$name]['api_key'] = '.' . $name . '.key';
                     }
                     $c = $modx->newQuery('transport.modTransportPackage');
                     $c->where(array('provider' => $provider->get('id')));
                     $c->groupby('package_name');
                     foreach ($modx->getIterator('transport.modTransportPackage', $c) as $package) {
                         $packageName = $package->get('signature');
                         $providers[$name]['packages'][] = $packageName;
                     }
                 }
                 $data['packages'] = $providers;
             }
         }
     }
     /**
      * Turn the configuration into YAML, and write the file.
      */
     $config = Gitify::toYAML($data);
     file_put_contents(GITIFY_WORKING_DIR . '.gitify', $config);
     $output->writeln('<info>Gitify Project initiated and .gitify file written.</info>');
     /**
      * Check if we already have MODX installed, and if not, offer to install it right away.
      */
     if (!file_exists(GITIFY_WORKING_DIR . 'config.core.php')) {
         $question = new ConfirmationQuestion('No MODX installation found in the current directory. Would you like to install the latest stable version? <comment>(Y/N)</comment> ', false);
         if ($helper->ask($input, $output, $question)) {
             $command = $this->getApplication()->find('modx:install');
             $arguments = array('command' => 'modx:install');
             $input = new ArrayInput($arguments);
             return $command->run($input, $output);
         }
     }
     return 0;
 }
예제 #2
0
 /**
  * @param \xPDOObject|\modElement $object
  * @param array $options
  * @return string
  */
 public function generate($object, array $options = array())
 {
     $fieldMeta = $object->_fieldMeta;
     $data = $this->objectToArray($object, $options);
     // If there's a dedicated content field, we put that below the yaml for easier managing,
     // unless the object is a modStaticResource, calling getContent on a static resource can break the
     // extracting because it tries to return the (possibly binary) file.
     // the same problem with modDashboardWidget, it's have custom getContent method
     $content = '';
     if (method_exists($object, 'getContent') && !$object instanceof \modStaticResource && !$object instanceof \modDashboardWidget) {
         $content = $object->getContent();
         if (!empty($content)) {
             foreach ($data as $key => $value) {
                 if ($value === $content) {
                     unset($data[$key]);
                 }
             }
         }
     }
     // Strip out keys that have the same value as the default, or are excluded per the .gitify
     $excludes = isset($options['exclude_keys']) && is_array($options['exclude_keys']) ? $options['exclude_keys'] : array();
     foreach ($data as $key => $value) {
         if (isset($fieldMeta[$key]['default']) && $value === $fieldMeta[$key]['default'] || in_array($key, $excludes)) {
             unset($data[$key]);
         }
     }
     $out = Gitify::toYAML($data);
     if (!empty($content)) {
         $out .= Gitify::$contentSeparator . $content;
     }
     return $out;
 }
예제 #3
0
 private function savePackageToFile($packageSignature, $provider)
 {
     $packages = isset($this->config['packages']) ? $this->config['packages'] : array();
     $name = $provider->get('name');
     if ($packages && array_key_exists($name, $packages)) {
         if (in_array($packageSignature, $packages[$name])) {
             return false;
         }
     }
     $configProvider = isset($packages[$name]) ? $packages[$name] : array();
     if (!$configProvider) {
         /** @var \modTransportProvider $provider */
         $configProvider = array('service_url' => $provider->get('service_url'));
         if ($provider->get('description')) {
             $configProvider['description'] = $provider->get('description');
         }
         if ($provider->get('username')) {
             $configProvider['username'] = $provider->get('username');
         }
         if ($provider->get('api_key')) {
             $key = $provider->get('api_key');
             file_put_contents(GITIFY_WORKING_DIR . '.' . $name . '.key', $key);
             $configProvider['api_key'] = '.' . $name . '.key';
         }
     }
     $configProvider['packages'][] = $packageSignature;
     $packages[$name] = $configProvider;
     $this->config['packages'] = $packages;
     $config = Gitify::toYAML($this->config);
     file_put_contents(GITIFY_WORKING_DIR . '.gitify', $config);
     $this->output->writeln("<info>Add {$packageSignature} to .gitify</info>");
     return true;
 }