예제 #1
0
 /**
  * @param boolean $syncChild
  * @param string $childPattern
  * @return array
  * @throws SyncException
  */
 public function generateWeightCollection($syncChild, $childPattern)
 {
     $this->weightCollection = new WeightCollection();
     foreach ($this->fromAnalyzer->getSchemas() as $schema) {
         foreach ($schema->getTables() as $table) {
             try {
                 $tableName = $schema->getName() . PgAnalyzer::DB_SEPARATOR . $table->getName() . '(' . $table->getOid() . ')';
                 $this->logger->addInfo('Test table ' . $tableName . '
                     with ' . count($table->getParentTables()) . ' parents');
                 if (count($table->getParentTables()) == 0) {
                     $this->weightCollection->addTable($table);
                     $this->logger->addInfo('Add table ' . $tableName);
                 } elseif (count($table->getParentTables()) && $syncChild && empty($childPattern)) {
                     $this->weightCollection->addTable($table);
                     $this->logger->addInfo('Add table ' . $tableName);
                 } elseif (count($table->getParentTables()) && $syncChild && preg_match('/' . $childPattern . '/', $table->getName())) {
                     $this->weightCollection->addTable($table);
                     $this->logger->addInfo('Add table ' . $tableName);
                 }
             } catch (SyncException $ex) {
                 $this->logger->addError($ex->getMessage());
                 $this->logger->addError($ex->getTraceAsString());
                 throw new SyncException($ex->getMessage());
             }
         }
     }
     $this->session->set(SyncHandler::SESSION_WEIGHT_COLLECTION_KEY, $this->weightCollection);
     return $this->weightCollection->getInfos();
 }
예제 #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;
 }
예제 #3
0
 /**
  * @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());
     }
 }