/** * Update Website SQL entry according to the BackBee installation. * * @return array Returns domain and label set up in database */ private function updateWebsite() { $sites = $this->application->getConfig()->getSection('sites'); $site = array_pop($sites); $configuration = ['domain' => $site['domain'], 'label' => $site['label']]; return $this->fixtureLoader->updateWebsite($configuration); }
/** * 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; }
/** * Class constructor. * * @param BBAplication $application The current BBapplication * @param array $config Optional configurations overriding */ public function __construct(BBApplication $application = null, $config = null) { if (null !== $application) { $this->application = $application; $rendererConfig = $this->application->getConfig()->getRendererConfig(); if (is_array($rendererConfig) && isset($rendererConfig['path'])) { $config = null === $config ? $rendererConfig['path'] : array_merge_recursive($config, $rendererConfig['path']); } } if (is_array($config)) { if (true === array_key_exists('scriptdir', $config)) { $dirs = (array) $config['scriptdir']; array_walk($dirs, array('\\BackBee\\Utils\\File\\File', 'resolveFilepath'), array('base_dir' => $this->getApplication()->getRepository())); foreach ($dirs as $dir) { if (true === file_exists($dir) && true === is_dir($dir)) { $this->_scriptdir[] = $dir; } } if (true === $this->getApplication()->hasContext()) { $dirs = (array) $config['scriptdir']; array_walk($dirs, array('\\BackBee\\Utils\\File\\File', 'resolveFilepath'), array('base_dir' => $this->getApplication()->getBaseRepository())); foreach ($dirs as $dir) { if (true === file_exists($dir) && true === is_dir($dir)) { $this->_scriptdir[] = $dir; } } } } if (true === array_key_exists('layoutdir', $config)) { $dirs = (array) $config['layoutdir']; array_walk($dirs, array('\\BackBee\\Utils\\File\\File', 'resolveFilepath'), array('base_dir' => $this->getApplication()->getRepository())); foreach ($dirs as $dir) { if (true === file_exists($dir) && true === is_dir($dir)) { $this->_layoutdir[] = $dir; } } if (true === $this->getApplication()->hasContext()) { $dirs = (array) $config['layoutdir']; array_walk($dirs, array('\\BackBee\\Utils\\File\\File', 'resolveFilepath'), array('base_dir' => $this->getApplication()->getBaseRepository())); foreach ($dirs as $dir) { if (true === file_exists($dir) && true === is_dir($dir)) { $this->_layoutdir[] = $dir; } } } } } if (null !== $this->application) { $renderer_config = $application->getConfig()->getRendererConfig(); if (true === isset($renderer_config['bb_scripts_directory'])) { $directories = (array) $renderer_config['bb_scripts_directory']; foreach ($directories as $directory) { if (true === is_dir($directory) && true === is_readable($directory)) { $this->_scriptdir[] = $directory; } } } } $this->helpers = new ParameterBag(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $startingTime = microtime(true); $this->bbapp = $this->getContainer()->get('bbapp'); $this->em = $this->bbapp->getEntityManager(); $this->output = $output; if ($input->getOption('verbose')) { $this->output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } else { $this->output->setVerbosity(OutputInterface::VERBOSITY_NORMAL); } $this->em->getConnection()->getConfiguration()->setSQLLogger(null); $this->aclProvider = $this->bbapp->getSecurityContext()->getACLProvider(); $this->entitiesFinder = new EntityFinder(dirname($this->bbapp->getBBDir())); $this->classContentManager = $this->bbapp->getContainer()->get('classcontent.manager')->setBBUserToken($this->bbapp->getBBUserToken()); if (null !== $input->getOption('memory-limit')) { ini_set('memory_limit', $input->getOption('memory-limit')); } $outputCmd = ''; $outputCmd .= $input->getOption('memory-limit') !== null ? ' --m=' . $input->getOption('memory-limit') : ''; $outputCmd .= $input->getOption('user_name') !== null ? ' --user_name=' . $input->getOption('user_name') : ''; $outputCmd .= $input->getOption('user_password') !== null ? ' --user_password='******'user_password') : ''; $outputCmd .= $input->getOption('user_email') !== null ? ' --user_email=' . $input->getOption('user_email') : ''; $outputCmd .= $input->getOption('user_firstname') !== null ? ' --user_firstname=' . $input->getOption('user_firstname') : ''; $outputCmd .= $input->getOption('user_lastname') !== null ? ' --user_lastname=' . $input->getOption('user_lastname') : ''; $outputCmd .= $input->getOption('user_group') !== null ? ' --user_group=' . $input->getOption('user_group') : ''; $outputCmd .= $input->getOption('verbose') ? ' --v' : ''; $this->writeln(sprintf('BEGIN : users:update_rights %s', $outputCmd), OutputInterface::VERBOSITY_NORMAL); // Récupère le fichier users_rights.yml $usersRights = $this->bbapp->getConfig()->getGroupsConfig(); if (null === $this->aclProvider) { throw new \InvalidArgumentException('None ACL provider found'); } // Vérifier que les groups de droit sont bien définis if (false === is_array($usersRights)) { throw new \InvalidArgumentException('Malformed groups.yml file, aborting'); } if ($this->checksBackBeeVersion()) { // Vérification et mise à jour de la structure de la table user $this->checksUserTable(); // Vérification et mise à jour de la structure de la table group (anciennement groups) $this->checksGroupTable(); } // Traitement de l'option clean if ($input->getOption('clean')) { $this->writeln("\n" . '<info>[Cleaning all tables]</info>' . "\n"); $this->cleanTables(); $this->writeln(sprintf('Cleaning done in %d s.', microtime(true) - $startingTime)); } $this->writeln("\n" . '<info>[Check ACL tables existence]</info>' . "\n"); $this->checkAclTables(); // Update des droits $this->writeln("\n" . '<info>[Updating users rights]</info>' . "\n"); $this->updateRights($usersRights); // Update des utilisateurs $this->writeln("\n" . '<info>[Updating/Creating user]</info>' . "\n"); $this->updateUsers($usersRights, $input); $this->writeln(sprintf('<info>Update done in %d s.</info>', microtime(true) - $startingTime), OutputInterface::VERBOSITY_NORMAL); }
/** * Returns an array that contains every declared theme. * * @return array */ protected function getThemes() { $config = $this->app->getConfig()->getThemesConfig(); if (!is_array($config) || !isset($config['options']) || false == $config['options']) { $output->writeln("<info>No theme to install.</info>"); exit(0); } return ThemeTool::getThemesFromOptions($config['options']); }
/** * 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; }
/** * Class constructor. * * @param \BackBee\BBApplication $application */ public function __construct(BBApplication $application) { $this->application = $application; if (null !== ($rewritingConfig = $this->application->getConfig()->getRewritingConfig())) { if (array_key_exists('preserve-online', $rewritingConfig)) { $this->setPreserveOnline(true === $rewritingConfig['preserve-online']); } if (array_key_exists('preserve-unicity', $rewritingConfig)) { $this->setPreserveUnicity(true === $rewritingConfig['preserve-unicity']); } if (isset($rewritingConfig['scheme']) && is_array($rewritingConfig['scheme'])) { $this->schemes = $rewritingConfig['scheme']; } } }
/** * Dispatcher constructor. * * @param \BackBee\BBApplication $application The current instance of BB application */ public function __construct(BBApplication $application = null, Config $config = null) { $this->application = $application; if (null === $config && null !== $application) { $config = $application->getConfig(); } if (null !== $config) { if (null !== ($events_config = $config->getRawSection('events'))) { $this->addListeners($events_config); } } if (null !== $application) { $this->container = $this->application->getContainer(); } $this->_is_restored = false; }
/** * Initiate doctrine connection for the Command on master database if its configure * * @param object $input The input option of command * @param object $output The output of command * * @throws \DatabaseConnectionException When Unable to connect to database */ protected function initConnection($input, $output) { if (null !== $input->getOption('host')) { $connection['host'] = $input->getOption('host'); } if (null !== $input->getOption('port')) { $connection['port'] = $input->getOption('port'); } if (null !== $input->getOption('user')) { $connection['user'] = $input->getOption('user'); } if (null !== $input->getOption('password')) { $connection['password'] = $input->getOption('password'); } $doctrine_config = $this->bbapp->getConfig()->getDoctrineConfig(); if (isset($connection['user']) && isset($connection['password'])) { if (isset($doctrine_config['dbal']['master'])) { $doctrine_config['dbal']['master'] = array_merge($doctrine_config['dbal']['master'], $connection); } else { $doctrine_config['dbal'] = array_merge($doctrine_config['dbal'], $connection); } } // DISABLE CACHE DOCTRINE unset($doctrine_config['dbal']['metadata_cache_driver']); unset($doctrine_config['dbal']['query_cache_driver']); if (!array_key_exists('proxy_ns', $doctrine_config['dbal'])) { $doctrine_config['dbal']['proxy_ns'] = 'Proxies'; } if (!array_key_exists('proxy_dir', $doctrine_config['dbal'])) { $doctrine_config['dbal']['proxy_dir'] = $this->bbapp->getCacheDir() . '/' . 'Proxies'; } try { $em = EntityManagerCreator::create($doctrine_config['dbal']); if (isset($doctrine_config['dbal']['master'])) { $em->getConnection()->connect('master'); } else { $em->getConnection()->connect(); } } catch (\Exception $e) { throw new DatabaseConnectionException('Unable to connect to the database.', 0, $e); } return $em; }
/** * 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; }
/** * Generate a layout thumbnail according to the configuration. * * @access public * * @param Layout $layout The layout to treate * @param BBApplication $app The current instance of BBApplication * * @return mixed FALSE if something wrong, the ressource path of the thumbnail elsewhere */ public function generateThumbnail(Layout $layout, BBApplication $app) { // Is the layout valid ? if (!$layout->isValid()) { return false; } // Is some layout configuration existing ? if (null === $app->getConfig()->getSection('layout')) { return false; } $layoutconfig = $app->getConfig()->getSection('layout'); // Is some thumbnail configuration existing ? if (!isset($layoutconfig['thumbnail'])) { return false; } $thumbnailconfig = $layoutconfig['thumbnail']; // Is gd available ? if (!function_exists('gd_info')) { return false; } $gd_info = gd_info(); // Is the selected format supported by gd ? if (!isset($thumbnailconfig['format'])) { return false; } if (true !== $gd_info[strtoupper($thumbnailconfig['format']) . ' Support']) { return false; } // Is the template file existing ? if (!isset($thumbnailconfig['template'])) { return false; } $templatefile = $thumbnailconfig['template']; $thumbnaildir = dirname($templatefile); File::resolveFilepath($templatefile, null, array('include_path' => $app->getResourceDir())); if (false === file_exists($templatefile) || false === is_readable($templatefile)) { return false; } try { $gd_function = 'imagecreatefrom' . strtolower($thumbnailconfig['format']); $thumbnail = $gd_function($templatefile); $thumbnailfile = $thumbnaildir . '/' . $layout->getUid() . '.' . strtolower($thumbnailconfig['format']); // Is a background color existing ? if (!isset($thumbnailconfig['background']) || !is_array($thumbnailconfig['background']) || 3 != count($thumbnailconfig['background'])) { return false; } $background = imagecolorallocate($thumbnail, $thumbnailconfig['background'][0], $thumbnailconfig['background'][1], $thumbnailconfig['background'][2]); // Is a clipping zone existing ? if (!isset($thumbnailconfig['clip']) || !is_array($thumbnailconfig['clip']) || 4 != count($thumbnailconfig['clip'])) { return false; } $gridcolumn = 12; if (null !== ($lessconfig = $app->getConfig()->getSection('less'))) { if (isset($lessconfig['gridcolumn'])) { $gridcolumn = $lessconfig['gridcolumn']; } } $domlayout = $layout->getDomDocument(); if (!$domlayout->hasChildNodes() || !$domlayout->firstChild->hasChildNodes()) { $this->drawRect($thumbnail, $thumbnailconfig['clip'], $background); } else { $this->drawThumbnailZone($thumbnail, $domlayout->firstChild, $thumbnailconfig['clip'], $background, $gridcolumn); } imagesavealpha($thumbnail, true); $thumbnaildir = dirname(File::normalizePath($app->getCurrentResourceDir() . '/' . $thumbnailfile)); if (false === is_dir($thumbnaildir)) { mkdir($thumbnaildir, 0755, true); } imagepng($thumbnail, File::normalizePath($app->getCurrentResourceDir() . '/' . $thumbnailfile)); } catch (\Exception $e) { return false; } $layout->setPicPath($thumbnailfile); return $layout->getPicPath(); }
/** * Class constructor. * * @access public * * @param \BackBee\BBApplication $application The current BBapplication */ public function __construct(BBApplication $application = null) { $this->application = $application; if (null !== $application) { if (null !== ($parameters_config = $application->getConfig()->getParametersConfig())) { if (true === array_key_exists('force_url_extension', $parameters_config)) { $this->force_url_extension = $parameters_config['force_url_extension']; } } if (false === $this->getRouteCollection()->isRestored()) { $route = $application->getConfig()->getRouteConfig(); if (true === is_array($route) && 0 < count($route)) { $this->registerRoutes('controller', $route); } } } $this->url_extension = self::DEFAULT_URL_EXTENSION; register_shutdown_function(array($this, 'terminate')); }
/** * {@inheritdoc} */ public function __construct(BBApplication $application, $section = 'roles') { $this->_roles = $application->getConfig()->getSecurityConfig($section) ?: array(); }