/** * Execute the command * * @param InputInterface $input * @param OutputInterface $output * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $ep = $this->getService('sugarcrm.entrypoint'); $bm = new BeanManager($ep); $this->module = $input->getOption('module'); // Get the file as a parameter if (empty($this->module)) { $moduleList = array_keys($ep->getBeansList()); $msg = 'You must define the module with --module'; $msg .= PHP_EOL . PHP_EOL . 'List of Available modules: ' . PHP_EOL; $msg .= ' - ' . implode(PHP_EOL . ' - ', $moduleList); throw new \InvalidArgumentException($msg); } ########### FIELDS $moduleFields = $bm->getModuleFields($this->module, $input->getOption('lang'), true); // Change the lists that are arrays as strings foreach ($moduleFields as $key => $moduleProps) { if (array_key_exists('options_list', $moduleProps)) { $optionsList = ''; foreach ($moduleFields[$key]['options_list'] as $optK => $optV) { $optionsList .= "{$optK}<=>{$optV}" . PHP_EOL; } $moduleFields[$key]['options_list'] = $optionsList; } else { $moduleFields[$key]['options_list'] = 'N/A'; } } // create the writer $writer = new CsvWriter(array('delimiter' => ';', 'enclosure' => '"', 'encoding' => 'UTF-8', 'bom' => false, 'first_row_header' => true, 'trim' => true)); $file = $this->module . '-Fields.' . date('Y-m-d') . '.csv'; //Open the csv file to write $writer->open(getcwd() . '/' . $file); $writer->writeRows($moduleFields); $writer->close(); $output->writeln("<comment>All fields for {$this->module} written in {$file}</comment>"); ########### RELATIONSHIPS $moduleRelationships = $bm->getModuleRelationships($this->module); // create the writer $writer = new CsvWriter(array('delimiter' => ';', 'enclosure' => '"', 'encoding' => 'UTF-8', 'bom' => false, 'first_row_header' => true, 'trim' => true)); $file = $this->module . '-Relationships.' . date('Y-m-d') . '.csv'; //Open the csv file to write $writer->open(getcwd() . '/' . $file); $writer->writeRows($moduleRelationships); $writer->close(); $output->writeln("<comment>All relationships for {$this->module} written in {$file}</comment>"); }
protected function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getService('logger'); $path = $input->getOption('path'); $user_name = $input->getOption('username'); $lang = $input->getOption('lang'); $fields = explode(',', $input->getOption('fields')); $pretty = !$input->getOption('raw'); $bm = new BeanManager($this->getService('sugarcrm.entrypoint')); $bean_list = array(); try { if (!empty($user_name)) { $um = new UsersManager($this->getService('sugarcrm.entrypoint')); $bean_list[] = $um->getUserBeanByName($user_name); } else { $bean_list = $bm->getList('Users'); } } catch (BeanNotFoundException $e) { $logger->error("User '{$user_name}' doesn't exists on the SugarCRM located at '{$path}'."); return ExitCode::EXIT_USER_NOT_FOUND; } $format = $input->getOption('format'); if ($format === 'text') { // Output table $table = new Table($output); $table->setStyle('borderless'); $fields_data = $bm->beanListToArray($fields, $bean_list, $pretty, $lang); $table->setHeaders(array_keys($fields_data[0])); $table->setRows($fields_data); $table->render(); } else { $serial = SerializerBuilder::create()->build(); try { $output->write($serial->serialize($bm->beanListToArray($fields, $bean_list, $pretty, $lang), $format)); } catch (UnsupportedFormatException $e) { $output->write("<comment>Format {$format} is not supported.</comment>\n"); return ExitCode::EXIT_FORMAT_ERROR; } } }
/** * Get, from the known files, the list of hooks defined in the system * @param string $module * @return array List of Hooks */ public function getHooksDefinitionsFromFiles($module, $byFiles = true) { $modulesList = array_keys($this->getEntryPoint()->getBeansList()); if (!in_array($module, $modulesList)) { throw new BeanNotFoundException("{$module} is not a valid module name"); } $hooks = array(); // Create a new find to locate all the files where hooks could be defined $beanManager = new Bean($this->getEntryPoint()); $bean = $beanManager->newBean($module); $files = array(); // process the main file $mainFile = 'custom/modules/' . $beanManager->getModuleDirectory($module) . '/logic_hooks.php'; if (file_exists($mainFile)) { $files[] = $mainFile; } // find files in ExtDir $customExtDir = 'custom/Extension/modules/' . $beanManager->getModuleDirectory($module) . '/Ext/LogicHooks/'; if (is_dir($customExtDir)) { $finder = new Finder(); $finder->files()->in($customExtDir)->name('*.php'); foreach ($finder as $file) { $files[] = $customExtDir . $file->getRelativePathname(); } } // read file and exit as soon as we find one $hooksDefs = array(); foreach ($files as $file) { if ($byFiles === true) { $hook_array = array(); } require $file; $hooksDefs[$file] = $hook_array; } return $byFiles === true ? $hooksDefs : $hook_array; }
public function testRightInstanciation() { // first load a bean $entryPoint = $this->getEntryPointInstance(); // My beans are empty: I have never loaded anything BeanFactoryCache::clearCache(); $loadedBeans = BeanFactoryCache::getLoadedBeans(); $this->assertEmpty($loadedBeans); $DBTest = new DBTest(); $sugarDB = $DBTest->rightInstanciation(); $sugarBean = new Bean($entryPoint, $sugarDB); $sugarBean->getBean('Users', 1, array(), true, true); // Now it contains something $loadedBeans = BeanFactoryCache::getLoadedBeans(); $this->assertNotEmpty($loadedBeans); // Now it's empty again BeanFactoryCache::clearCache(); $loadedBeans = BeanFactoryCache::getLoadedBeans(); $this->assertEmpty($loadedBeans); }