Skip to content

Commit e95e298

Browse files
fixed the bug of status not updating and internal id not getting assigned to the documents
1 parent 9f9aef7 commit e95e298

2 files changed

Lines changed: 47 additions & 49 deletions

File tree

src/Migration/Cache.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ public function __construct()
3030
*/
3131
public function add(Resource $resource): void
3232
{
33-
// if documents then storing the status counter only
34-
if ($resource->getName() == Resource::TYPE_DOCUMENT) {
35-
$status = $resource->getStatus();
36-
$documentId = $resource->getInternalId();
37-
$this->cache[$resource->getName()][$documentId] = $status;
38-
return;
39-
}
40-
4133
if (! $resource->getInternalId()) {
4234
$resourceId = uniqid();
4335
if (isset($this->cache[$resource->getName()][$resourceId])) {
@@ -47,6 +39,13 @@ public function add(Resource $resource): void
4739
$resource->setInternalId(uniqid());
4840
}
4941

42+
if ($resource->getName() == Resource::TYPE_DOCUMENT) {
43+
$status = $resource->getStatus();
44+
$documentId = $resource->getInternalId();
45+
$this->cache[$resource->getName()][$documentId] = $status;
46+
return;
47+
}
48+
5049
if ($resource->getName() == Resource::TYPE_FILE || $resource->getName() == Resource::TYPE_DEPLOYMENT) {
5150
/** @var File|Deployment $resource */
5251
$resource->setData(''); // Prevent Memory Leak

src/Migration/Transfer.php

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,24 @@ public function getStatusCounters(): array
129129
}
130130
}
131131
}
132-
132+
133133
foreach ($this->cache->getAll() as $resourceType => $resources) {
134-
foreach ($resources as $resourceId => $resource) {
134+
foreach ($resources as $resource) {
135135
if ($resourceType === Resource::TYPE_DOCUMENT && is_string($resource)) {
136136
$documentStatus = $resource;
137137
$status[$resourceType][$documentStatus]++;
138-
139-
if ($documentStatus === 'pending' && $status[$resourceType]['pending'] > 0) {
138+
139+
if ($status[$resourceType]['pending'] > 0) {
140140
$status[$resourceType]['pending']--;
141141
}
142-
143-
continue; // Skip to next iteration
142+
143+
continue;
144144
}
145-
146-
// For all other non-document resources
145+
147146
if (isset($status[$resource->getName()])) {
148147
$status[$resource->getName()][$resource->getStatus()]++;
149-
150-
if ($resource->getStatus() === 'pending' && $status[$resource->getName()]['pending'] > 0) {
148+
149+
if ($status[$resource->getName()]['pending'] > 0) {
151150
$status[$resource->getName()]['pending']--;
152151
}
153152
}
@@ -270,46 +269,46 @@ public function getCurrentResource(): string
270269
* @param string $statusLevel If no status level is provided, all status types will be returned.
271270
* @return array<array<string, mixed>>
272271
*/
273-
public function getReport(string $statusLevel = ''): array
274-
{
275-
$report = [];
276-
$cache = $this->cache->getAll();
272+
public function getReport(string $statusLevel = ''): array
273+
{
274+
$report = [];
275+
$cache = $this->cache->getAll();
276+
277+
foreach ($cache as $type => $resources) {
278+
foreach ($resources as $id => $resource) {
279+
if ($type === Resource::TYPE_DOCUMENT && is_string($resource)) {
280+
if ($statusLevel && $resource !== $statusLevel) {
281+
continue;
282+
}
283+
// no message for document is stored
284+
$report[] = [
285+
'resource' => $type,
286+
'id' => $id,
287+
'status' => $resource,
288+
'message' => '',
289+
];
290+
continue;
291+
}
292+
293+
if (!is_object($resource)) {
294+
continue;
295+
}
277296

278-
foreach ($cache as $type => $resources) {
279-
foreach ($resources as $id => $resource) {
280-
if ($type === Resource::TYPE_DOCUMENT && is_string($resource)) {
281-
if ($statusLevel && $resource !== $statusLevel) {
297+
if ($statusLevel && $resource->getStatus() !== $statusLevel) {
282298
continue;
283299
}
284-
// no message for document is stored
300+
285301
$report[] = [
286302
'resource' => $type,
287-
'id' => $id,
288-
'status' => $resource,
289-
'message' => '',
303+
'id' => $resource->getId(),
304+
'status' => $resource->getStatus(),
305+
'message' => $resource->getMessage(),
290306
];
291-
continue;
292-
}
293-
294-
if (!is_object($resource)) {
295-
continue;
296-
}
297-
298-
if ($statusLevel && $resource->getStatus() !== $statusLevel) {
299-
continue;
300307
}
301-
302-
$report[] = [
303-
'resource' => $type,
304-
'id' => $resource->getId(),
305-
'status' => $resource->getStatus(),
306-
'message' => $resource->getMessage(),
307-
];
308308
}
309-
}
310309

311-
return $report;
312-
}
310+
return $report;
311+
}
313312

314313
/**
315314
* @throws \Exception

0 commit comments

Comments
 (0)