示例#1
0
文件: Config.php 项目: civicrm/cv
 /**
  * Update a section of the config
  *
  * @param callable $filter
  *   A filter function which accepts the old config and returns the new config.
  *   Ex: function($data) { $data['x']=123; return $data; }
  * @return bool
  * @throws \RuntimeException
  */
 public static function update($filter)
 {
     $fs = new Filesystem();
     return $fs->update(self::getFileName(), function ($rawIn) use($filter) {
         $data = empty($rawIn) ? array() : json_decode($rawIn, TRUE);
         $data = call_user_func($filter, $data);
         return Encoder::encode($data, 'json-pretty');
     });
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->boot($input, $output);
     if ($input->getOption('out') === 'auto') {
         $hasReturn = preg_match('/^\\s*return[ \\t\\r\\n]/', $input->getArgument('code')) || preg_match('/[;\\{]\\s*return[ \\t\\r\\n]/', $input->getArgument('code'));
         $input->setOption('out', $hasReturn ? \Civi\Cv\Encoder::getDefaultFormat() : 'none');
     }
     $value = eval($input->getArgument('code') . ';');
     $this->sendResult($input, $output, $value);
 }
示例#3
0
文件: ApiCommand.php 项目: civicrm/cv
    protected function configure()
    {
        $this->setName('api')->setDescription('Call an API')->addOption('in', NULL, InputOption::VALUE_REQUIRED, 'Input format (args,json)', 'args')->addOption('out', NULL, InputOption::VALUE_REQUIRED, 'Output format (' . implode(',', Encoder::getFormats()) . ')', Encoder::getDefaultFormat())->addArgument('Entity.action', InputArgument::REQUIRED)->addArgument('key=value', InputArgument::IS_ARRAY)->setHelp('Call an API

Examples:
  cv api system.get
  cv api contact.get id=10
  echo \'{"id":10, "api.Email.get": 1}\' | cv api contact.get --in=json

NOTE: To change the default output format, set CV_OUTPUT.
');
        parent::configureBootOptions();
    }
示例#4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->boot($input, $output);
     $config = Config::read();
     $oldSiteData = empty($config['sites'][CIVICRM_SETTINGS_PATH]) ? array() : $config['sites'][CIVICRM_SETTINGS_PATH];
     $oldJson = Encoder::encode($oldSiteData, 'json-pretty');
     $newJson = $this->editor->editBuffer($oldJson);
     $newSiteData = json_decode($newJson);
     print "NEW DATA\n\n====\n{$newJson}\n====\n";
     //    Config::update(function ($config) use ($newSiteData) {
     //      $config['sites'][CIVICRM_SETTINGS_PATH] = $newSiteData;
     //      return $config;
     //    });
 }
示例#5
0
文件: UrlCommand.php 项目: civicrm/cv
    protected function configure()
    {
        $this->setName('url')->setDescription('Compose a URL to a CiviCRM page')->addArgument('path')->addOption('out', NULL, InputArgument::OPTIONAL, 'Specify return format (json,none,php,pretty,shell)', \Civi\Cv\Encoder::getDefaultFormat())->addOption('relative', 'r', InputOption::VALUE_NONE, 'Prefer relative URL format. (Default: absolute)')->addOption('frontend', 'f', InputOption::VALUE_NONE, 'Generate a frontend URL (Default: backend)')->addOption('open', 'O', InputOption::VALUE_NONE, 'Open a local web browser')->setHelp('
Compose a URL to a CiviCRM page

Examples:
  cv url civicrm/dashboard
  cv url civicrm/dashboard --open
  cv url \'civicrm/a/#/mailing/123?angularDebug=1\'

NOTE: To change the default output format, set CV_OUTPUT.
');
        parent::configureBootOptions();
    }
示例#6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('file')) {
         $this->boot($input, $output);
         $reader = new SiteConfigReader(CIVICRM_SETTINGS_PATH);
         $liveData = $reader->compile(array('buildkit', 'home', 'active'));
     } else {
         $liveData = json_decode(file_get_contents($input->getOption('file')), 1);
     }
     if ($liveData === NULL) {
         throw new \RuntimeException("Failed to extract current configuration.");
     }
     $siteConfig = array();
     foreach ($this->defaults as $field => $value) {
         if (!isset($liveData[$field])) {
             $siteConfig[$field] = $value;
         }
     }
     $output->writeln(sprintf("<info>Site:</info> %s", CIVICRM_SETTINGS_PATH));
     if (empty($siteConfig)) {
         $output->writeln("<info>No extra fields are required.</info>");
     } else {
         $output->writeln(sprintf("<info>These fields were missing. Setting defaults:</info>"));
         $output->writeln(Encoder::encode($siteConfig, 'json-pretty'));
         Config::update(function ($config) use($siteConfig, $output) {
             if (isset($config['sites'][CIVICRM_SETTINGS_PATH])) {
                 $config['sites'][CIVICRM_SETTINGS_PATH] = array_merge($siteConfig, $config['sites'][CIVICRM_SETTINGS_PATH]);
             } else {
                 $config['sites'][CIVICRM_SETTINGS_PATH] = $siteConfig;
             }
             ksort($config['sites'][CIVICRM_SETTINGS_PATH]);
             return $config;
         });
         $output->writeln(sprintf("<info>Please edit</info> %s", Config::getFileName()));
     }
 }
示例#7
0
 protected function configure()
 {
     $this->setName('vars:show')->setDescription('Show the configuration of the local CiviCRM installation')->addOption('out', NULL, InputOption::VALUE_REQUIRED, 'Output format (' . implode(',', Encoder::getFormats()) . ')', Encoder::getDefaultFormat());
     parent::configureBootOptions();
 }
示例#8
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param $result
  */
 protected function sendResult(InputInterface $input, OutputInterface $output, $result)
 {
     $output->writeln(Encoder::encode($result, $input->getOption('out')));
 }