fixed import export
This commit is contained in:
@ -3,8 +3,11 @@
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\JobShouldQueue;
|
||||
use App\Models\Common\Media as MediaModel;
|
||||
use App\Notifications\Common\ExportCompleted;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use MediaUploader;
|
||||
|
||||
class CreateMediableForExport extends JobShouldQueue
|
||||
{
|
||||
@ -33,18 +36,7 @@ class CreateMediableForExport extends JobShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$source = storage_path('app/uploads/' . $this->file_name);
|
||||
$destination = storage_path('app/uploads/' . company_id() . '/exports/');
|
||||
|
||||
// Create exports directory
|
||||
if (!File::isDirectory($destination)) {
|
||||
File::makeDirectory($destination);
|
||||
}
|
||||
|
||||
File::move($source, $destination . $this->file_name);
|
||||
|
||||
// Create the media record
|
||||
$media = $this->importMedia($this->file_name, 'exports');
|
||||
$media = $this->getQueuedMedia();
|
||||
|
||||
$this->user->attachMedia($media, 'export');
|
||||
|
||||
@ -52,4 +44,55 @@ class CreateMediableForExport extends JobShouldQueue
|
||||
|
||||
$this->user->notify(new ExportCompleted($download_url));
|
||||
}
|
||||
|
||||
public function getQueuedMedia()
|
||||
{
|
||||
return config('excel.temporary_files.remote_disk') !== null
|
||||
? $this->getRemoteQueuedMedia()
|
||||
: $this->getLocalQueuedMedia();
|
||||
}
|
||||
|
||||
public function getLocalQueuedMedia()
|
||||
{
|
||||
$source = storage_path('app/temp/' . $this->file_name);
|
||||
|
||||
$destination = $this->getMediaFolder('exports');
|
||||
|
||||
$media = MediaUploader::makePrivate()
|
||||
->beforeSave(function(MediaModel $media) {
|
||||
$media->company_id = company_id();
|
||||
})
|
||||
->fromSource($source)
|
||||
->toDirectory($destination)
|
||||
->upload();
|
||||
|
||||
File::delete($source);
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
public function getRemoteQueuedMedia()
|
||||
{
|
||||
$disk = config('excel.temporary_files.remote_disk');
|
||||
$prefix = config('excel.temporary_files.remote_prefix');
|
||||
|
||||
$content = Storage::disk($disk)->get($this->file_name);
|
||||
|
||||
$file_name = str_replace([$prefix, '.xlsx', '.xls'], '', $this->file_name);
|
||||
|
||||
$destination = $this->getMediaFolder('exports');
|
||||
|
||||
$media = MediaUploader::makePrivate()
|
||||
->beforeSave(function(MediaModel $media) {
|
||||
$media->company_id = company_id();
|
||||
})
|
||||
->fromString($content)
|
||||
->useFilename($file_name)
|
||||
->toDirectory($destination)
|
||||
->upload();
|
||||
|
||||
Storage::disk($disk)->delete($this->file_name);
|
||||
|
||||
return $media;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user