/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $locale = $this->container->get('models')->getRepository('Shopware\\Models\\Shop\\Locale')->findOneByLocale($input->getArgument('locale'));
     if (!$locale) {
         $output->writeln('<error>Provided locale not found</error>');
         return;
     }
     $filteredQueryBuilder = $this->container->get('models')->getDBALQueryBuilder();
     $localeQueryBuilder = $this->container->get('models')->getDBALQueryBuilder();
     $statement = $localeQueryBuilder->select('DISTINCT CONCAT(s.namespace, s.name) as hash')->from('s_core_snippets', 's')->where('s.localeID = :locale')->setParameter('locale', $locale->getId())->execute();
     $localeSnippets = $statement->fetchAll();
     $statement = $filteredQueryBuilder->select('DISTINCT CONCAT(s.namespace, s.name) as hash, s.namespace', 's.name')->from('s_core_snippets', 's')->where($filteredQueryBuilder->expr()->notIn('CONCAT(s.namespace, s.name)', array_map(function ($item) {
         return "'" . $item['hash'] . "'";
     }, $localeSnippets)))->setParameter('snippets', array_map(function ($item) {
         return $item['hash'];
     }, $localeSnippets))->execute();
     $snippets = $statement->fetchAll();
     $output->writeln('<info></info>');
     $output->writeln('<info>' . count($snippets) . ' missing snippets detected</info>');
     $outputAdapter = new \Enlight_Config_Adapter_File(array('configDir' => $input->getOption('target') . '/'));
     $data = array();
     foreach ($snippets as $snippet) {
         if (!array_key_exists($snippet['namespace'], $data)) {
             $data[$snippet['namespace']] = new \Enlight_Components_Snippet_Namespace(array('name' => $snippet['namespace'], 'section' => array($locale->getLocale())));
         }
         $content = $data[$snippet['namespace']];
         $content->set($snippet['name'], '');
     }
     $output->writeln('<info>' . count($data) . ' namespaces written</info>');
     foreach ($data as $namespace) {
         $outputAdapter->write($namespace, true);
     }
 }
Esempio n. 2
0
 /**
  * Test case
  */
 public function testConfigFileWrite()
 {
     $adapter = new Enlight_Config_Adapter_File(array('configDir' => Enlight_TestHelper::Instance()->TestPath('TempFiles'), 'exclusiveLock' => true, 'skipExtends' => false, 'configType' => 'ini'));
     $config = new Enlight_Config('test');
     $config->setData(array('test' => true));
     $config->setSection('test');
     $adapter->write($config);
 }
Esempio n. 3
0
 /**
  * @param   $dir
  * @return  Shopware_Components_Snippet_Manager
  */
 public function addConfigDir($dir)
 {
     if (!$this->fileAdapter) {
         return $this;
     }
     $this->fileAdapter->addConfigDir($dir);
     return $this;
 }
 /**
  * Dumps all snippets from database into the provided $snippetsDir
  *
  * @param string|null $snippetsDir
  * @param string $localeName
  * @throws \Exception
  */
 public function dumpFromDatabase($snippetsDir, $localeName)
 {
     $snippetsDir = $this->kernelRoot . '/' . $snippetsDir . '/';
     if (!file_exists($snippetsDir)) {
         return;
     }
     $snippetRepository = $this->em->getRepository('Shopware\\Models\\Snippet\\Snippet');
     $locale = $this->em->getRepository('Shopware\\Models\\Shop\\Locale')->findOneByLocale($localeName);
     if (!$locale) {
         throw new \Exception(\sprintf('Locale "%s" not found.', $localeName));
     }
     $outputAdapter = new \Enlight_Config_Adapter_File(array('configDir' => $snippetsDir . '/'));
     $inputAdapter = new \Enlight_Config_Adapter_DbTable(array('db' => $this->db, 'table' => 's_core_snippets', 'namespaceColumn' => 'namespace', 'sectionColumn' => array('localeID', 'shopID')));
     $namespaces = array_map(function ($result) {
         return $result['namespace'];
     }, $snippetRepository->getDistinctNamespacesQuery($locale->getId())->getArrayResult());
     if (count($namespaces) == 0) {
         if ($this->output) {
             $this->output->writeln('<error>No snippets found for the given locale(s)</error>');
         }
         return;
     }
     $data = array();
     foreach ($namespaces as $namespace) {
         if (!array_key_exists($namespace, $data)) {
             $data[$namespace] = true;
             $content = new \Enlight_Components_Snippet_Namespace(array('adapter' => $inputAdapter, 'name' => $namespace, 'section' => array($locale->getId())));
             $content->setSection($locale->getLocale());
             $outputAdapter->write($content, true);
         }
     }
 }