Loading src/UnicaenDbImport/CodeGenerator/CodeGenerator.php +33 −4 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use UnicaenDbImport\CodeGenerator\Helper\TableHelper; use UnicaenDbImport\CodeGenerator\Helper\TableValidationHelper; use UnicaenDbImport\Config\ConfigAwareTrait; use UnicaenDbImport\Domain\DestinationInterface; use UnicaenDbImport\Domain\Operation; use UnicaenDbImport\Domain\ResultInterface; use UnicaenDbImport\Domain\SourceInterface; Loading Loading @@ -254,8 +255,8 @@ abstract class CodeGenerator implements CodeGeneratorInterface /** * @inheritDoc */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, public function generateSQLForDestinationOperation( $operation, SourceInterface $source, DestinationInterface $destination) { Loading @@ -264,12 +265,40 @@ abstract class CodeGenerator implements CodeGeneratorInterface $sourceCodeColumn = $source->getSourceCodeColumn(); $columns = $source->getColumns(); return $this->tableHelper->generateSQLForOperationInDestinationTableFromDiffViewRequestResult( $rows, // colonne ID écartée $columns = array_diff($columns, ['ID', 'id']); switch ($operation) { case Operation::OPERATION_INSERT; $sql = $this->tableHelper->generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns, $idColumnSequence); break; case Operation::OPERATION_UPDATE; $sql = $this->tableHelper->generateSQLForUpdateOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; case Operation::OPERATION_DELETE; $sql = $this->tableHelper->generateSQLForDeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; case Operation::OPERATION_UNDELETE; $sql = $this->tableHelper->generateSQLForUndeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; default: throw new RuntimeException("Opération inattendue"); } return $sql . PHP_EOL; } /** Loading src/UnicaenDbImport/CodeGenerator/CodeGeneratorInterface.php +4 −4 Original line number Diff line number Diff line Loading @@ -124,13 +124,13 @@ interface CodeGeneratorInterface public function generateSQLForDiffViewSelect(SourceInterface $source, DestinationInterface $destination); /** * @param array $rows * @param string $operation * @param SourceInterface $source * @param DestinationInterface $destination * @return string * @return string[] */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, public function generateSQLForDestinationOperation( $operation, SourceInterface $source, DestinationInterface $destination); Loading src/UnicaenDbImport/CodeGenerator/Helper/LogTableHelper.php +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ EOT; throw new RuntimeException("Type de résultat inattendu"); break; } $success = $result->getException() ? 0 : 1; $success = $result->getFailure() ? 0 : 1; $startDate = $result->getStartDate()->format("Y-m-d H:i:s"); $endDate = $result->getEndDate()->format("Y-m-d H:i:s"); Loading src/UnicaenDbImport/CodeGenerator/Helper/TableHelper.php +24 −10 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ EOT; * @param string $sourceCodeColumn * @param string[] $columns * @param string|null|false $idColumnSequence * @return string * @return string[] */ public function generateSQLForOperationInDestinationTableFromDiffViewRequestResult( array $rows, Loading Loading @@ -272,16 +272,29 @@ EOT; foreach ($operations as $operation) { switch ($operation) { case Operation::OPERATION_INSERT: $sqls[] = $this->generateSQLForInsertOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns, $idColumnSequence) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns, $idColumnSequence) . PHP_EOL; break; case Operation::OPERATION_UPDATE: $sqls[] = $this->generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForUpdateOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; case Operation::OPERATION_UNDELETE: $sqls[] = $this->generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForUndeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; case Operation::OPERATION_DELETE: $sqls[] = $this->generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForDeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; default: throw new RuntimeException("Opération inconnue rencontrée : " . $operation); Loading @@ -289,7 +302,8 @@ EOT; } } return empty($sqls) ? '' : implode(PHP_EOL, $sqls); // return empty($sqls) ? '' : implode(PHP_EOL, $sqls); return $sqls; } /** Loading Loading @@ -363,7 +377,7 @@ EOT; * @param string|null|false $idColumnSequence * @return string */ protected function generateSQLForInsertOperationInDestinationTable( public function generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, array $columns, Loading Loading @@ -502,7 +516,7 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); /** * @param string $destinationTable Loading @@ -510,7 +524,7 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); /** * @param string $destinationTable Loading @@ -518,5 +532,5 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); } No newline at end of file src/UnicaenDbImport/CodeGenerator/Oracle/CodeGenerator.php +0 −23 Original line number Diff line number Diff line Loading @@ -3,8 +3,6 @@ namespace UnicaenDbImport\CodeGenerator\Oracle; use UnicaenDbImport\CodeGenerator\Oracle; use UnicaenDbImport\Domain\DestinationInterface; use UnicaenDbImport\Domain\SourceInterface; use UnicaenDbImport\Platforms\OraclePlatform; /** Loading Loading @@ -42,27 +40,6 @@ class CodeGenerator extends \UnicaenDbImport\CodeGenerator\CodeGenerator 'END;'; } /** * @inheritDoc */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, SourceInterface $source, DestinationInterface $destination) { $sql = parent::generateSQLForDestinationUpdateFromDiffViewRequestResult($rows, $source, $destination); if ($sql === '') { return ''; } // les ; séparant les INSERT/MERGE perturbent le driver Oracle donc on met ça dans un bloc BEGIN END et miracle... return 'BEGIN ' . PHP_EOL . $sql . PHP_EOL . 'END;'; } /** * @inheritDoc */ Loading Loading
src/UnicaenDbImport/CodeGenerator/CodeGenerator.php +33 −4 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use UnicaenDbImport\CodeGenerator\Helper\TableHelper; use UnicaenDbImport\CodeGenerator\Helper\TableValidationHelper; use UnicaenDbImport\Config\ConfigAwareTrait; use UnicaenDbImport\Domain\DestinationInterface; use UnicaenDbImport\Domain\Operation; use UnicaenDbImport\Domain\ResultInterface; use UnicaenDbImport\Domain\SourceInterface; Loading Loading @@ -254,8 +255,8 @@ abstract class CodeGenerator implements CodeGeneratorInterface /** * @inheritDoc */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, public function generateSQLForDestinationOperation( $operation, SourceInterface $source, DestinationInterface $destination) { Loading @@ -264,12 +265,40 @@ abstract class CodeGenerator implements CodeGeneratorInterface $sourceCodeColumn = $source->getSourceCodeColumn(); $columns = $source->getColumns(); return $this->tableHelper->generateSQLForOperationInDestinationTableFromDiffViewRequestResult( $rows, // colonne ID écartée $columns = array_diff($columns, ['ID', 'id']); switch ($operation) { case Operation::OPERATION_INSERT; $sql = $this->tableHelper->generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns, $idColumnSequence); break; case Operation::OPERATION_UPDATE; $sql = $this->tableHelper->generateSQLForUpdateOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; case Operation::OPERATION_DELETE; $sql = $this->tableHelper->generateSQLForDeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; case Operation::OPERATION_UNDELETE; $sql = $this->tableHelper->generateSQLForUndeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns); break; default: throw new RuntimeException("Opération inattendue"); } return $sql . PHP_EOL; } /** Loading
src/UnicaenDbImport/CodeGenerator/CodeGeneratorInterface.php +4 −4 Original line number Diff line number Diff line Loading @@ -124,13 +124,13 @@ interface CodeGeneratorInterface public function generateSQLForDiffViewSelect(SourceInterface $source, DestinationInterface $destination); /** * @param array $rows * @param string $operation * @param SourceInterface $source * @param DestinationInterface $destination * @return string * @return string[] */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, public function generateSQLForDestinationOperation( $operation, SourceInterface $source, DestinationInterface $destination); Loading
src/UnicaenDbImport/CodeGenerator/Helper/LogTableHelper.php +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ EOT; throw new RuntimeException("Type de résultat inattendu"); break; } $success = $result->getException() ? 0 : 1; $success = $result->getFailure() ? 0 : 1; $startDate = $result->getStartDate()->format("Y-m-d H:i:s"); $endDate = $result->getEndDate()->format("Y-m-d H:i:s"); Loading
src/UnicaenDbImport/CodeGenerator/Helper/TableHelper.php +24 −10 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ EOT; * @param string $sourceCodeColumn * @param string[] $columns * @param string|null|false $idColumnSequence * @return string * @return string[] */ public function generateSQLForOperationInDestinationTableFromDiffViewRequestResult( array $rows, Loading Loading @@ -272,16 +272,29 @@ EOT; foreach ($operations as $operation) { switch ($operation) { case Operation::OPERATION_INSERT: $sqls[] = $this->generateSQLForInsertOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns, $idColumnSequence) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns, $idColumnSequence) . PHP_EOL; break; case Operation::OPERATION_UPDATE: $sqls[] = $this->generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForUpdateOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; case Operation::OPERATION_UNDELETE: $sqls[] = $this->generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForUndeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; case Operation::OPERATION_DELETE: $sqls[] = $this->generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, $columns) . ';' . PHP_EOL; $sqls[] = $this->generateSQLForDeleteOperationInDestinationTable( $destinationTable, $sourceCodeColumn, $columns) . PHP_EOL; break; default: throw new RuntimeException("Opération inconnue rencontrée : " . $operation); Loading @@ -289,7 +302,8 @@ EOT; } } return empty($sqls) ? '' : implode(PHP_EOL, $sqls); // return empty($sqls) ? '' : implode(PHP_EOL, $sqls); return $sqls; } /** Loading Loading @@ -363,7 +377,7 @@ EOT; * @param string|null|false $idColumnSequence * @return string */ protected function generateSQLForInsertOperationInDestinationTable( public function generateSQLForInsertOperationInDestinationTable( $destinationTable, $sourceCodeColumn, array $columns, Loading Loading @@ -502,7 +516,7 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForUpdateOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); /** * @param string $destinationTable Loading @@ -510,7 +524,7 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForUndeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); /** * @param string $destinationTable Loading @@ -518,5 +532,5 @@ EOT; * @param array $columns * @return string */ abstract protected function generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); abstract public function generateSQLForDeleteOperationInDestinationTable($destinationTable, $sourceCodeColumn, array $columns); } No newline at end of file
src/UnicaenDbImport/CodeGenerator/Oracle/CodeGenerator.php +0 −23 Original line number Diff line number Diff line Loading @@ -3,8 +3,6 @@ namespace UnicaenDbImport\CodeGenerator\Oracle; use UnicaenDbImport\CodeGenerator\Oracle; use UnicaenDbImport\Domain\DestinationInterface; use UnicaenDbImport\Domain\SourceInterface; use UnicaenDbImport\Platforms\OraclePlatform; /** Loading Loading @@ -42,27 +40,6 @@ class CodeGenerator extends \UnicaenDbImport\CodeGenerator\CodeGenerator 'END;'; } /** * @inheritDoc */ public function generateSQLForDestinationUpdateFromDiffViewRequestResult( array $rows, SourceInterface $source, DestinationInterface $destination) { $sql = parent::generateSQLForDestinationUpdateFromDiffViewRequestResult($rows, $source, $destination); if ($sql === '') { return ''; } // les ; séparant les INSERT/MERGE perturbent le driver Oracle donc on met ça dans un bloc BEGIN END et miracle... return 'BEGIN ' . PHP_EOL . $sql . PHP_EOL . 'END;'; } /** * @inheritDoc */ Loading