Example #1
0
 /**
  * Init main tools
  *
  * @return CreateWebsiteCommand
  */
 protected function init(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $this->bbapp = $this->getApplication()->getApplication();
     $this->entyMgr = $this->bbapp->getEntityManager();
     $this->siteLabel = $this->input->getOption('site_label');
     if (filter_var($this->input->getOption('site_domain'), FILTER_VALIDATE_URL)) {
         $urlData = parse_url($this->input->getOption('site_domain'));
         if (!empty($urlData['host']) && $urlData['host'] !== null) {
             $this->siteDomain = $urlData['host'] . (empty($urlData['port']) ? '' : ':' . $urlData['port']) . (empty($urlData['path']) ? '' : $urlData['path']);
         }
     } else {
         throw new \InvalidArgumentException('Invalid site domain format. Example of valid domain: http://backbee.com');
     }
     return $this;
 }
Example #2
0
 /**
  * Insert the user in DB and security.yml file
  *
  * @return CreateSudoerCommand
  */
 protected function runInsertSudoerProcess()
 {
     if (!$this->input->getOption('user_name') || !$this->input->getOption('user_password') || !$this->input->getOption('user_email')) {
         $this->output->writeln('<info>You have to specify all option in order to insert a new superadmin user (--user_name, --user_password, --user_email)</info>');
         return $this;
     }
     # Check if user already exists in db
     if (null === ($adminUser = $this->entyMgr->getRepository('BackBee\\Security\\User')->findOneBy(array('_login' => $this->input->getOption('user_name'))))) {
         $adminUser = $this->createUser($this->input->getOption('user_name'), $this->input->getOption('user_password'), $this->input->getOption('user_email'));
         $this->output->writeln('<info>New user created.</info>');
     }
     # Recreate security.yml
     $securityConf = $this->bbapp->getConfig()->getSecurityConfig();
     if (!array_key_exists($adminUser->getLogin(), $securityConf['sudoers'])) {
         $securityConf['sudoers'][$adminUser->getLogin()] = $adminUser->getId();
         file_put_contents($this->bbapp->getBaseDir() . DIRECTORY_SEPARATOR . 'repository/Config/security.yml', Yaml::dump($securityConf));
         $this->output->writeln('<info>User added in security.yml file.</info>');
     }
     return $this;
 }