/** * @param int $articleID * @return bool */ private function deleteDownloads($articleID) { /* @var ArticleRepository $articleRepository */ $articleRepository = $this->getArticleRepository(); $article = $articleRepository->find($articleID); if (!$article instanceof Article) { return false; } $downloads = $article->getDownloads(); foreach ($downloads as $downloadModel) { $filename = $downloadModel->getFile(); $this->em->remove($downloadModel); /* @var MediaRepository $mediaRepository */ $mediaRepository = $this->getMediaRepository(); $mediaList = $mediaRepository->findBy(['path' => $filename]); foreach ($mediaList as $mediaModel) { $this->em->remove($mediaModel); } } $sql = 'SELECT id FROM s_articles_downloads WHERE articleID = ' . $articleID; $downloads = $this->db->fetchCol($sql); if (!empty($downloads)) { $this->deleteTranslation('download', $downloads); } $this->em->flush(); return true; }
/** * Remove unnecessary menu item of Import/Export Advanced */ private function removeImportExportAdvancedMenuItem() { $oldMenuItem = $this->findMenuItemByLabel(self::OLD_MENU_LABEL); if ($this->menuItemExists($oldMenuItem)) { $this->modelManager->remove($oldMenuItem); $this->modelManager->flush(); } }
/** * Removes the import files on update to version 1.2.2 */ private function removeImportFilesAlbum() { $repo = $this->modelManager->getRepository(Album::class); $album = $repo->findOneBy(['name' => 'ImportFiles']); if ($album) { $this->modelManager->remove($album); $this->modelManager->flush(); } }
/** * @param EntityRepository $menuRepository */ private function removeActualMenuItem(EntityRepository $menuRepository) { /** @var Menu $currentMenuItem */ $currentMenuItem = $menuRepository->findOneBy(['label' => MainMenuItemInstaller::CURRENT_MENU_LABEL]); if ($currentMenuItem instanceof Menu) { $this->modelManger->remove($currentMenuItem); $this->modelManger->flush(); } }
private function removePriceGroup() { $ids = $this->db->fetchCol("SELECT id FROM s_core_pricegroups WHERE description = 'TEST-GROUP'"); foreach ($ids as $id) { $group = $this->entityManager->find('Shopware\\Models\\Price\\Group', $id); $this->entityManager->remove($group); $this->entityManager->flush(); $this->entityManager->clear(); } }
/** * Removes the database entries for themes which file no more exist. */ private function removeDeletedThemes() { $themes = $this->repository->createQueryBuilder('templates'); $themes->where('templates.version = 3')->andWhere('templates.pluginId IS NULL'); $themes = $themes->getQuery()->getResult(AbstractQuery::HYDRATE_OBJECT); /**@var $theme Shop\Template */ foreach ($themes as $theme) { $directory = $this->pathResolver->getDirectory($theme); if (!file_exists($directory)) { $this->entityManager->remove($theme); } } $this->entityManager->flush(); }
private function removeAclResource() { $sql = "SELECT id FROM s_core_acl_resources\n WHERE pluginID = ?;"; $resourceId = $this->db->fetchOne($sql, [$this->getId()]); if (!$resourceId) { return; } $resource = $this->em->getRepository(\Shopware\Models\User\Resource::class)->find($resourceId); foreach ($resource->getPrivileges() as $privilege) { $this->em->remove($privilege); } $this->em->remove($resource); $this->em->flush(); }
/** * Delete resource and its privileges from database * @param $resourceName * @return bool */ public function deleteResource($resourceName) { $repository = $this->em->getRepository('Shopware\\Models\\User\\Resource'); /** @var $resource \Shopware\Models\User\Resource */ $resource = $repository->findOneBy(array("name" => $resourceName)); if (empty($resource)) { return false; } // remove the resource flag in the s_core_menu manually. $this->em->getConnection()->executeUpdate("UPDATE s_core_menu SET resourceID = NULL WHERE resourceID = ?", [$resource->getId()]); //The mapping table s_core_acl_roles must be cleared manually. $this->em->getConnection()->executeUpdate("DELETE FROM s_core_acl_roles WHERE resourceID = ?", [$resource->getId()]); //The privileges will be removed automatically $this->em->remove($resource); $this->em->flush(); return true; }
/** * Helper function which removes all unused configuration containers and elements * which are stored in the database but not in the passed container. * * @param \Doctrine\Common\Collections\ArrayCollection $containers * @param \Doctrine\Common\Collections\ArrayCollection $fields * @param Form\Container $container */ private function removeUnused(ArrayCollection $containers, ArrayCollection $fields, Form\Container $container) { $structure = $this->getContainerNames($container); $structure = $this->eventManager->filter('Theme_Configurator_Container_Names_Loaded', $structure, array('containers' => $container, 'fields' => $fields, 'container' => $container)); /**@var $layout Shop\TemplateConfig\Layout */ foreach ($containers as $layout) { if (!in_array($layout->getName(), $structure['containers'])) { $this->entityManager->remove($layout); } } /**@var $layout Shop\TemplateConfig\Element */ foreach ($fields as $layout) { if (!in_array($layout->getName(), $structure['fields'])) { $this->entityManager->remove($layout); } } $this->entityManager->flush(); }
/** * */ public function refreshPluginList() { $refreshed = \Zend_Date::now(); $repository = $this->em->getRepository('Shopware\\Models\\Plugin\\Plugin'); /** @var $collection \Shopware_Components_Plugin_Namespace */ foreach ($this->plugins as $namespace => $collection) { if (!$collection instanceof \Shopware_Components_Plugin_Namespace) { continue; } foreach (['Local', 'Community', 'Commercial', 'Default'] as $source) { $path = Shopware()->AppPath('Plugins_' . $source . '_' . $namespace); if (!is_dir($path)) { continue; } foreach (new \DirectoryIterator($path) as $dir) { if (!$dir->isDir() || $dir->isDot()) { continue; } $file = $dir->getPathname() . DIRECTORY_SEPARATOR . 'Bootstrap.php'; if (!file_exists($file)) { continue; } $name = $dir->getFilename(); $plugin = $collection->get($name); if ($this->validateIonCube($file)) { throw new \Exception(sprintf('Plugin %s is encrypted but ioncube Loader extension is not installed', $name)); } if ($plugin === null) { $plugin = $collection->initPlugin($name, new \Enlight_Config(['source' => $source, 'path' => $dir->getPathname() . DIRECTORY_SEPARATOR])); } $collection->registerPlugin($plugin); } } } $sql = 'SELECT id, refresh_date FROM s_core_plugins WHERE refresh_date<?'; $pluginIds = Shopware()->Db()->fetchCol($sql, [$refreshed]); foreach ($pluginIds as $pluginId) { $plugin = $repository->find($pluginId); $this->em->remove($plugin); } $this->em->flush(); }