From bdc0187c7445178a19486099468dabf9cabcbc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Fri, 8 Oct 2021 15:59:13 +0200 Subject: [PATCH] Fixed migrations issues. --- .../DivanteScheduledExportBundle.php | 1 + src/ScheduledExportBundle/Export/Export.php | 8 ++++---- .../{ => Migrations}/Installer.php | 16 +++------------- .../Model/ScheduledExportRegistry.php | 2 +- .../Resources/config/services.yml | 2 +- 5 files changed, 10 insertions(+), 19 deletions(-) rename src/ScheduledExportBundle/{ => Migrations}/Installer.php (86%) diff --git a/src/ScheduledExportBundle/DivanteScheduledExportBundle.php b/src/ScheduledExportBundle/DivanteScheduledExportBundle.php index 25254f2..70dc781 100644 --- a/src/ScheduledExportBundle/DivanteScheduledExportBundle.php +++ b/src/ScheduledExportBundle/DivanteScheduledExportBundle.php @@ -7,6 +7,7 @@ namespace Divante\ScheduledExportBundle; +use Divante\ScheduledExportBundle\Migrations\Installer; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; diff --git a/src/ScheduledExportBundle/Export/Export.php b/src/ScheduledExportBundle/Export/Export.php index 81b5f4a..ccac8f2 100644 --- a/src/ScheduledExportBundle/Export/Export.php +++ b/src/ScheduledExportBundle/Export/Export.php @@ -124,14 +124,14 @@ public function getExportRegistry() : ScheduledExportRegistry Folder::getByPath($this->objectsFolder)->getId() ?? 0 ); - $exportRegistry = ScheduledExportRegistry::getByGridConfigId($adaptedGridConfigId); - - if (!$exportRegistry) { + try { + $exportRegistry = ScheduledExportRegistry::getByGridConfigId($adaptedGridConfigId); + } catch (Exception $exception) { $exportRegistry = new ScheduledExportRegistry(); $exportRegistry->setGridConfigId($adaptedGridConfigId); $exportRegistry->save(); } - + return $exportRegistry; } diff --git a/src/ScheduledExportBundle/Installer.php b/src/ScheduledExportBundle/Migrations/Installer.php similarity index 86% rename from src/ScheduledExportBundle/Installer.php rename to src/ScheduledExportBundle/Migrations/Installer.php index 53a687e..bef888c 100644 --- a/src/ScheduledExportBundle/Installer.php +++ b/src/ScheduledExportBundle/Migrations/Installer.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Divante\ScheduledExportBundle; +namespace Divante\ScheduledExportBundle\Migrations; use Divante\ScheduledExportBundle\Model\ScheduledExportRegistry; use Divante\ScheduledExportBundle\Model\ScheduledExportRegistry\Dao; @@ -43,21 +43,11 @@ private function installDatabase(): void 'CREATE TABLE IF NOT EXISTS `' . Dao::TABLE_NAME . '` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `gridConfigId` varchar(255) NOT NULL, - `data` varchar(255) NOT NULL, + `data` varchar(255), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;' ); - //insert permission - $key = Dao::TABLE_NAME; - $permission = new Definition(); - $permission->setKey($key); - - $res = new DefinitionDao(); - $res->configure(\Pimcore\Db::get()); - $res->setModel($permission); - $res->save(); - $list = new Listing(); $settings = $list->getSettings(); @@ -68,7 +58,7 @@ private function installDatabase(): void $adaptedGridConfigId = sprintf('%s_%s', $name[0], $name[1]); - $exportRegistry = new ScheduledExportRegistry($adaptedGridConfigId, $item->getData()); + $exportRegistry = new ScheduledExportRegistry($adaptedGridConfigId, (string) $item->getData()); $exportRegistry->save(); } } diff --git a/src/ScheduledExportBundle/Model/ScheduledExportRegistry.php b/src/ScheduledExportBundle/Model/ScheduledExportRegistry.php index d911b4f..6d338d5 100644 --- a/src/ScheduledExportBundle/Model/ScheduledExportRegistry.php +++ b/src/ScheduledExportBundle/Model/ScheduledExportRegistry.php @@ -43,7 +43,7 @@ class ScheduledExportRegistry extends AbstractModel public function __construct(string $gridConfigId = null, $data = null) { - if (!empty($gridConfigId) && !empty($data)) { + if (!empty($gridConfigId)) { $this->setGridConfigId($gridConfigId); $this->setData($data); } diff --git a/src/ScheduledExportBundle/Resources/config/services.yml b/src/ScheduledExportBundle/Resources/config/services.yml index dad1357..c3fd2fd 100644 --- a/src/ScheduledExportBundle/Resources/config/services.yml +++ b/src/ScheduledExportBundle/Resources/config/services.yml @@ -23,7 +23,7 @@ services: tags: - { name: 'process_manager.process', type: 'scheduledexport', form-type: Divante\ScheduledExportBundle\Form\Type\ProcessManager\ScheduledExportType } - Divante\ScheduledExportBundle\Installer: + Divante\ScheduledExportBundle\Migrations\Installer: public: true arguments: $bundle: "@=service('kernel').getBundle('DivanteScheduledExportBundle')"