/** * {@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); }
public static function build(BBApplication $application, $objectIdentity) { $matches = array(); if (preg_match(self::$_pattern1, $objectIdentity, $matches)) { return new self($application->getEntityManager(), trim($matches[1]), trim($matches[2])); } elseif (preg_match(self::$_pattern2, $objectIdentity, $matches)) { return new self($application->getEntityManager(), trim($matches[2]), trim($matches[1])); } return new self($application->getEntityManager(), null, null); }
/** * @param \BackBee\BBApplication $application * @param \Doctrine\ORM\EntityManager $em */ public function __construct(BBApplication $application, EntityManager $em = null) { $this->_application = $application; if (null === $em) { $this->_em = $this->_application->getEntityManager(); } else { $this->_em = $em; } $platform = $this->_em->getConnection()->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); $this->_schemaTool = new SchemaTool($this->_em); $this->_entityFinder = new EntityFinder(dirname($this->_application->getBBDir())); }
public function rssAction($uri = null) { if (null === $this->application) { throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR); } if (false === $this->application->getContainer()->has('site')) { throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR); } $site = $this->application->getContainer()->get('site'); if (false !== ($ext = strrpos($uri, '.'))) { $uri = substr($uri, 0, $ext); } if ('_root_' == $uri) { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site); } else { $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates())); } try { $this->application->info(sprintf('Handling URL request `rss%s`.', $uri)); $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false)); $response->headers->set('Content-Type', 'text/xml'); $response->setClientTtl(15); $response->setTtl(15); $this->send($response); } catch (\Exception $e) { $this->defaultAction('/rss/' . $uri); } }
/** * Computes the URL of a page according to a scheme. * * @param array $scheme The scheme to apply * @param Page $page The page * @param AbstractClassContent $content The optionnal main content of the page * @return string The generated URL */ private function doGenerate($scheme, Page $page, AbstractClassContent $content = null) { $replacement = ['$parent' => $page->isRoot() ? '' : $page->getParent()->getUrl(false), '$title' => StringUtils::urlize($page->getTitle()), '$datetime' => $page->getCreated()->format('ymdHis'), '$date' => $page->getCreated()->format('ymd'), '$time' => $page->getCreated()->format('His')]; $matches = []; if (preg_match_all('/(\\$content->[a-z]+)/i', $scheme, $matches)) { foreach ($matches[1] as $pattern) { $property = explode('->', $pattern); $property = array_pop($property); try { $replacement[$pattern] = StringUtils::urlize($content->{$property}); } catch (\Exception $e) { $replacement[$pattern] = ''; } } } $matches = []; if (preg_match_all('/(\\$ancestor\\[([0-9]+)\\])/i', $scheme, $matches)) { foreach ($matches[2] as $level) { $ancestor = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getAncestor($page, $level); if (null !== $ancestor && $page->getLevel() > $level) { $replacement['$ancestor[' . $level . ']'] = $ancestor->getUrl(false); } else { $replacement['$ancestor[' . $level . ']'] = ''; } } } $url = preg_replace('/\\/+/', '/', str_replace(array_keys($replacement), array_values($replacement), $scheme)); return $this->getUniqueness($page, $url); }
/** * Init main tools * * @return CreateSudoerCommand */ protected function init(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->bbapp = $this->getContainer()->get('bbapp'); $this->entyMgr = $this->bbapp->getEntityManager(); return $this; }
/** * Return the current root of the page to be rendered. * * @return null|BackBee\NestedNode\Page */ public function getCurrentRoot() { if (null !== $this->getCurrentPage()) { return $this->getCurrentPage()->getRoot(); } elseif (null === $this->getCurrentSite()) { return; } else { return $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($this->getCurrentSite()); } }
/** * Format the name of an event. * * @param string $event_name * @param object $entity * * @return string the formated event name */ private function formatEventName($event_name, $entity) { if (is_object($entity)) { $event_name = strtolower(str_replace(NAMESPACE_SEPARATOR, '.', get_class($entity)) . '.' . $event_name); if ($entity instanceof \Doctrine\ORM\Proxy\Proxy) { $prefix = str_replace(NAMESPACE_SEPARATOR, '.', $this->application->getEntityManager()->getConfiguration()->getProxyNamespace()); $prefix .= '.' . $entity::MARKER . '.'; $event_name = str_replace(strtolower($prefix), '', $event_name); } } else { $event_name = strtolower(str_replace(NAMESPACE_SEPARATOR, '.', $entity) . '.' . $event_name); } $event_name = str_replace(array('backbee.', 'classcontent.'), array('', ''), $event_name); return $event_name; }
/** * 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; }
/** * Clears cached data associated to the page to be flushed. * * @param \BackBee\Event\Event $event */ public function onFlushPage(Event $event) { // Checks if page caching is available $this->object = $event->getTarget(); if (false === $this->object instanceof Page || false === $this->checkCachePageEvent(false)) { return; } if (true === $this->page_cache_deletion_done) { return; } $pages = ScheduledEntities::getScheduledEntityUpdatesByClassname($this->application->getEntityManager(), 'BackBee\\NestedNode\\Page'); if (0 === count($pages)) { return; } $page_uids = array(); foreach ($pages as $page) { $page_uids[] = $page->getUid(); } $this->cache_page->removeByTag($page_uids); $this->page_cache_deletion_done = true; $this->application->debug(sprintf('Remove cache for `%s(%s)`.', get_class($this->object), implode(', ', $page_uids))); }
/** * Update URL for a page and its descendants according to the application UrlGeneratorInterface. * * @param BBApplication $application * @param Page $page * @param AbstractClassContent $maincontent */ private static function updateUrl(BBApplication $application, Page $page, AbstractClassContent $maincontent = null) { $urlGenerator = $application->getUrlGenerator(); $em = $application->getEntityManager(); $uow = $em->getUnitOfWork(); $changeSet = $uow->getEntityChangeSet($page); if (null === $maincontent && 0 < count($urlGenerator->getDiscriminators())) { if ($uow->isScheduledForInsert($page)) { foreach ($uow->getScheduledEntityInsertions() as $entity) { if ($entity instanceof \BackBee\ClassContent\AbstractClassContent && $page === $entity->getMainNode()) { $maincontent = $entity; break; } } } else { $maincontent = $em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getLastByMainnode($page, $urlGenerator->getDiscriminators()); } } $newUrl = null; $url = $page->getUrl(false); if (isset($changeSet['_url']) && !empty($url)) { $newUrl = $urlGenerator->getUniqueness($page, $page->getUrl()); } else { $force = isset($changeSet['_state']) && !($changeSet['_state'][0] & Page::STATE_ONLINE); $newUrl = $urlGenerator->generate($page, $maincontent, $force); } if ($newUrl !== $page->getUrl(false)) { $page->setUrl($newUrl); $classMetadata = $em->getClassMetadata('BackBee\\NestedNode\\Page'); if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) { $uow->recomputeSingleEntityChangeSet($classMetadata, $page); } elseif (!$uow->isScheduledForDelete($page)) { $uow->computeChangeSet($classMetadata, $page); } return true; } return false; }
/** * Update URL for a page and its descendants according to the application UrlGeneratorInterface. * * @param \BackBee\BBApplication $application * @param \BackBee\NestedNode\Page $page * @param \BackBee\ClassContent\AbstractClassContent $maincontent */ private static function _updateUrl(BBApplication $application, Page $page, AbstractClassContent $maincontent = null) { $urlGenerator = $application->getUrlGenerator(); if (!$urlGenerator instanceof UrlGeneratorInterface) { return; } $em = $application->getEntityManager(); if (null === $maincontent && 0 < count($urlGenerator->getDiscriminators())) { $maincontent = $em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getLastByMainnode($page, $urlGenerator->getDiscriminators()); } $newUrl = $urlGenerator->generate($page, $maincontent); if ($page->getUrl() != $newUrl) { $page->setUrl($newUrl); $uow = $em->getUnitOfWork(); if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) { $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page); } elseif (!$uow->isScheduledForDelete($page)) { $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page); } } }