Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $path = $input->getOption('path');
     $user_name = $input->getArgument('username');
     $password = $input->getOption('password');
     $admin = $input->getOption('admin');
     $active = $input->getOption('active');
     if ($input->getOption('ask-password')) {
         $helper = $this->getHelper('question');
         $question = new Question("Please enter the new password for user {$user_name}: ", null);
         defined('PHPUNIT_SUGARCLI_TESTSUITE') || $question->setHidden(true);
         defined('PHPUNIT_SUGARCLI_TESTSUITE') || $question->setHiddenFallback(true);
         $password = $helper->ask($input, $output, $question);
     }
     $additionnal_fields = array();
     foreach ($this->fields_mapping as $option => $field_name) {
         $value = $input->getOption($option);
         if (!is_null($value)) {
             $additionnal_fields[$field_name] = $value;
         }
     }
     try {
         $um = new UsersManager($this->getService('sugarcrm.entrypoint'));
         if ($this->isCreate($input)) {
             $um->createUser($user_name, $additionnal_fields);
             // Users are active by default.
             if (is_null($active)) {
                 $active = true;
             }
         } else {
             $um->updateUser($user_name, $additionnal_fields);
         }
         if (!is_null($admin)) {
             $um->setAdmin($user_name, $this->getBoolean($admin));
         }
         if (!is_null($active)) {
             $um->setActive($user_name, $this->getBoolean($active));
         }
         if (!is_null($password)) {
             $um->setPassword($user_name, $password);
         }
     } catch (BeanNotFoundException $e) {
         $logger->error("User '{$user_name}' doesn't exists on the SugarCRM located at '{$path}'.");
         return ExitCode::EXIT_USER_NOT_FOUND;
     }
 }
Exemplo n.º 2
0
 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;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @expectedException Inet\SugarCRM\Exception\BeanNotFoundException
  */
 public function testInvalidUser()
 {
     $sugar = $this->getEntryPointInstance();
     $um = new UsersManager($sugar);
     $um->getUserBeanByName('invalid user');
 }