Skip to content

Commit 5a5503f

Browse files
committed
update: swap variable terminologies.
1 parent c839b03 commit 5a5503f

File tree

6 files changed

+62
-68
lines changed

6 files changed

+62
-68
lines changed

src/Migration/Cache.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function add(Resource $resource): void
4141

4242
if ($resource->getName() == Resource::TYPE_ROW) {
4343
$status = $resource->getStatus();
44-
$documentId = $resource->getSequence();
45-
$this->cache[$resource->getName()][$documentId] = $status;
44+
$rowId = $resource->getSequence();
45+
$this->cache[$resource->getName()][$rowId] = $status;
4646
return;
4747
}
4848

@@ -78,14 +78,14 @@ public function addAll(array $resources): void
7878
*/
7979
public function update(Resource $resource): void
8080
{
81-
// if documents then updating the status counter only
81+
// if rows then updating the status counter only
8282
if ($resource->getName() == Resource::TYPE_ROW) {
83-
$documentId = $resource->getSequence();
84-
if (!isset($this->cache[$resource->getName()][$documentId])) {
83+
$rowId = $resource->getSequence();
84+
if (!isset($this->cache[$resource->getName()][$rowId])) {
8585
$this->add($resource);
8686
} else {
8787
$status = $resource->getStatus();
88-
$this->cache[$resource->getName()][$documentId] = $status;
88+
$this->cache[$resource->getName()][$rowId] = $status;
8989
}
9090
return;
9191
}

src/Migration/Sources/Appwrite.php

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private function exportTables(int $batchSize): void
685685
$response = $this->database->listTables($database, $queries);
686686

687687
foreach ($response as $table) {
688-
$newCollection = new Table(
688+
$newTable = new Table(
689689
$database,
690690
$table['name'],
691691
$table['$id'],
@@ -695,7 +695,7 @@ private function exportTables(int $batchSize): void
695695
$table['$updatedAt'],
696696
);
697697

698-
$tables[] = $newCollection;
698+
$tables[] = $newTable;
699699
}
700700

701701
if (empty($tables)) {
@@ -744,7 +744,7 @@ private function exportColumns(int $batchSize): void
744744

745745
switch ($column['type']) {
746746
case Column::TYPE_STRING:
747-
$attr = match ($column['format'] ?? '') {
747+
$col = match ($column['format'] ?? '') {
748748
Column::TYPE_EMAIL => new Email(
749749
$column['key'],
750750
$table,
@@ -800,7 +800,7 @@ private function exportColumns(int $batchSize): void
800800

801801
break;
802802
case Column::TYPE_BOOLEAN:
803-
$attr = new Boolean(
803+
$col = new Boolean(
804804
$column['key'],
805805
$table,
806806
required: $column['required'],
@@ -811,7 +811,7 @@ private function exportColumns(int $batchSize): void
811811
);
812812
break;
813813
case Column::TYPE_INTEGER:
814-
$attr = new Integer(
814+
$col = new Integer(
815815
$column['key'],
816816
$table,
817817
required: $column['required'],
@@ -824,7 +824,7 @@ private function exportColumns(int $batchSize): void
824824
);
825825
break;
826826
case Column::TYPE_FLOAT:
827-
$attr = new Decimal(
827+
$col = new Decimal(
828828
$column['key'],
829829
$table,
830830
required: $column['required'],
@@ -837,7 +837,7 @@ private function exportColumns(int $batchSize): void
837837
);
838838
break;
839839
case Column::TYPE_RELATIONSHIP:
840-
$attr = new Relationship(
840+
$col = new Relationship(
841841
$column['key'],
842842
$table,
843843
relatedTable: $column['relatedCollection'],
@@ -851,7 +851,7 @@ private function exportColumns(int $batchSize): void
851851
);
852852
break;
853853
case Column::TYPE_DATETIME:
854-
$attr = new DateTime(
854+
$col = new DateTime(
855855
$column['key'],
856856
$table,
857857
required: $column['required'],
@@ -863,7 +863,7 @@ private function exportColumns(int $batchSize): void
863863
break;
864864
}
865865

866-
if (!isset($attr)) {
866+
if (!isset($col)) {
867867
throw new Exception(
868868
resourceName: Resource::TYPE_COLUMN,
869869
resourceGroup: Transfer::GROUP_DATABASES,
@@ -872,7 +872,7 @@ private function exportColumns(int $batchSize): void
872872
);
873873
}
874874

875-
$columns[] = $attr;
875+
$columns[] = $col;
876876
}
877877

878878
if (empty($columns)) {
@@ -990,47 +990,47 @@ private function exportRows(int $batchSize): void
990990

991991
$response = $this->database->listRows($table, $queries);
992992

993-
foreach ($response as $document) {
993+
foreach ($response as $row) {
994994
// HACK: Handle many to many
995995
if (!empty($manyToMany)) {
996996
$stack = ['$id']; // Adding $id because we can't select only relations
997997
foreach ($manyToMany as $relation) {
998998
$stack[] = $relation . '.$id';
999999
}
10001000

1001-
$doc = $this->database->getRow(
1001+
$rowItem = $this->database->getRow(
10021002
$table,
1003-
$document['$id'],
1003+
$row['$id'],
10041004
[$this->database->querySelect($stack)]
10051005
);
10061006

10071007
foreach ($manyToMany as $key) {
1008-
$document[$key] = [];
1009-
foreach ($doc[$key] as $relationDocument) {
1010-
$document[$key][] = $relationDocument['$id'];
1008+
$row[$key] = [];
1009+
foreach ($rowItem[$key] as $relatedRowItem) {
1010+
$row[$key][] = $relatedRowItem['$id'];
10111011
}
10121012
}
10131013
}
10141014

1015-
$id = $document['$id'];
1016-
$permissions = $document['$permissions'];
1015+
$id = $row['$id'];
1016+
$permissions = $row['$permissions'];
10171017

1018-
unset($document['$id']);
1019-
unset($document['$permissions']);
1020-
unset($document['$collectionId']);
1021-
unset($document['$databaseId']);
1022-
unset($document['$sequence']);
1023-
unset($document['$collection']);
1018+
unset($row['$id']);
1019+
unset($row['$permissions']);
1020+
unset($row['$collectionId']);
1021+
unset($row['$databaseId']);
1022+
unset($row['$sequence']);
1023+
unset($row['$collection']);
10241024

1025-
$document = new Row(
1025+
$row = new Row(
10261026
$id,
10271027
$table,
1028-
$document,
1028+
$row,
10291029
$permissions
10301030
);
10311031

1032-
$rows[] = $document;
1033-
$lastRow = $document;
1032+
$rows[] = $row;
1033+
$lastRow = $row;
10341034
}
10351035

10361036
$this->callback($rows);
@@ -1456,10 +1456,4 @@ private function exportDeploymentData(Func $func, array $deployment): void
14561456
}
14571457
}
14581458
}
1459-
1460-
1461-
private function mapCollectionToTable()
1462-
{
1463-
1464-
}
14651459
}

src/Migration/Sources/Appwrite/Reader/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ public function listRows(TableResource $resource, array $queries = []): array
308308
);
309309
}
310310

311-
return \array_map(function ($document) {
312-
return $document->getArrayCopy();
311+
return \array_map(function ($row) {
312+
return $row->getArrayCopy();
313313
}, $rows);
314314
}
315315

src/Migration/Sources/CSV.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ private function exportRows(int $batchSize): void
169169

170170
$buffer = [];
171171

172-
while (($row = fgetcsv($stream)) !== false) {
173-
if (count($row) !== count($headers)) {
172+
while (($csvRowItem = fgetcsv($stream)) !== false) {
173+
if (count($csvRowItem) !== count($headers)) {
174174
throw new \Exception('CSV row does not match the number of header columns.');
175175
}
176176

177-
$data = array_combine($headers, $row);
177+
$data = array_combine($headers, $csvRowItem);
178178
if ($data === false) {
179179
continue;
180180
}
@@ -205,13 +205,13 @@ private function exportRows(int $batchSize): void
205205
};
206206
}
207207

208-
$documentId = $parsedData['$id'] ?? 'unique()';
208+
$rowId = $parsedData['$id'] ?? 'unique()';
209209

210210
// `$id`, `$permissions` in the doc can cause issues!
211211
unset($parsedData['$id'], $parsedData['$permissions']);
212212

213-
$document = new Row($documentId, $table, $parsedData);
214-
$buffer[] = $document;
213+
$row = new Row($rowId, $table, $parsedData);
214+
$buffer[] = $row;
215215

216216
if (count($buffer) === $batchSize) {
217217
$this->callback($buffer);
@@ -286,27 +286,27 @@ private function withCsvStream(callable $fn): void
286286
/**
287287
* @throws \Exception
288288
*/
289-
private function validateCSVHeaders(array $headers, array $attributeTypes): void
289+
private function validateCSVHeaders(array $headers, array $columnTypes): void
290290
{
291-
$expectedAttributes = array_keys($attributeTypes);
291+
$expectedColumns = array_keys($columnTypes);
292292

293293
// Ignore keys like $id, $permissions, etc.
294294
$filteredHeaders = array_filter($headers, fn ($key) => ! str_starts_with($key, '$'));
295295

296-
$extraAttributes = array_diff($filteredHeaders, $expectedAttributes);
297-
$missingAttributes = array_diff($expectedAttributes, $filteredHeaders);
296+
$extraColumns = array_diff($filteredHeaders, $expectedColumns);
297+
$missingColumns = array_diff($expectedColumns, $filteredHeaders);
298298

299-
if (! empty($missingAttributes) || ! empty($extraAttributes)) {
299+
if (! empty($missingColumns) || ! empty($extraColumns)) {
300300
$messages = [];
301301

302-
if (! empty($missingAttributes)) {
303-
$label = count($missingAttributes) === 1 ? 'Missing column' : 'Missing columns';
304-
$messages[] = "{$label}: '".implode("', '", $missingAttributes)."'";
302+
if (! empty($missingColumns)) {
303+
$label = count($missingColumns) === 1 ? 'Missing column' : 'Missing columns';
304+
$messages[] = "{$label}: '".implode("', '", $missingColumns)."'";
305305
}
306306

307-
if (! empty($extraAttributes)) {
308-
$label = count($extraAttributes) === 1 ? 'Unexpected column' : 'Unexpected columns';
309-
$messages[] = "{$label}: '".implode("', '", $extraAttributes)."'";
307+
if (! empty($extraColumns)) {
308+
$label = count($extraColumns) === 1 ? 'Unexpected column' : 'Unexpected columns';
309+
$messages[] = "{$label}: '".implode("', '", $extraColumns)."'";
310310
}
311311

312312
throw new \Exception('CSV header mismatch. '.implode(' | ', $messages));

src/Migration/Sources/Firebase.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ private function exportTable(Table $table, int $batchSize, bool $transferRows):
498498

499499
// Transfer Documents and Calculate Schemas
500500
while (true) {
501-
$documents = [];
501+
$rows = [];
502502

503503
$result = $this->call('GET', $resourceURL, [
504504
'Content-Type' => 'application/json',
@@ -522,7 +522,7 @@ private function exportTable(Table $table, int $batchSize, bool $transferRows):
522522
}
523523
}
524524

525-
$documents[] = $this->convertRow($table, $row, $rowSchema);
525+
$rows[] = $this->convertRow($table, $row, $rowSchema);
526526
}
527527

528528
// Transfer Rows
@@ -544,7 +544,7 @@ private function exportTable(Table $table, int $batchSize, bool $transferRows):
544544
$this->callback(array_values($columnsToCreate));
545545
}
546546

547-
$this->callback($documents);
547+
$this->callback($rows);
548548
}
549549

550550
if (count($result['documents']) < $batchSize) {
@@ -590,10 +590,10 @@ private function calculateValue(array $field)
590590
}
591591
}
592592

593-
private function convertRow(Table $table, array $document, array $rowSchema): Row
593+
private function convertRow(Table $table, array $row, array $rowSchema): Row
594594
{
595595
$data = [];
596-
foreach ($document['fields'] as $key => $field) {
596+
foreach ($row['fields'] as $key => $field) {
597597
$value = $this->calculateValue($field);
598598

599599
if ($rowSchema[$key]->getType() === Column::TYPE_STRING && is_array($value)) {
@@ -605,7 +605,7 @@ private function convertRow(Table $table, array $document, array $rowSchema): Ro
605605
$data[$key] = $value;
606606
}
607607

608-
$rowId = explode('/', $document['name']);
608+
$rowId = explode('/', $row['name']);
609609
$rowId = end($rowId);
610610
// Strip non-alphanumeric except underscore and hyphen
611611
$rowId = preg_replace("/[^A-Za-z0-9\_\-]/", '', $rowId);

src/Migration/Transfer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public function getStatusCounters(): array
133133
foreach ($this->cache->getAll() as $resourceType => $resources) {
134134
foreach ($resources as $resource) {
135135
if ($resourceType === Resource::TYPE_ROW && is_string($resource)) {
136-
$documentStatus = $resource;
137-
$status[$resourceType][$documentStatus]++;
136+
$rowStatus = $resource;
137+
$status[$resourceType][$rowStatus]++;
138138

139139
if ($status[$resourceType]['pending'] > 0) {
140140
$status[$resourceType]['pending']--;
@@ -280,7 +280,7 @@ public function getReport(string $statusLevel = ''): array
280280
if ($statusLevel && $resource !== $statusLevel) {
281281
continue;
282282
}
283-
// no message for document is stored
283+
// no message for row is stored
284284
$report[] = [
285285
'resource' => $type,
286286
'id' => $id,

0 commit comments

Comments
 (0)