From 39845ce5d616d72079bfb551f7fadf389cd44312 Mon Sep 17 00:00:00 2001 From: Dominique Feyer Date: Tue, 18 Jul 2017 19:23:33 +0200 Subject: [PATCH 1/2] TASK: Add support for PostgreSQL --- Classes/Command/ImportCommandController.php | 7 ++- Classes/Domain/Model/Import.php | 25 ++++----- Classes/Domain/Service/ImportService.php | 2 +- Migrations/Mysql/Version20170718190551.php | 42 +++++++++++++++ .../Postgresql/Version20170718190551.php | 51 +++++++++++++++++++ 5 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 Migrations/Mysql/Version20170718190551.php create mode 100644 Migrations/Postgresql/Version20170718190551.php diff --git a/Classes/Command/ImportCommandController.php b/Classes/Command/ImportCommandController.php index 5573943..2f82177 100644 --- a/Classes/Command/ImportCommandController.php +++ b/Classes/Command/ImportCommandController.php @@ -139,6 +139,7 @@ public function batchCommand($preset, $parts = null, $batchSize = null, $externa $this->checkForPartsSettingsOrQuit($presetSettings, $preset); + array_walk($presetSettings['parts'], function ($partSetting, $partName) use ($preset, $parts, $batchSize) { $this->elapsedTime = 0; $this->batchCounter = 0; @@ -166,13 +167,15 @@ public function batchCommand($preset, $parts = null, $batchSize = null, $externa } }); + $this->importService->stop(); + $import = $this->importService->getLastImport(); $this->outputLine(); $this->outputLine('Import finished.'); - $this->outputLine(sprintf(' Started %s', $import->getStart()->format(DATE_RFC2822))); - $this->outputLine(sprintf(' Finished %s', $import->getEnd()->format(DATE_RFC2822))); + $this->outputLine(sprintf(' Started %s', $import->getStartTime()->format(DATE_RFC2822))); + $this->outputLine(sprintf(' Finished %s', $import->getEndTime()->format(DATE_RFC2822))); $this->outputLine(sprintf(' Runtime %d seconds', $import->getElapsedTime())); $this->outputLine(); $this->outputLine('See log for more details and possible errors.'); diff --git a/Classes/Domain/Model/Import.php b/Classes/Domain/Model/Import.php index c3344a7..f6799e7 100644 --- a/Classes/Domain/Model/Import.php +++ b/Classes/Domain/Model/Import.php @@ -20,13 +20,13 @@ class Import /** * @var \DateTime */ - protected $start; + protected $startTime; /** * @var \DateTime * @ORM\Column(nullable=true) */ - protected $end; + protected $endTime; /** * @var string @@ -52,7 +52,7 @@ class Import public function initializeObject($initializationCause) { if ($initializationCause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) { - $this->start = new \DateTime(); + $this->startTime = new \DateTimeImmutable(); $this->addImportStartedEvent(); } } @@ -74,6 +74,7 @@ public function getExternalImportIdentifier() { return $this->externalImportIdentifier; } + /** * @param string $eventType * @param string $externalIdentifier @@ -123,19 +124,19 @@ protected function addImportEndedEvent() } /** - * @return \DateTime + * @return \DateTimeImmutable */ - public function getStart() + public function getStartTime() { - return $this->start; + return $this->startTime; } /** - * @return \DateTime + * @return \DateTimeImmutable */ - public function getEnd() + public function getEndTime() { - return $this->end; + return $this->endTime; } /** @@ -143,7 +144,7 @@ public function getEnd() */ public function getElapsedTime() { - return (integer) $this->end->getTimestamp() - $this->start->getTimestamp(); + return (integer) $this->endTime->getTimestamp() - $this->startTime->getTimestamp(); } /** @@ -151,10 +152,10 @@ public function getElapsedTime() */ public function end() { - if ($this->end instanceof \DateTime) { + if ($this->endTime instanceof \DateTimeImmutable) { throw new Exception('This import has ended earlier', 1426763297); } - $this->end = new \DateTime(); + $this->endTime = new \DateTimeImmutable(); $this->addImportEndedEvent(); } } diff --git a/Classes/Domain/Service/ImportService.php b/Classes/Domain/Service/ImportService.php index 360c4be..cdb63c9 100644 --- a/Classes/Domain/Service/ImportService.php +++ b/Classes/Domain/Service/ImportService.php @@ -78,7 +78,7 @@ public function start($externalImportIdentifier = null, $force = false) if ($externalImportIdentifier !== null) { $existingImport = $this->importRepository->findOneByExternalImportIdentifier($externalImportIdentifier); if (!$force && $existingImport instanceof Import) { - throw new ImportAlreadyExecutedException(sprintf('An import referring to the external identifier "%s" has already been executed on %s.', $externalImportIdentifier, $existingImport->getStart()->format('d.m.Y h:m:s')), 1464028408403); + throw new ImportAlreadyExecutedException(sprintf('An import referring to the external identifier "%s" has already been executed on %s.', $externalImportIdentifier, $existingImport->getStartTime()->format('d.m.Y h:m:s')), 1464028408403); } } diff --git a/Migrations/Mysql/Version20170718190551.php b/Migrations/Mysql/Version20170718190551.php new file mode 100644 index 0000000..d97fd31 --- /dev/null +++ b/Migrations/Mysql/Version20170718190551.php @@ -0,0 +1,42 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on "mysql".'); + + $this->addSql('ALTER TABLE ttree_contentrepositoryimporter_domain_model_import CHANGE start starttime DATETIME NOT NULL, end endtime DATETIME DEFAULT NULL'); + } + + /** + * @param Schema $schema + * @return void + */ + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on "mysql".'); + + $this->addSql('ALTER TABLE ttree_contentrepositoryimporter_domain_model_import CHANGE starttime start DATETIME NOT NULL, endtime end DATETIME DEFAULT NULL'); + } +} diff --git a/Migrations/Postgresql/Version20170718190551.php b/Migrations/Postgresql/Version20170718190551.php new file mode 100644 index 0000000..af29e9b --- /dev/null +++ b/Migrations/Postgresql/Version20170718190551.php @@ -0,0 +1,51 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on "postgresql".'); + + $this->addSql('CREATE TABLE ttree_contentrepositoryimporter_domain_model_import (persistence_object_identifier VARCHAR(40) NOT NULL, starttime TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, endtime TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, externalimportidentifier VARCHAR(255) DEFAULT NULL, PRIMARY KEY(persistence_object_identifier))'); + $this->addSql('CREATE TABLE ttree_contentrepositoryimporter_domain_model_recordmapping (persistence_object_identifier VARCHAR(40) NOT NULL, creationdate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, modificationdate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, importerclassname VARCHAR(255) NOT NULL, importerclassnamehash VARCHAR(32) NOT NULL, externalidentifier VARCHAR(255) NOT NULL, externalrelativeuri VARCHAR(255) DEFAULT NULL, nodeidentifier VARCHAR(255) NOT NULL, nodepath VARCHAR(4000) NOT NULL, nodepathhash VARCHAR(32) NOT NULL, PRIMARY KEY(persistence_object_identifier))'); + $this->addSql('CREATE INDEX nodepathhash ON ttree_contentrepositoryimporter_domain_model_recordmapping (nodepathhash)'); + $this->addSql('CREATE INDEX nodeidentifier ON ttree_contentrepositoryimporter_domain_model_recordmapping (nodeidentifier)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_8C1932AD8FC282F11EE98D63 ON ttree_contentrepositoryimporter_domain_model_recordmapping (importerclassnamehash, externalidentifier)'); + $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event ADD externalidentifier VARCHAR(255) DEFAULT NULL'); + } + + /** + * @param Schema $schema + * @return void + */ + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on "postgresql".'); + + $this->addSql('DROP TABLE ttree_contentrepositoryimporter_domain_model_import'); + $this->addSql('DROP TABLE ttree_contentrepositoryimporter_domain_model_recordmapping'); + $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event DROP externalidentifier'); + $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event ALTER data TYPE TEXT'); + $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event ALTER data DROP DEFAULT'); + } +} From 728f8c4962116400387b35b072a22af69250ec37 Mon Sep 17 00:00:00 2001 From: Dominique Feyer Date: Wed, 19 Jul 2017 10:15:56 +0200 Subject: [PATCH 2/2] TASK: Cleanup PostgreSQL migration --- Migrations/Postgresql/Version20170718190551.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Migrations/Postgresql/Version20170718190551.php b/Migrations/Postgresql/Version20170718190551.php index af29e9b..707928e 100644 --- a/Migrations/Postgresql/Version20170718190551.php +++ b/Migrations/Postgresql/Version20170718190551.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Schema\Schema; /** - * Auto-generated Migration: Please modify to your needs! This block will be used as the migration description if getDescription() is not used. + * Add tables to store content repository importer data */ class Version20170718190551 extends AbstractMigration { @@ -15,7 +15,7 @@ class Version20170718190551 extends AbstractMigration */ public function getDescription() { - return ''; + return 'Add tables to store content repository importer data'; } /** @@ -45,7 +45,5 @@ public function down(Schema $schema) $this->addSql('DROP TABLE ttree_contentrepositoryimporter_domain_model_import'); $this->addSql('DROP TABLE ttree_contentrepositoryimporter_domain_model_recordmapping'); $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event DROP externalidentifier'); - $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event ALTER data TYPE TEXT'); - $this->addSql('ALTER TABLE neos_neos_eventlog_domain_model_event ALTER data DROP DEFAULT'); } }