diff --git a/src/Migration/Cache.php b/src/Migration/Cache.php index 3e836947..3651bae7 100644 --- a/src/Migration/Cache.php +++ b/src/Migration/Cache.php @@ -27,13 +27,17 @@ public function __construct() } /** - * Get cache key for a resource + * Get cache key from resource * * @param Resource $resource * @return string - */ - public function getResourceCacheKey(Resource $resource): string + */ + public function resolveResourceCacheKey(Resource $resource): string { + if (! $resource->getSequence()) { + $resource->setSequence(uniqid()); + } + $resourceName = $resource->getName(); $keys = []; @@ -83,15 +87,7 @@ public function getResourceCacheKey(Resource $resource): string */ public function add(Resource $resource): void { - if (! $resource->getSequence()) { - $resourceId = uniqid(); - if (isset($this->cache[$resource->getName()][$resourceId])) { - $resourceId = uniqid(); - // todo: $resourceId is not used? - } - $resource->setSequence(uniqid()); - } - $key = $this->getResourceCacheKey($resource); + $key = $this->resolveResourceCacheKey($resource); if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) { $status = $resource->getStatus(); $this->cache[$resource->getName()][$key] = $status; @@ -130,7 +126,7 @@ public function addAll(array $resources): void */ public function update(Resource $resource): void { - $key = $this->getResourceCacheKey($resource); + $key = $this->resolveResourceCacheKey($resource); // if rows then updating the status counter only if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) { if (!isset($this->cache[$resource->getName()][$key])) { @@ -171,7 +167,7 @@ public function updateAll(array $resources): void */ public function remove(Resource $resource): void { - $key = $this->getResourceCacheKey($resource); + $key = $this->resolveResourceCacheKey($resource); if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) { if (! isset($this->cache[$resource->getName()][$key])) { throw new \Exception('Resource does not exist in cache');