Example #1
0
 /**
  * @param Table $table
  * @throws SyncException
  */
 public function addTable(Table $table)
 {
     $weight = count($table->getForeignKeys());
     if (!isset($this->weights[$weight])) {
         $weightContainer = new Weight();
         $weightContainer->setWeight($weight);
         $this->weights[$weight] = $weightContainer;
     }
     $this->weights[$weight]->addTableStatus($table->getOid());
 }
Example #2
0
 /**
  * 
  * @param Table $table
  * @param Table $parentTable
  * @param boolean $strict default false. If false, search in both ways
  * @return string
  * @throws \Exception
  */
 private function getJoinCriteria(Table $table, Table $parentTable, $strict = false)
 {
     $libelle = '';
     //Look for the FK object
     if ($table && count($table->getForeignKeys()) > 0) {
         foreach ($table->getForeignKeys() as $fk) {
             //var_dump($fk);
             if ($fk->getParentTable() == $parentTable->getOid()) {
                 $cols = [];
                 $refCols = [];
                 $colNames = [];
                 $refColNames = [];
                 //var_dump($fk->getCols());
                 foreach ($fk->getCols() as $colId) {
                     $col = $table->getAColumn($colId);
                     if ($col) {
                         $cols[] = $col;
                         $colNames[] = $table->getAlias() . '.' . $col->getName();
                     } else {
                         throw new \Exception('Unknwon column ID : ' . $colId . print_r($table->getColumns(), true));
                     }
                 }
                 if (count($cols) == 0) {
                     throw new \Exception('No Column in the foreign key' . print_r($fk, true));
                 }
                 $index = 0;
                 foreach ($fk->getRefCols() as $colId) {
                     $col = $parentTable->getAColumn($colId);
                     if ($col) {
                         if (count($cols) == 1 || $cols[$index]->getType() == $col->getType()) {
                             $refCols[] = $col;
                             $refColNames[] = $parentTable->getAlias() . '.' . $col->getName();
                         } else {
                             throw new \Exception('Columns order not matching');
                         }
                     } else {
                         throw new \Exception('Unknwon column ID : ' . $colId . print_r($parentTable->getColumns(), true));
                     }
                     $index++;
                 }
                 $libelle = '(' . implode(', ', $colNames) . ') = (' . implode(', ', $refColNames) . ')';
                 break;
             }
         }
     }
     if (empty($libelle) && !$strict) {
         $libelle = $this->getJoinCriteria($parentTable, $table, true);
     }
     if (empty($libelle)) {
         throw new \Exception('No foreign key possible');
     }
     return $libelle;
 }
Example #3
0
 /**
  * Get tables linked to a given table (reference by and referenced by)
  * @param Table $parentTable
  * @return array array<Tables>
  */
 public function getProximityTablesFrom(Table $parentTable)
 {
     $tables = [];
     foreach ($parentTable->getForeignKeys() as $fk) {
         $table = $this->getTableByOid($fk->getParentTable());
         if (!isset($tables[$table->getOid()])) {
             $tables[$table->getOid()] = $table;
         }
     }
     foreach ($parentTable->getReferencedInTables() as $oid) {
         $table = $this->getTableByOid($oid);
         if (!isset($tables[$table->getOid()])) {
             $tables[$table->getOid()] = $table;
         }
     }
     return $tables;
 }
Example #4
0
 /**
  * @param Table $table
  */
 private function enableUserTriggers(Table $table)
 {
     $tableFullName = $table->getSchema() . PgAnalyzer::DB_SEPARATOR . $table->getName();
     $sql = "ALTER TABLE " . $tableFullName . " ENABLE TRIGGER USER";
     $this->doctrine->getConnection($this->parameters->getManagerTo())->executeQuery($sql);
 }