From 48834be1aa44b6c3e45ae3e59c9ad63fb7650347 Mon Sep 17 00:00:00 2001 From: Dominic Scheirlinck Date: Mon, 16 Jun 2014 13:56:53 +1200 Subject: [PATCH 1/6] Query debugging using a helper method Reduces duplicated code --- src/Doxport/Action/Base/Action.php | 6 ++++++ src/Doxport/Action/Base/QueryAction.php | 21 +++++++++++++++++++++ src/Doxport/Action/Delete.php | 4 ++-- src/Doxport/Action/Export.php | 4 +--- src/Doxport/Action/Import.php | 4 +--- src/Doxport/Exception/IOException.php | 3 ++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Doxport/Action/Base/Action.php b/src/Doxport/Action/Base/Action.php index e1ac70e..2793435 100644 --- a/src/Doxport/Action/Base/Action.php +++ b/src/Doxport/Action/Base/Action.php @@ -127,6 +127,10 @@ public function setChunk(Chunk $chunk) */ protected function debugMemory() { + if (!$this->options['verbose']) { + return; + } + $a = [ memory_get_usage(), memory_get_peak_usage(), @@ -141,4 +145,6 @@ protected function debugMemory() $this->logger->notice('Memory: ' . $s); } + + } diff --git a/src/Doxport/Action/Base/QueryAction.php b/src/Doxport/Action/Base/QueryAction.php index 9fb8db7..5c9c1d3 100644 --- a/src/Doxport/Action/Base/QueryAction.php +++ b/src/Doxport/Action/Base/QueryAction.php @@ -3,6 +3,7 @@ namespace Doxport\Action\Base; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query; use Doxport\Doctrine\AliasGenerator; use Doxport\Doctrine\JoinWalk; use Doxport\File\AbstractFile; @@ -121,6 +122,26 @@ protected function entityToArray($entity, array $fields = []) return $array; } + /** + * Prints debugging information about the given query + * + * @param Query $query + */ + protected function debugQuery(Query $query) + { + if (!$this->options['verbose']) { + return; + } + + $sql = $query->getSQL(); + + if (is_array($sql)) { + $sql = implode('; ', $sql); + } + + $this->logger->info($sql); + } + /** * @param JoinWalk $walk * @return mixed diff --git a/src/Doxport/Action/Delete.php b/src/Doxport/Action/Delete.php index 9530328..bdb96ad 100644 --- a/src/Doxport/Action/Delete.php +++ b/src/Doxport/Action/Delete.php @@ -23,7 +23,7 @@ protected function processQuery(JoinWalk $walk) // Get query $this->logger->notice('Getting select query for {target}', ['target' => $walk->getTargetId()]); $query = $walk->getQuery(); - $this->logger->info($query->getSQL()); + $this->debugQuery($query); // Output join information $this->logger->info((string)$walk); @@ -116,7 +116,7 @@ public function processClear(Walk $path, array $fields, array $joinFields) // Get query $this->logger->notice('Getting select query for {target}', ['target' => $walk->getTargetId()]); $query = $walk->getQuery(); - $this->logger->info($query->getSQL()); + $this->debugQuery($query); // Output join information $this->logger->info((string)$walk); diff --git a/src/Doxport/Action/Export.php b/src/Doxport/Action/Export.php index c2d88dd..21eb988 100644 --- a/src/Doxport/Action/Export.php +++ b/src/Doxport/Action/Export.php @@ -25,9 +25,7 @@ class Export extends QueryAction */ protected function processQuery(JoinWalk $walk) { - if ($this->options['verbose']) { - $this->debugMemory(); - } + $this->debugMemory(); if (!empty($this->clear[$walk->getTargetId()])) { $clearFile = $this->getClearFile($walk); diff --git a/src/Doxport/Action/Import.php b/src/Doxport/Action/Import.php index 07e14ae..424e8b7 100644 --- a/src/Doxport/Action/Import.php +++ b/src/Doxport/Action/Import.php @@ -138,9 +138,7 @@ protected function flush($count = null) $this->logger->notice(' changes flushed.'); - if ($this->options['verbose']) { - $this->debugMemory(); - } + $this->debugMemory(); } /** diff --git a/src/Doxport/Exception/IOException.php b/src/Doxport/Exception/IOException.php index 6e662d3..c62532e 100644 --- a/src/Doxport/Exception/IOException.php +++ b/src/Doxport/Exception/IOException.php @@ -3,4 +3,5 @@ namespace Doxport\Exception; class IOException extends \Exception -{} +{ +} From 67d7a7a881f7c434433e17f062fe44687169df82 Mon Sep 17 00:00:00 2001 From: Dominic Scheirlinck Date: Mon, 16 Jun 2014 13:59:20 +1200 Subject: [PATCH 2/6] Don't duplicate identitcal execute methods --- src/Doxport/Console/DeleteCommand.php | 24 +-------------------- src/Doxport/Console/ExportCommand.php | 25 +--------------------- src/Doxport/Console/QueryActionCommand.php | 12 +++++++++++ 3 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/Doxport/Console/DeleteCommand.php b/src/Doxport/Console/DeleteCommand.php index bd9aa8d..dab03fa 100644 --- a/src/Doxport/Console/DeleteCommand.php +++ b/src/Doxport/Console/DeleteCommand.php @@ -20,32 +20,10 @@ protected function configure() { parent::configure(); - $this - ->setName('delete') + $this->setName('delete') ->setDescription('Deletes a set of data from the database, beginning with a specified type, but not including it'); } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return void - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - parent::execute($input, $output); - - $pass = $this->doxport->getConstraintPass(); - $vertices = $pass->run(); - - $pass = $this->doxport->getClearPass($vertices); - $pass->run(); - - $pass = $this->doxport->getJoinPass($vertices); - $pass->run(); - - $this->logger->notice('All done.'); - } - /** * @return Action */ diff --git a/src/Doxport/Console/ExportCommand.php b/src/Doxport/Console/ExportCommand.php index 0da5bab..8f5a079 100644 --- a/src/Doxport/Console/ExportCommand.php +++ b/src/Doxport/Console/ExportCommand.php @@ -19,33 +19,10 @@ protected function configure() { parent::configure(); - $this - ->setName('export') + $this->setName('export') ->setDescription('Exports a set of data from the database, beginning with a specified type'); } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return void - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - parent::execute($input, $output); - - $pass = $this->doxport->getConstraintPass(); - $vertices = $pass->run(); - - $pass = $this->doxport->getClearPass($vertices); - $pass->run(); - - $pass = $this->doxport->getJoinPass($vertices); - $pass->run(); - - $this->logger->notice('All done.'); - } - - /** * @return Action */ diff --git a/src/Doxport/Console/QueryActionCommand.php b/src/Doxport/Console/QueryActionCommand.php index 3f4756c..f779442 100644 --- a/src/Doxport/Console/QueryActionCommand.php +++ b/src/Doxport/Console/QueryActionCommand.php @@ -37,7 +37,19 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); + $this->validateInput($input); + + $pass = $this->doxport->getConstraintPass(); + $vertices = $pass->run(); + + $pass = $this->doxport->getClearPass($vertices); + $pass->run(); + + $pass = $this->doxport->getJoinPass($vertices); + $pass->run(); + + $this->logger->notice('All done.'); } protected function configureDoxport(InputInterface $input) From 6bd51b1ffc7d95e7f02a48e96e0b0c28adaf2214 Mon Sep 17 00:00:00 2001 From: Dominic Scheirlinck Date: Mon, 16 Jun 2014 14:10:04 +1200 Subject: [PATCH 3/6] Moved base console classes to separate namespace --- src/Doxport/Console/{ => Base}/ActionCommand.php | 3 ++- src/Doxport/Console/{ => Base}/Command.php | 4 ++-- src/Doxport/Console/{ => Base}/QueryActionCommand.php | 3 ++- src/Doxport/Console/DeleteCommand.php | 3 +-- src/Doxport/Console/ExportCommand.php | 3 +-- src/Doxport/Console/ImportCommand.php | 1 + test/Doxport/Console/CommandTest.php | 1 + test/Doxport/Console/ImportCommandTest.php | 2 ++ 8 files changed, 12 insertions(+), 8 deletions(-) rename src/Doxport/Console/{ => Base}/ActionCommand.php (97%) rename src/Doxport/Console/{ => Base}/Command.php (95%) rename src/Doxport/Console/{ => Base}/QueryActionCommand.php (98%) diff --git a/src/Doxport/Console/ActionCommand.php b/src/Doxport/Console/Base/ActionCommand.php similarity index 97% rename from src/Doxport/Console/ActionCommand.php rename to src/Doxport/Console/Base/ActionCommand.php index f9f6e60..0236dc0 100644 --- a/src/Doxport/Console/ActionCommand.php +++ b/src/Doxport/Console/Base/ActionCommand.php @@ -1,8 +1,9 @@ addOption('verbose', 'v', InputOption::VALUE_NONE, 'Verbose logging', null); } diff --git a/src/Doxport/Console/QueryActionCommand.php b/src/Doxport/Console/Base/QueryActionCommand.php similarity index 98% rename from src/Doxport/Console/QueryActionCommand.php rename to src/Doxport/Console/Base/QueryActionCommand.php index f779442..c416e21 100644 --- a/src/Doxport/Console/QueryActionCommand.php +++ b/src/Doxport/Console/Base/QueryActionCommand.php @@ -1,8 +1,9 @@ Date: Mon, 16 Jun 2014 14:10:24 +1200 Subject: [PATCH 4/6] Added test for property class --- test/Doxport/Metadata/PropertyTest.php | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/Doxport/Metadata/PropertyTest.php diff --git a/test/Doxport/Metadata/PropertyTest.php b/test/Doxport/Metadata/PropertyTest.php new file mode 100644 index 0000000..3eb1f93 --- /dev/null +++ b/test/Doxport/Metadata/PropertyTest.php @@ -0,0 +1,38 @@ +assertTrue($property->hasAnnotation('Doxport\Annotation\Exclude')); + $this->assertFalse($property->hasAnnotation('Doxport\Annotation\Clear')); + } + + public function testGetTargetEntity() + { + $target = uniqid(); + + $property = new Property('something', [new Exclude()], [ + 'targetEntity' => $target + ]); + + $this->assertEquals($target, $property->getTargetEntity()); + } + + /** + * @expectedException LogicException + */ + public function testNoTargetEntity() + { + $property = new Property('something', [], []); + $property->getTargetEntity(); + } +} From 2bb409fceed9255906b3f7527aab6734e2374d78 Mon Sep 17 00:00:00 2001 From: Dominic Scheirlinck Date: Mon, 16 Jun 2014 14:15:20 +1200 Subject: [PATCH 5/6] Revert parent being replaced --- src/Doxport/Action/Base/Action.php | 2 -- src/Doxport/Console/Base/Command.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Doxport/Action/Base/Action.php b/src/Doxport/Action/Base/Action.php index 2793435..1c39cf7 100644 --- a/src/Doxport/Action/Base/Action.php +++ b/src/Doxport/Action/Base/Action.php @@ -145,6 +145,4 @@ protected function debugMemory() $this->logger->notice('Memory: ' . $s); } - - } diff --git a/src/Doxport/Console/Base/Command.php b/src/Doxport/Console/Base/Command.php index 606bb3f..22a7fcb 100644 --- a/src/Doxport/Console/Base/Command.php +++ b/src/Doxport/Console/Base/Command.php @@ -25,7 +25,7 @@ abstract class Command extends CommandComponent implements LoggerAwareInterface */ protected function configure() { - CommandComponent::configure(); + parent::configure(); $this->addOption('verbose', 'v', InputOption::VALUE_NONE, 'Verbose logging', null); } From 8ed99febe876221fce39d29a6d7f5a22db9d1b0c Mon Sep 17 00:00:00 2001 From: Dominic Scheirlinck Date: Mon, 16 Jun 2014 14:17:44 +1200 Subject: [PATCH 6/6] Skip persist if entity not found during import update --- src/Doxport/Action/Import.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Doxport/Action/Import.php b/src/Doxport/Action/Import.php index 424e8b7..9bbd061 100644 --- a/src/Doxport/Action/Import.php +++ b/src/Doxport/Action/Import.php @@ -176,6 +176,7 @@ protected function processUpdate($entityName, array $updates) if (empty($entity)) { $this->logger->warning('Cannot find {entity} to update, skipping update', ['entity' => $entityName]); + continue; } // @todo Doesn't support foreign keys in identifier