protected function execute(InputInterface $input, OutputInterface $output) { // load Civi to get access to civicrm_api_get_function_name $civicrm_api3 = $this->getContainer()->get('civicrm_api3'); if (!$civicrm_api3 || !$civicrm_api3->local) { $output->writeln("Requires access to local CiviCRM source tree. Configure civicrm_api3_conf_path.</error>"); return; } if (!preg_match('/^[A-Z][A-Za-z0-9_ \\.\\-]*$/', $input->getArgument('<Label>'))) { throw new Exception("Label should be valid"); } if (!$input->getArgument('<Name>')) { // $input->setArgument('<Name>', \CRM_Utils_String::munge(ucwords(str_replace('_', ' ', $input->getArgument('<Label>'))), '', 0)); $input->setArgument('<Name>', \CRM_Case_XMLProcessor::mungeCasetype($input->getArgument('<Label>'))); } if (!preg_match('/^[A-Z][A-Za-z0-9]*$/', $input->getArgument('<Name>'))) { throw new Exception("Name should be valid (alphanumeric beginning with uppercase)"); } $ctx = array(); $ctx['type'] = 'module'; $ctx['basedir'] = rtrim(getcwd(), '/'); $ctx['caseTypeLabel'] = $input->getArgument('<Label>'); $ctx['caseTypeName'] = $input->getArgument('<Name>'); $basedir = new Path($ctx['basedir']); $info = new Info($basedir->string('info.xml')); $info->load($ctx); $attrs = $info->get()->attributes(); if ($attrs['type'] != 'module') { $output->writeln('<error>Wrong extension type: ' . $attrs['type'] . '</error>'); return; } $dirs = new Dirs(array($basedir->string('xml', 'case'))); $dirs->save($ctx, $output); $xmlFile = $basedir->string('xml', 'case', $ctx['caseTypeName'] . '.xml'); if (!file_exists($xmlFile)) { $output->writeln(sprintf('<info>Write %s</info>', $xmlFile)); file_put_contents($xmlFile, $this->getContainer()->get('templating')->render('CRMCivixBundle:Code:case-type.xml.php', $ctx)); } else { $output->writeln(sprintf('<error>Skip %s: file already exists</error>', $xmlFile)); } $module = new Module($this->getContainer()->get('templating')); $module->loadInit($ctx); $module->save($ctx, $output); }