Skip to content

Commit

Permalink
Merge pull request #544 from emielmolenaar/configurable-temp-path
Browse files Browse the repository at this point in the history
Fixes running multiple workers processing image manipulations
  • Loading branch information
freekmurze committed Mar 8, 2017
2 parents 0293be9 + 15d1946 commit c9ed3f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions config/medialibrary.php
Expand Up @@ -8,6 +8,12 @@
*/
'defaultFilesystem' => 'media',

/*
* The path where to store temporary files while performing image conversions.
* If set to null, storage_path('medialibrary/temp') will be used.
*/
'temp_file_path' => null,

/*
* The maximum file size of an item in bytes. Adding a file
* that is larger will result in an exception.
Expand Down
20 changes: 18 additions & 2 deletions src/FileManipulator.php
Expand Up @@ -55,7 +55,7 @@ public function performConversions(ConversionCollection $conversions, Media $med
return;
}

$temporaryDirectory = new TemporaryDirectory(storage_path('medialibrary/temp'));
$temporaryDirectory = new TemporaryDirectory($this->getTemporaryDirectoryPath());

$copiedOriginalFile = app(Filesystem::class)->copyFromMediaLibrary(
$media,
Expand All @@ -76,9 +76,11 @@ public function performConversions(ConversionCollection $conversions, Media $med
app(Filesystem::class)->copyToMediaLibrary($renamedFile, $media, true);

event(new ConversionHasBeenCompleted($media, $conversion));

unlink($renamedFile);
}

$temporaryDirectory->delete();
unlink($copiedOriginalFile);
}

public function performConversion(Media $media, Conversion $conversion, string $imageFile): string
Expand Down Expand Up @@ -109,6 +111,20 @@ protected function dispatchQueuedConversions(Media $media, ConversionCollection
app(Dispatcher::class)->dispatch($job);
}

/**
* @return string
*/
protected function getTemporaryDirectoryPath(): string
{
$path = config('medialibrary.temp_file_path');

if ($path !== null) {
return $path;
}

return storage_path('medialibrary/temp');
}

/**
* @param \Spatie\MediaLibrary\Media $media
*
Expand Down

0 comments on commit c9ed3f7

Please sign in to comment.