Media uploads

Mark as deleted

Change-Id: Id45a95717120a7a5a3c623abb9cb71c2c4be6dd6
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-07-12 21:48:14 -03:00
parent a776d6fe0d
commit 922c31fd40
8 changed files with 107 additions and 46 deletions

View File

@ -142,7 +142,7 @@ class PresentationMediaUpload extends PresentationMaterial
return sprintf($format, $mountingFolder, $summit->getId(), $presentation->getId());
$presentation->generateSlug();
return sprintf($format, $mountingFolder, sprintf("%s-%s",$summit->getId(), filter_var($summit->getRawSlug(), FILTER_SANITIZE_ENCODED)), sprintf("%s-%s", $presentation->getId(), filter_var($presentation->getSlug(), FILTER_SANITIZE_ENCODED)));
return sprintf($format, $mountingFolder, sprintf("%s-%s", $summit->getId(), filter_var($summit->getRawSlug(), FILTER_SANITIZE_ENCODED)), sprintf("%s-%s", $presentation->getId(), filter_var($presentation->getSlug(), FILTER_SANITIZE_ENCODED)));
}
public function __construct()

View File

@ -0,0 +1,46 @@
<?php namespace App\Services\FileSystem;
/**
* Copyright 2021 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
/**
* Class AbstractFileUploadStrategy
* @package App\Services\FileSystem
*/
abstract class AbstractFileUploadStrategy implements IFileUploadStrategy
{
abstract protected function getDriver():string;
/**
* @inheritDoc
*/
public function save(UploadedFile $file, string $path, string $filename)
{
return Storage::disk($this->getDriver())->putFileAs($path, $file, $filename);
}
/**
* @param string $path
* @param string $filename
* @return bool|mixed
*/
public function markAsDeleted(string $path, string $filename)
{
Log::debug(sprintf("AbstractFileUploadStrategy:: markAsDeleted path %s filename %s", $path, $filename));
return Storage::disk($this->getDriver())->move
(
sprintf("%s/%s", $path, $filename),
sprintf("%s/DELETED_%s", $path, $filename)
);
}
}

View File

@ -11,21 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\FileSystem\IFileUploadStrategy;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Services\FileSystem\AbstractFileUploadStrategy;
/**
* Class DropboxStorageFileUploadStrategy
* @package App\Services\FileSystem\Dropbox
*/
final class DropboxStorageFileUploadStrategy implements IFileUploadStrategy
final class DropboxStorageFileUploadStrategy extends AbstractFileUploadStrategy
{
const Driver = 'dropbox';
/**
* @inheritDoc
*/
public function save(UploadedFile $file, string $path, string $filename)
protected function getDriver(): string
{
return Storage::disk('dropbox')->putFileAs($path, $file, $filename);
return self::Driver;
}
}

View File

@ -25,5 +25,12 @@ interface IFileUploadStrategy
* @param string $filename
* @return mixed
*/
public function save(UploadedFile $file, string $path, string $filename);
public function save(UploadedFile $file, string $path, string $filename);
/**
* @param string $path
* @param string $filename
* @return mixed
*/
public function markAsDeleted(string $path, string $filename);
}

View File

@ -11,24 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\FileSystem\IFileUploadStrategy;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Services\FileSystem\AbstractFileUploadStrategy;
/**
* Class LocalStorageFileUploadStrategy
* @package App\Services\FileSystem\Local
*/
final class LocalStorageFileUploadStrategy implements IFileUploadStrategy
final class LocalStorageFileUploadStrategy extends AbstractFileUploadStrategy
{
const Driver = 'local';
/**
* @param UploadedFile $file
* @param string $path
* @param string $filename
* @return mixed
*/
public function save(UploadedFile $file, string $path, string $filename)
protected function getDriver(): string
{
return Storage::disk('local')->putFileAs($path, $file, $filename);
return self::Driver;
}
}

View File

@ -11,22 +11,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\FileSystem\IFileUploadStrategy;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Services\FileSystem\AbstractFileUploadStrategy;
/**
* Class S3StorageFileUploadStrategy
* @package App\Services\FileSystem\S3
*/
final class S3StorageFileUploadStrategy implements IFileUploadStrategy
final class S3StorageFileUploadStrategy extends AbstractFileUploadStrategy
{
/**
* @inheritDoc
*/
public function save(UploadedFile $file, string $path, string $filename)
const Driver = "s3";
protected function getDriver(): string
{
return Storage::disk('s3')->putFileAs($path, $file, $filename);
return self::Driver;
}
}

View File

@ -11,24 +11,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\FileSystem\IFileUploadStrategy;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Services\FileSystem\AbstractFileUploadStrategy;
/**
* Class SwiftStorageFileUploadStrategy
* @package App\Services\FileSystem\Swift
*/
class SwiftStorageFileUploadStrategy implements IFileUploadStrategy
class SwiftStorageFileUploadStrategy extends AbstractFileUploadStrategy
{
/**
* @param UploadedFile $file
* @param string $path
* @param string $filename
* @return mixed
*/
public function save(UploadedFile $file, string $path, string $filename)
const Driver = "swift";
protected function getDriver(): string
{
return Storage::disk('swift')->putFileAs($path, $file, $filename);
return self::Driver;
}
}

View File

@ -514,6 +514,22 @@ final class PresentationService
$presentation_id
));
foreach($presentation->getMediaUploads() as $mediaUpload){
$mediaUploadType = $mediaUpload->getMediaUploadType();
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
if (!is_null($strategy)) {
$strategy->markAsDeleted($mediaUpload->getPath(IStorageTypesConstants::PrivateType), $mediaUpload->getFilename());
}
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPublicStorageType());
if (!is_null($strategy)) {
$strategy->markAsDeleted($mediaUpload->getPath(IStorageTypesConstants::PublicType), $mediaUpload->getFilename());
}
}
$summit->removeEvent($presentation);
});
@ -1068,7 +1084,6 @@ final class PresentationService
if (is_null($mediaUpload))
throw new EntityNotFoundException('Presentation Media Upload not found.');
$fileInfo = FileUploadInfo::build($request, $payload);
if(!is_null($fileInfo)) {
@ -1091,6 +1106,7 @@ final class PresentationService
}
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
if (!is_null($strategy)) {
$strategy->save($fileInfo->getFile(), $mediaUpload->getPath(IStorageTypesConstants::PrivateType), $fileInfo->getFileName());
}
@ -1132,6 +1148,19 @@ final class PresentationService
throw new EntityNotFoundException("Media Upload not found.");
}
$mediaUploadType = $mediaUpload->getMediaUploadType();
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
if (!is_null($strategy)) {
$strategy->markAsDeleted($mediaUpload->getPath(IStorageTypesConstants::PrivateType), $mediaUpload->getFilename());
}
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPublicStorageType());
if (!is_null($strategy)) {
$strategy->markAsDeleted($mediaUpload->getPath(IStorageTypesConstants::PublicType), $mediaUpload->getFilename());
}
$presentation->removeMediaUpload($mediaUpload);
});
}