Skip to content

Commit

Permalink
Use old locally-copied files as fallback, then delete them
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Feb 16, 2021
1 parent 5b09707 commit 42ee225
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,27 @@ private function _getAssetContents(Asset $asset): array
$contents = Craft::$app->getCache()->getOrSet(
$this->getCachedAssetKey($asset),
static function() use($asset) {
return $asset->getContents();
$oldCacheDir = Craft::$app->getPath()->getAssetsPath(false) . DIRECTORY_SEPARATOR . 'embeddedassets';
$oldSubDir = $oldCacheDir . DIRECTORY_SEPARATOR . substr($asset->uid, 0, 2);
$oldCachedPath = $oldSubDir . DIRECTORY_SEPARATOR . $asset->uid . '.json';
$contents = null;

if (file_exists($oldCachedPath)) {
$contents = file_get_contents($oldCachedPath);
FileHelper::unlink($oldCachedPath);

if (FileHelper::isDirectoryEmpty($oldSubDir)) {
FileHelper::removeDirectory($oldSubDir);
}

if (FileHelper::isDirectoryEmpty($oldCacheDir)) {
FileHelper::removeDirectory($oldCacheDir);
}
} else {
$contents = $asset->getContents();
}

return $contents;
},
0);

Expand Down

0 comments on commit 42ee225

Please sign in to comment.