Skip to content

Commit

Permalink
Actually fixed #2463
Browse files Browse the repository at this point in the history
I have absolutely no idea what I was thinking in 30db5af
  • Loading branch information
brandonkelly committed Feb 21, 2018
1 parent 450d4fb commit f93109e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased

### Fixed
- Fixed an error that occurred when creating a new transform or thumbnail for a remotely-stored image, if Craft didn’t already have a copy of the image cached locally. ([#2463](https://github.com/craftcms/cms/issues/2463))
- Fixed a bug where various asset transform operations could result in a PHP error. ([#2463](https://github.com/craftcms/cms/issues/2463))
- Fixed an error that occurred if a site’s base URL was set to `@web` and the `CRAFT_SITE` constant wasn’t defined. ([#2464](https://github.com/craftcms/cms/issues/2464))
- Fixed a bug where global sets and other elements could become hidden if a new site was added with the “Is this the primary site?” setting enabled. ([#2465](https://github.com/craftcms/cms/issues/2465))
- Fixed a bug where `craft\helpers\ChartHelper::getRunChartDataFromQuery()` was overriding the query’s `SELECT` clause.
Expand Down
30 changes: 20 additions & 10 deletions src/services/AssetTransforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,10 @@ public function getLocalImageSource(Asset $asset): string
if (!is_file($imageSourcePath) || filesize($imageSourcePath) === 0) {

// Delete it just in case it's a 0-byter
if (file_exists($imageSourcePath) && !FileHelper::unlink($imageSourcePath)) {
Craft::warning("Unable to delete the file \"{$imageSourcePath}\".", __METHOD__);
try {
FileHelper::unlink($imageSourcePath);
} catch (ErrorException $e) {
Craft::warning("Unable to delete the file \"{$imageSourcePath}\": ".$e->getMessage(), __METHOD__);
}

$tempFilename = uniqid(pathinfo($asset->filename, PATHINFO_FILENAME), true).'.'.$asset->getExtension();
Expand All @@ -826,8 +828,10 @@ public function getLocalImageSource(Asset $asset): string
$volume->saveFileLocally($asset->getUri(), $tempPath);

if (!is_file($tempPath) || filesize($tempPath) === 0) {
if (!FileHelper::unlink($tempPath)) {
Craft::warning("Unable to delete the file \"{$tempPath}\".", __METHOD__);
try {
FileHelper::unlink($tempPath);
} catch (ErrorException $e) {
Craft::warning("Unable to delete the file \"{$tempPath}\": ".$e->getMessage(), __METHOD__);
}
throw new VolumeException(Craft::t('app', 'Tried to download the source file for image “{file}”, but it was 0 bytes long.',
['file' => $asset->filename]));
Expand All @@ -837,8 +841,10 @@ public function getLocalImageSource(Asset $asset): string

// Delete the leftover data.
$this->queueSourceForDeletingIfNecessary($imageSourcePath);
if (!FileHelper::unlink($tempPath)) {
Craft::warning("Unable to delete the file \"{$tempPath}\".", __METHOD__);
try {
FileHelper::unlink($tempPath);
} catch (ErrorException $e) {
Craft::warning("Unable to delete the file \"{$tempPath}\": ".$e->getMessage(), __METHOD__);
}
}
}
Expand Down Expand Up @@ -1057,8 +1063,10 @@ public function deleteAllTransformData(Asset $asset)

$file = Craft::$app->getPath()->getAssetSourcesPath().DIRECTORY_SEPARATOR.$asset->id.'.'.pathinfo($asset->filename, PATHINFO_EXTENSION);

if (!FileHelper::unlink($file)) {
Craft::warning("Unable to delete the file \"{$file}\".", __METHOD__);
try {
FileHelper::unlink($file);
} catch (ErrorException $e) {
Craft::warning("Unable to delete the file \"{$file}\": ".$e->getMessage(), __METHOD__);
}
}

Expand All @@ -1078,8 +1086,10 @@ public function deleteResizedAssetVersion(Asset $asset)
foreach ($dirs as $dir) {
$files = glob($dir.'/[0-9]*/'.$asset->id.'.[a-z]*');
foreach ($files as $path) {
if (!FileHelper::unlink($path)) {
Craft::warning('Unable to delete asset thumbnails.', __METHOD__);
try {
FileHelper::unlink($path);
} catch (ErrorException $e) {
Craft::warning('Unable to delete asset thumbnails: '.$e->getMessage(), __METHOD__);
}
}
}
Expand Down

0 comments on commit f93109e

Please sign in to comment.