| 295 | | $rs = $this->con->executeQuery('SELECT * FROM '.constant($tableName.'Peer::TABLE_NAME')); |
|---|
| 296 | | |
|---|
| 297 | | while ($rs->next()) |
|---|
| 298 | | { |
|---|
| 299 | | $pk = $tableName; |
|---|
| 300 | | $values = array(); |
|---|
| 301 | | foreach ($tableMap->getColumns() as $column) |
|---|
| 302 | | { |
|---|
| 303 | | $col = strtolower($column->getColumnName()); |
|---|
| 304 | | if ($column->isPrimaryKey()) |
|---|
| 305 | | { |
|---|
| 306 | | $pk .= '_'.$rs->get($col); |
|---|
| 307 | | } |
|---|
| 308 | | else if ($column->isForeignKey()) |
|---|
| 309 | | { |
|---|
| 310 | | $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName()); |
|---|
| 311 | | |
|---|
| 312 | | $values[$col] = $relatedTable->getPhpName().'_'.$rs->get($col); |
|---|
| 313 | | } |
|---|
| 314 | | else |
|---|
| 315 | | { |
|---|
| 316 | | $values[$col] = $rs->get($col); |
|---|
| 317 | | } |
|---|
| 318 | | } |
|---|
| 319 | | |
|---|
| 320 | | if (!isset($dumpData[$tableName])) |
|---|
| 321 | | { |
|---|
| | 329 | $resultsSets = array(); |
|---|
| | 330 | if ($hasParent) |
|---|
| | 331 | { |
|---|
| | 332 | $resultsSets = $this->fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $fixColumn); |
|---|
| | 333 | } |
|---|
| | 334 | else |
|---|
| | 335 | { |
|---|
| | 336 | $resultsSets[] = $this->con->executeQuery('SELECT * FROM '.constant($tableName.'Peer::TABLE_NAME')); |
|---|
| | 337 | } |
|---|
| | 338 | |
|---|
| | 339 | foreach ($resultsSets as $rs) |
|---|
| | 340 | { |
|---|
| | 341 | if($rs->getRecordCount() > 0 && !isset($dumpData[$tableName])){ |
|---|
| 325 | | $dumpData[$tableName][$pk] = $values; |
|---|
| | 345 | while ($rs->next()) |
|---|
| | 346 | { |
|---|
| | 347 | $pk = $tableName; |
|---|
| | 348 | $values = array(); |
|---|
| | 349 | $primaryKeys = array(); |
|---|
| | 350 | $foreignKeys = array(); |
|---|
| | 351 | |
|---|
| | 352 | foreach ($tableMap->getColumns() as $column) |
|---|
| | 353 | { |
|---|
| | 354 | $col = strtolower($column->getColumnName()); |
|---|
| | 355 | $isPrimaryKey = $column->isPrimaryKey(); |
|---|
| | 356 | |
|---|
| | 357 | if (is_null($rs->get($col))) |
|---|
| | 358 | { |
|---|
| | 359 | continue; |
|---|
| | 360 | } |
|---|
| | 361 | |
|---|
| | 362 | if ($isPrimaryKey) |
|---|
| | 363 | { |
|---|
| | 364 | $value = $rs->get($col); |
|---|
| | 365 | $pk .= '_'.$value; |
|---|
| | 366 | $primaryKeys[$col] = $value; |
|---|
| | 367 | } |
|---|
| | 368 | |
|---|
| | 369 | if ($column->isForeignKey()) |
|---|
| | 370 | { |
|---|
| | 371 | $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName()); |
|---|
| | 372 | if ($isPrimaryKey) |
|---|
| | 373 | { |
|---|
| | 374 | $foreignKeys[$col] = $rs->get($col); |
|---|
| | 375 | $primaryKeys[$col] = $relatedTable->getPhpName().'_'.$rs->get($col); |
|---|
| | 376 | } |
|---|
| | 377 | else |
|---|
| | 378 | { |
|---|
| | 379 | $values[$col] = $relatedTable->getPhpName().'_'.$rs->get($col); |
|---|
| | 380 | } |
|---|
| | 381 | } |
|---|
| | 382 | elseif (!$isPrimaryKey || ($isPrimaryKey && !$tableMap->isUseIdGenerator())) |
|---|
| | 383 | { |
|---|
| | 384 | // We did not want auto incremented primary keys |
|---|
| | 385 | $values[$col] = $rs->get($col); |
|---|
| | 386 | } |
|---|
| | 387 | } |
|---|
| | 388 | |
|---|
| | 389 | if (count($primaryKeys) > 1 || (count($primaryKeys) > 0 && count($foreignKeys) > 0)) |
|---|
| | 390 | { |
|---|
| | 391 | $values = array_merge($primaryKeys, $values); |
|---|
| | 392 | } |
|---|
| | 393 | |
|---|
| | 394 | $dumpData[$tableName][$pk] = $values; |
|---|
| | 395 | } |
|---|
| | 458 | |
|---|
| | 459 | protected function fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $column, $in = null) |
|---|
| | 460 | { |
|---|
| | 461 | $rs = $this->con->executeQuery(sprintf('SELECT * FROM %s WHERE %s %s', |
|---|
| | 462 | constant($tableName.'Peer::TABLE_NAME'), |
|---|
| | 463 | strtolower($column->getColumnName()), |
|---|
| | 464 | is_null($in) ? 'IS NULL' : 'IN ('.$in.')' |
|---|
| | 465 | )); |
|---|
| | 466 | $in = array(); |
|---|
| | 467 | while ($rs->next()) |
|---|
| | 468 | { |
|---|
| | 469 | $in[] = "'".$rs->get(strtolower($column->getRelatedColumnName()))."'"; |
|---|
| | 470 | } |
|---|
| | 471 | |
|---|
| | 472 | if ($in = implode(', ', $in)) |
|---|
| | 473 | { |
|---|
| | 474 | $rs->seek(0); |
|---|
| | 475 | $resultsSets[] = $rs; |
|---|
| | 476 | $resultsSets = $this->fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $column, $in); |
|---|
| | 477 | } |
|---|
| | 478 | |
|---|
| | 479 | return $resultsSets; |
|---|
| | 480 | } |
|---|