Ejemplo n.º 1
0
 /**
  * AImportBundle's constructor.
  *
  * @param BBApplication $application
  */
 public function __construct(BBApplication $application)
 {
     $this->_application = $application;
     $this->_config = new Config($this->_dir);
     foreach ($this->_application->getConfig()->getSection('doctrine') as $key => $db_config) {
         $this->_config->setSection($key, $db_config, true);
     }
     $this->_relations = $this->_config->getSection('relations');
     if (0 == count($this->_relations)) {
         return false;
     }
     $log_filepath = $application->getConfig()->getLoggingConfig();
     $log_filepath = $log_filepath['logfile'];
     if ('/' !== $log_filepath[0] || false === is_dir(dirname($log_filepath))) {
         $log_filepath = $application->getBaseDir() . '/log/import.log';
     } else {
         $log_filepath = dirname($log_filepath) . '/import.log';
     }
     $logger = new \BackBee\Logging\Appender\File(array('logfile' => $log_filepath));
     $this->setPhpConf($this->_config->getSection('php_ini'));
     foreach ($this->_relations as $class => $config) {
         $type = true === isset($config['type']) ? $config['type'] : 'import';
         try {
             $this->{$type . ucfirst($class)}($config);
         } catch (SkippedImportException $exc) {
             echo $exc->getMessage() . "\n";
         } catch (\Exception $e) {
             $logger->write(array('d' => date('Y/m/d H:i:s'), 'p' => '', 'm' => $e->getMessage(), 'u' => ''));
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Create new site entry inside sites.yml file
  *
  * @return CreateWebsiteCommand
  */
 protected function runSitesYmlProcess()
 {
     $sitesConf = $this->bbapp->getConfig()->getSitesConfig();
     if ($this->siteDomain === null) {
         throw new \InvalidArgumentException('This site domain is not valid (empty value)');
     }
     if (is_array($sitesConf) && array_key_exists($this->siteLabel, $sitesConf)) {
         throw new \InvalidArgumentException('This label `' . $this->siteLabel . '` already present in sites.yml');
     }
     $newSite = [\BackBee\Utils\StringUtils::urlize($this->siteLabel) => ['label' => $this->siteLabel, 'domain' => $this->siteDomain]];
     $newSitesConf = is_array($sitesConf) ? array_merge($sitesConf, $newSite) : $newSite;
     file_put_contents($this->bbapp->getBaseDir() . DIRECTORY_SEPARATOR . 'repository/Config/sites.yml', Yaml::dump($newSitesConf));
     return $this;
 }
Ejemplo n.º 3
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;
 }