Enable moving inbound files to s3 and logging in DB
This commit is contained in:
@@ -7,7 +7,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File as FileFacade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\{CollectionOrNull,CompressedString};
|
||||
@@ -58,13 +60,17 @@ class File extends Model
|
||||
parent::boot();
|
||||
|
||||
static::creating(function($model) {
|
||||
Log::debug(sprintf('%s:- Storing file [%s]',self::LOGKEY,$model->file));
|
||||
Log::debug(sprintf('%s:- Storing file [%s] in [%s]',self::LOGKEY,$model->fullname,$model->full_storage_path));
|
||||
|
||||
// Store file
|
||||
|
||||
// Delete file from inbound
|
||||
if (Storage::put($model->full_storage_path,Storage::disk('local')->get($model->fullname),'public')) {
|
||||
unlink($model->fullname);
|
||||
} else {
|
||||
throw new \Exception(sprintf('Unable to move file [%s] to [%s]',$model->fullname,$model->full_storage_path));
|
||||
};
|
||||
|
||||
// Delete anything being replaced
|
||||
// @todo implement replace
|
||||
});
|
||||
|
||||
// @todo if the file is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
|
||||
@@ -148,6 +154,13 @@ class File extends Model
|
||||
->withPivot(['id','parent_id','extra']);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getFullStoragePathAttribute(): string
|
||||
{
|
||||
return sprintf('%04X/%s',$this->filearea_id,$this->file);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function jsonSerialize(): array
|
||||
|
Reference in New Issue
Block a user