Skip to content
Snippets Groups Projects
Select Git revision
  • Fix
  • master default protected
  • patch-1
  • zf-3.x
  • origin/trunk
  • origin/new_version
  • 1.1.1
  • 1.1.0
  • 1.0.0
9 results

CodeGenerator.php

Blame
  • Forked from lib / unicaen / db-import
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CodeGenerator.php 4.00 KiB
    <?php
    
    namespace UnicaenDbImport\CodeGenerator\PostgreSQL;
    
    use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
    use UnicaenDbImport\CodeGenerator\Common\AbstractCodeGenerator;
    use UnicaenDbImport\CodeGenerator\PostgreSQL\Helper\FunctionCallingHelper;
    use UnicaenDbImport\CodeGenerator\PostgreSQL\Helper\FunctionCreationHelper;
    use UnicaenDbImport\CodeGenerator\PostgreSQL\Helper\TableValidationHelper;
    use UnicaenDbImport\Domain\DestinationInterface;
    use UnicaenDbImport\Domain\SourceInterface;
    
    /**
     * Version PostgreSQL.
     *
     * @author Unicaen
     * @todo N'utiliser que des helpers de génération de code car quel est la différence entre CodeGenerator et un helper ?
     */
    class CodeGenerator extends AbstractCodeGenerator
    {
        /**
         * @var PostgreSqlPlatform
         */
        protected $platform;
    
        /**
         * CodeGenerator constructor.
         *
         * @param TableValidationHelper  $tableValidationHelper
         * @param FunctionCreationHelper $functionCreationHelper
         * @param FunctionCallingHelper  $functionCallingHelper
         */
        public function __construct(TableValidationHelper $tableValidationHelper,
                                    FunctionCreationHelper $functionCreationHelper,
                                    FunctionCallingHelper $functionCallingHelper)
        {
            parent::__construct($tableValidationHelper, $functionCreationHelper, $functionCallingHelper);
    
            $this->platform = new PostgreSqlPlatform();
        }
    
        /**
         * @param \UnicaenDbImport\Domain\SourceInterface $source
         * @param DestinationInterface                    $destination
         * @return string
         */
        public function generateImportMetaRequestFunctionCreationSQL(SourceInterface $source,
                                                                     DestinationInterface $destination)
        {
            $destinationTable = $destination->getTable();
            $sourceCodeColumn = $source->getSourceCodeColumn();
            $columns = $source->getColumns();
    
            $sql = $this->functionCreationHelper->generateSQL($destinationTable, $sourceCodeColumn, $columns);
    
            return $sql;
        }
    
        public function generateSourceAndDestinationDiffSelectSQL(SourceInterface $source,
                                                                  DestinationInterface $destination,
                                                                  $intermediateTable = null,
                                                                  $importHash = null)
        {
            $sourceTable = $intermediateTable ?: $source->getTable();
            $destinationTable = $destination->getTable();
            $sourceCodeColumn = $destination->getSourceCodeColumn();
            $columns = $destination->getColumns();
            $columnsToChar = $destination->getColumnsToChar();
    
            $this->functionCallingHelper->setImportHash($importHash);