Exemple #1
0
 public function __construct(Registry $doctrine, Session $session, Logger $logger, Parameters $parameters)
 {
     $this->doctrine = $doctrine;
     $this->session = $session;
     $this->logger = $logger;
     $this->parameters = $parameters;
     $this->emFrom = $this->doctrine->getManager($this->parameters->getManagerFrom());
     $this->emTo = $this->doctrine->getManager($this->parameters->getManagerTo());
     $fromRetriever = new PgRetriever($doctrine, $this->logger, $this->parameters->getManagerFrom());
     $fromRetriever->setIndexType(PgRetriever::INDEX_TYPE_NAME);
     //$toRetriever = new PgRetriever($doctrine, $this->logger, $this->parameters->getManagerTo() );
     //$toRetriever->setIndexType(PgRetriever::INDEX_TYPE_NAME);
     $this->fromAnalyzer = new PgAnalyzer($this->logger, $fromRetriever);
     //$this->toAnalyzer = new PgAnalyzer($this->logger, $toRetriever);
     if ($this->session->has(CompareStructure::SESSION_FROM_KEY)) {
         $this->fromAnalyzer->setSchemas($this->session->get(CompareStructure::SESSION_FROM_KEY));
         $this->fromAnalyzer->initTables();
     } else {
         throw new SyncException('No source data');
     }
     /*if($this->session->has(CompareStructure::SESSION_TO_KEY)){
           $this->toAnalyzer->setSchemas($this->session->get(CompareStructure::SESSION_TO_KEY));
           $this->toAnalyzer->initTables();
       }else{
           throw new SyncException('No targeted data');
       }*/
 }
Exemple #2
0
 public function exportDataToCsv(PgAnalyzer $pgAnalyzer)
 {
     $fileNames = ['nodes' => self::NODE_FILENAME . '_' . time() . '.csv', 'links' => self::LINKS_FILENAME . '_' . time() . '.csv'];
     $handleNodes = fopen(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileNames['nodes'], 'w');
     $handleLinks = fopen(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileNames['links'], 'w');
     $headerNodes = ['tableId:ID', 'name', ':LABEL'];
     $headerLinks = [':START_ID', 'role', ':END_ID', ':TYPE'];
     fputcsv($handleNodes, $headerNodes);
     fputcsv($handleLinks, $headerLinks);
     foreach ($pgAnalyzer->getSchemas() as $schema) {
         foreach ($schema->getTables() as $table) {
             fputcsv($handleNodes, [$schema->getName() . PgAnalyzer::DB_SEPARATOR . $table->getName(), $table->getName(), $schema->getName() . '|Table' . (count($table->getChildTables()) ? '|Parent' : '') . (count($table->getParentTables()) ? '|Child' : '')], ",", "'");
             foreach ($table->getForeignKeys() as $fk) {
                 $parentTable = $pgAnalyzer->getTableByOid($fk->getParentTable());
                 fputcsv($handleLinks, [$table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName(), 'reference', $parentTable->getSchema() . PgAnalyzer::DB_SEPARATOR . $parentTable->getName(), 'FOREIGN_KEY'], ",", "'");
             }
             foreach ($table->getParentTables() as $parent) {
                 $parentTable = $pgAnalyzer->getTableByOid($parent->getOid());
                 fputcsv($handleLinks, [$table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName(), 'inherit', $parentTable->getSchema() . PgAnalyzer::DB_SEPARATOR . $parentTable->getName(), 'INHERIT'], ",", "'");
             }
         }
     }
     fclose($handleNodes);
     fclose($handleLinks);
     return $fileNames;
 }
 /**
  * @throws StructureException
  */
 public function compareFunctions()
 {
     try {
         foreach ($this->fromAnalyzer->getSchemas() as $schemaName => $schema) {
             foreach ($schema->getFunctions() as $fromFonctionName => $fromFonction) {
                 $toFonction = $this->fromAnalyzer->getFunctionByName($schemaName, $fromFonctionName);
                 //From Here it's a deeper inspectiion of the function structure
             }
         }
     } catch (ElementNotFoundException $ex) {
         throw new StructureException('Problem in targeted database : ' . $ex->getMessage());
     } catch (\Exception $ex) {
         throw new StructureException($ex->getMessage());
     }
 }
 /**
  * @param $tableOid
  * @param $weight
  * @return string
  * @throws SyncException
  * @throws \rombar\PgExplorerBundle\Exceptions\ElementNotFoundException
  */
 private function syncTable($tableOid, Weight $weight)
 {
     $table = $this->fromAnalyzer->getTableByOid($tableOid);
     if ($this->isTableSynchronizable($table)) {
         $data = $this->getFromTableData($table);
         if (count($data) > 0) {
             $message = $this->insertData($table, $data);
         } else {
             $this->logger->addInfo('Table ' . $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName() . ' is empty');
             $message = 'OK';
             //Nothing to do. Table is empty
         }
         if ($message == 'OK') {
             $weight->updateTableStatus($table->getOid(), true);
             return $message;
         } else {
             throw new SyncException('Table ' . $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName() . ' not sync : ' . $message);
         }
     } else {
         $this->logger->addWarning('Table not Synchronizable (yet?) : ' . $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName());
         return self::TABLE_NOT_SYNC;
     }
 }
Exemple #5
0
 /**
  * Get tables linked to a given table (reference, referenced by and among joins)
  * @param Table $parentTable
  * @param PgAnalyzer $pgAnalyzer
  * @return array<Table>
  */
 private function getProximityTablesFrom(Table $parentTable, PgAnalyzer $pgAnalyzer)
 {
     $tables = [];
     foreach ($pgAnalyzer->getProximityTablesFrom($parentTable) as $tbId => $tble) {
         if (!isset($tables[$tbId])) {
             //Avoid circular referencing and double values
             $tables[$tbId] = $tble;
         }
     }
     if ($parentTable->getJoins()) {
         foreach ($parentTable->getJoins() as $table) {
             foreach ($pgAnalyzer->getProximityTablesFrom($table) as $tbId => $tble) {
                 if (!isset($tables[$tbId])) {
                     //Avoid circular referencing and double values
                     $tables[$tbId] = $tble;
                 }
             }
         }
     }
     return $tables;
 }