Skip to content

Commit 8142d72

Browse files
authored
Merge pull request #97 from utopia-php/dat-597
updated the bug of resource key setting
2 parents e0e351b + a535cb2 commit 8142d72

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

src/Migration/Cache.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ public function __construct()
2727
}
2828

2929
/**
30-
* Get cache key for a resource
30+
* Get cache key from resource
3131
*
3232
* @param Resource $resource
3333
* @return string
34-
*/
35-
public function getResourceCacheKey(Resource $resource): string
34+
*/
35+
public function resolveResourceCacheKey(Resource $resource): string
3636
{
37+
if (! $resource->getSequence()) {
38+
$resource->setSequence(uniqid());
39+
}
40+
3741
$resourceName = $resource->getName();
3842
$keys = [];
3943

@@ -83,15 +87,7 @@ public function getResourceCacheKey(Resource $resource): string
8387
*/
8488
public function add(Resource $resource): void
8589
{
86-
if (! $resource->getSequence()) {
87-
$resourceId = uniqid();
88-
if (isset($this->cache[$resource->getName()][$resourceId])) {
89-
$resourceId = uniqid();
90-
// todo: $resourceId is not used?
91-
}
92-
$resource->setSequence(uniqid());
93-
}
94-
$key = $this->getResourceCacheKey($resource);
90+
$key = $this->resolveResourceCacheKey($resource);
9591
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
9692
$status = $resource->getStatus();
9793
$this->cache[$resource->getName()][$key] = $status;
@@ -130,7 +126,7 @@ public function addAll(array $resources): void
130126
*/
131127
public function update(Resource $resource): void
132128
{
133-
$key = $this->getResourceCacheKey($resource);
129+
$key = $this->resolveResourceCacheKey($resource);
134130
// if rows then updating the status counter only
135131
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
136132
if (!isset($this->cache[$resource->getName()][$key])) {
@@ -171,7 +167,7 @@ public function updateAll(array $resources): void
171167
*/
172168
public function remove(Resource $resource): void
173169
{
174-
$key = $this->getResourceCacheKey($resource);
170+
$key = $this->resolveResourceCacheKey($resource);
175171
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
176172
if (! isset($this->cache[$resource->getName()][$key])) {
177173
throw new \Exception('Resource does not exist in cache');

0 commit comments

Comments
 (0)