Skip to content

Commit

Permalink
Merge pull request ttreeagency#21 from ttreeagency/task-postgresql
Browse files Browse the repository at this point in the history
TASK: Add support for PostgreSQL
  • Loading branch information
dfeyer authored Jul 20, 2017
2 parents f0cdf8f + 728f8c4 commit 97dd6d3
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 15 deletions.
7 changes: 5 additions & 2 deletions Classes/Command/ImportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
Expand Down
25 changes: 13 additions & 12 deletions Classes/Domain/Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Import
/**
* @var \DateTime
*/
protected $start;
protected $startTime;

/**
* @var \DateTime
* @ORM\Column(nullable=true)
*/
protected $end;
protected $endTime;

/**
* @var string
Expand All @@ -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();
}
}
Expand All @@ -74,6 +74,7 @@ public function getExternalImportIdentifier()
{
return $this->externalImportIdentifier;
}

/**
* @param string $eventType
* @param string $externalIdentifier
Expand Down Expand Up @@ -123,38 +124,38 @@ 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;
}

/**
* @return integer
*/
public function getElapsedTime()
{
return (integer) $this->end->getTimestamp() - $this->start->getTimestamp();
return (integer) $this->endTime->getTimestamp() - $this->startTime->getTimestamp();
}

/**
* @throws Exception
*/
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();
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
42 changes: 42 additions & 0 deletions Migrations/Mysql/Version20170718190551.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Adapt column naming to support PostgreSQL
*/
class Version20170718190551 extends AbstractMigration
{

/**
* @return string
*/
public function getDescription()
{
return 'Adapt column naming to support PostgreSQL';
}

/**
* @param Schema $schema
* @return void
*/
public function up(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 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');
}
}
49 changes: 49 additions & 0 deletions Migrations/Postgresql/Version20170718190551.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Add tables to store content repository importer data
*/
class Version20170718190551 extends AbstractMigration
{

/**
* @return string
*/
public function getDescription()
{
return 'Add tables to store content repository importer data';
}

/**
* @param Schema $schema
* @return void
*/
public function up(Schema $schema)
{
$this->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');
}
}

0 comments on commit 97dd6d3

Please sign in to comment.