diff --git a/CommandlogBundle/Command/ShowCommand.php b/CommandlogBundle/Command/ShowCommand.php index a966f8e..614fa36 100644 --- a/CommandlogBundle/Command/ShowCommand.php +++ b/CommandlogBundle/Command/ShowCommand.php @@ -57,7 +57,14 @@ protected function configure() null, InputOption::VALUE_NONE, 'Show detailed command payload?' - ); + ) + ->addOption( + 'deep', + 'd', + InputOption::VALUE_NONE, + 'Deep search including mass updates, deletes, etc.' + ) + ; } protected function execute(InputInterface $input, OutputInterface $output) @@ -75,6 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $entity, $id, $output, + $input->getOption('deep'), $input->getOption('detailed') ); @@ -118,17 +126,22 @@ private function findEntityByTable(string $table) throw new \Exception('Table does not exist or its not loggable'); } - private function getEntityChangelog(string $entity, string $id, OutputInterface $output, bool $detailed) + private function getEntityChangelog(string $entity, string $id, OutputInterface $output, bool $deepSearch, bool $detailed) { + $deepSearchSql = $deepSearch + ? ' OR (entityId = 0 AND data REGEXP \':data\')' + : ''; + $queryStr = 'select id, commandId, data, createdOn from Changelog where entity = :entity' - . ' and (entityId = \':entityId\' OR (entityId = 0 and data REGEXP \':data\'))' - . ' order by createdOn asc, microtime asc'; + . ' and (entityId = \':entityId\'' + . $deepSearchSql + . ') order by createdOn asc, microtime asc'; $replacements = [ ':entityId' => $id, ':entity' => $this->connection->quote($entity), - ':data' => '.*\,"arguments":\\[.*[\[,",\,]'. $id .'[\],",\,].*' + ':data' => '"arguments": *\\\\[.*[\\\\[," ]' . $id . '[\\\\]," ]' ]; $query = str_replace(