PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Services / ExportImportIdMapper.php

ExportImportIdMapper.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Services/ExportImportIdMapper.php

53 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Services;
6
7 /**
8 * Tracks old → new primary keys during import so foreign keys can be rewritten.
9 */
10 final class ExportImportIdMapper
11 {
12 /** @var array<string, array<int, int>> */
13 private array $maps = [];
14
15 public function remember(string $entity, int $oldId, int $newId): void
16 {
17 if ($oldId <= 0 || $newId <= 0) {
18 return;
19 }
20 $this->maps[$entity][$oldId] = $newId;
21 }
22
23 public function map(string $entity, $oldId): ?int
24 {
25 if ($oldId === null || $oldId === '') {
26 return null;
27 }
28 $old = (int) $oldId;
29 if ($old <= 0) {
30 return null;
31 }
32
33 return $this->maps[$entity][$old] ?? null;
34 }
35
36 /**
37 * For nullable FKs: unmapped IDs become null to avoid pointing at wrong rows.
38 *
39 * @param mixed $oldId
40 */
41 public function mapFkNullable(string $entity, $oldId): ?int
42 {
43 if ($oldId === null || $oldId === '') {
44 return null;
45 }
46 if ((int) $oldId === 0) {
47 return null;
48 }
49
50 return $this->map($entity, $oldId);
51 }
52 }
53