/** * Loads all snippets from all files in $snippetsDir * (including subfolders) and removes them from the database. * * @param null $snippetsDir * @param boolean $removeDirty */ public function removeFromDatabase($snippetsDir = null, $removeDirty = false) { $snippetsDir = $snippetsDir ?: $this->kernelRoot . '/snippets/'; if (!file_exists($snippetsDir)) { return; } $localeRepository = $this->em->getRepository('Shopware\\Models\\Shop\\Locale'); $inputAdapter = new \Enlight_Config_Adapter_File(array('configDir' => $snippetsDir)); $outputAdapter = new \Enlight_Config_Adapter_DbTable(array('db' => $this->db, 'table' => 's_core_snippets', 'namespaceColumn' => 'namespace', 'sectionColumn' => array('shopID', 'localeID'))); $finder = new Finder(); $finder->files()->in($snippetsDir); $defaultLocale = $localeRepository->findOneBy(array('locale' => 'en_GB')); foreach ($finder as $file) { $filePath = $file->getRelativePathname(); if (strpos($filePath, '.ini') == strlen($filePath) - 4) { $namespace = substr($filePath, 0, -4); } else { continue; } if ($this->output) { $this->output->writeln('<info>Processing ' . $namespace . ' namespace</info>'); } $namespaceData = new \Enlight_Components_Snippet_Namespace(array('adapter' => $inputAdapter, 'name' => $namespace)); foreach ($namespaceData->read()->toArray() as $index => $values) { if ($index == 'default') { $locale = $defaultLocale; } else { $locale = $localeRepository->findOneBy(array('locale' => $index)); } $namespaceData->setSection(array(1, $locale->getId()))->read(); $namespaceData->setData($values); $outputAdapter->delete($namespaceData, array_keys($values), $removeDirty); if ($this->output) { $this->output->writeln('<info>Deleted ' . count($values) . ' snippets from ' . $locale->getLocale() . '</info>'); } } if ($this->output) { $this->output->writeln('<info></info>'); } } }
/** * @inheritdoc */ public function write(\Enlight_Config $config, $fields = null, $update = true, $force = false, $allowReset = false) { $this->overwriteWithDefaultShopValues($config); return parent::write($config, $fields, $update, $force, $allowReset); }