Media uploads
Mark as deleted Change-Id: Id45a95717120a7a5a3c623abb9cb71c2c4be6dd6 Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
a776d6fe0d
commit
922c31fd40
@ -142,7 +142,7 @@ class PresentationMediaUpload extends PresentationMaterial
|
|||||||
return sprintf($format, $mountingFolder, $summit->getId(), $presentation->getId());
|
return sprintf($format, $mountingFolder, $summit->getId(), $presentation->getId());
|
||||||
|
|
||||||
$presentation->generateSlug();
|
$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()
|
public function __construct()
|
||||||
|
46
app/Services/FileSystem/AbstractFileUploadStrategy.php
Normal file
46
app/Services/FileSystem/AbstractFileUploadStrategy.php
Normal 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -11,21 +11,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
use App\Services\FileSystem\IFileUploadStrategy;
|
use App\Services\FileSystem\AbstractFileUploadStrategy;
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
/**
|
/**
|
||||||
* Class DropboxStorageFileUploadStrategy
|
* Class DropboxStorageFileUploadStrategy
|
||||||
* @package App\Services\FileSystem\Dropbox
|
* @package App\Services\FileSystem\Dropbox
|
||||||
*/
|
*/
|
||||||
final class DropboxStorageFileUploadStrategy implements IFileUploadStrategy
|
final class DropboxStorageFileUploadStrategy extends AbstractFileUploadStrategy
|
||||||
{
|
{
|
||||||
|
const Driver = 'dropbox';
|
||||||
|
|
||||||
/**
|
protected function getDriver(): string
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function save(UploadedFile $file, string $path, string $filename)
|
|
||||||
{
|
{
|
||||||
return Storage::disk('dropbox')->putFileAs($path, $file, $filename);
|
return self::Driver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,12 @@ interface IFileUploadStrategy
|
|||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return mixed
|
* @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);
|
||||||
}
|
}
|
@ -11,24 +11,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
use App\Services\FileSystem\IFileUploadStrategy;
|
use App\Services\FileSystem\AbstractFileUploadStrategy;
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
/**
|
/**
|
||||||
* Class LocalStorageFileUploadStrategy
|
* Class LocalStorageFileUploadStrategy
|
||||||
* @package App\Services\FileSystem\Local
|
* @package App\Services\FileSystem\Local
|
||||||
*/
|
*/
|
||||||
final class LocalStorageFileUploadStrategy implements IFileUploadStrategy
|
final class LocalStorageFileUploadStrategy extends AbstractFileUploadStrategy
|
||||||
{
|
{
|
||||||
|
const Driver = 'local';
|
||||||
|
|
||||||
/**
|
protected function getDriver(): string
|
||||||
* @param UploadedFile $file
|
|
||||||
* @param string $path
|
|
||||||
* @param string $filename
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function save(UploadedFile $file, string $path, string $filename)
|
|
||||||
{
|
{
|
||||||
return Storage::disk('local')->putFileAs($path, $file, $filename);
|
return self::Driver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
use App\Services\FileSystem\IFileUploadStrategy;
|
use App\Services\FileSystem\AbstractFileUploadStrategy;
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class S3StorageFileUploadStrategy
|
* Class S3StorageFileUploadStrategy
|
||||||
* @package App\Services\FileSystem\S3
|
* @package App\Services\FileSystem\S3
|
||||||
*/
|
*/
|
||||||
final class S3StorageFileUploadStrategy implements IFileUploadStrategy
|
final class S3StorageFileUploadStrategy extends AbstractFileUploadStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
const Driver = "s3";
|
||||||
* @inheritDoc
|
|
||||||
*/
|
protected function getDriver(): string
|
||||||
public function save(UploadedFile $file, string $path, string $filename)
|
|
||||||
{
|
{
|
||||||
return Storage::disk('s3')->putFileAs($path, $file, $filename);
|
return self::Driver;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,24 +11,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
use App\Services\FileSystem\IFileUploadStrategy;
|
use App\Services\FileSystem\AbstractFileUploadStrategy;
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
/**
|
/**
|
||||||
* Class SwiftStorageFileUploadStrategy
|
* Class SwiftStorageFileUploadStrategy
|
||||||
* @package App\Services\FileSystem\Swift
|
* @package App\Services\FileSystem\Swift
|
||||||
*/
|
*/
|
||||||
class SwiftStorageFileUploadStrategy implements IFileUploadStrategy
|
class SwiftStorageFileUploadStrategy extends AbstractFileUploadStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
const Driver = "swift";
|
||||||
* @param UploadedFile $file
|
|
||||||
* @param string $path
|
protected function getDriver(): string
|
||||||
* @param string $filename
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function save(UploadedFile $file, string $path, string $filename)
|
|
||||||
{
|
{
|
||||||
return Storage::disk('swift')->putFileAs($path, $file, $filename);
|
return self::Driver;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -514,6 +514,22 @@ final class PresentationService
|
|||||||
$presentation_id
|
$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);
|
$summit->removeEvent($presentation);
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -1068,7 +1084,6 @@ final class PresentationService
|
|||||||
if (is_null($mediaUpload))
|
if (is_null($mediaUpload))
|
||||||
throw new EntityNotFoundException('Presentation Media Upload not found.');
|
throw new EntityNotFoundException('Presentation Media Upload not found.');
|
||||||
|
|
||||||
|
|
||||||
$fileInfo = FileUploadInfo::build($request, $payload);
|
$fileInfo = FileUploadInfo::build($request, $payload);
|
||||||
|
|
||||||
if(!is_null($fileInfo)) {
|
if(!is_null($fileInfo)) {
|
||||||
@ -1091,6 +1106,7 @@ final class PresentationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
|
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
|
||||||
|
|
||||||
if (!is_null($strategy)) {
|
if (!is_null($strategy)) {
|
||||||
$strategy->save($fileInfo->getFile(), $mediaUpload->getPath(IStorageTypesConstants::PrivateType), $fileInfo->getFileName());
|
$strategy->save($fileInfo->getFile(), $mediaUpload->getPath(IStorageTypesConstants::PrivateType), $fileInfo->getFileName());
|
||||||
}
|
}
|
||||||
@ -1132,6 +1148,19 @@ final class PresentationService
|
|||||||
throw new EntityNotFoundException("Media Upload not found.");
|
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);
|
$presentation->removeMediaUpload($mediaUpload);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user