Refactoring clear media uploads

Change-Id: Ie7bf2b019707ead97307d4fa7d475c3534774665
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-07-12 22:43:39 -03:00
parent c4e5e7b9ed
commit 286352f795
3 changed files with 54 additions and 41 deletions

View File

@ -14,6 +14,8 @@
use App\Models\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
use App\Models\Foundation\Main\OrderableChilds;
use App\Models\Utils\IStorageTypesConstants;
use App\Services\Filesystem\FileUploadStrategyFactory;
use Behat\Transliterator\Transliterator;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackAnswer;
use App\Models\Foundation\Summit\SelectionPlan;
@ -1641,4 +1643,50 @@ class Presentation extends SummitEvent
{
$this->disclaimer_accepted_date = $disclaimer_accepted_date;
}
public function clearMediaUploads():void{
$mediaUploads = $this->getMediaUploads();
if ($mediaUploads->count()) {
Log::debug("Presentation::clearMediaUploads processing media uploads");
$private_paths = [];
$public_paths = [];
foreach ($mediaUploads as $mediaUpload) {
$mediaUploadType = $mediaUpload->getMediaUploadType();
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
if (!is_null($strategy)) {
$privatePath = $mediaUpload->getPath(IStorageTypesConstants::PrivateType);
if(!isset($private_paths[$privatePath]))
$private_paths[$privatePath] = $strategy;
Log::debug(sprintf("Presentation::clearMediaUploads marking as deleted %s/%s ", $privatePath, $mediaUpload->getFilename()));
$strategy->markAsDeleted($privatePath, $mediaUpload->getFilename());
}
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPublicStorageType());
if (!is_null($strategy)) {
$publicPath = $mediaUpload->getPath(IStorageTypesConstants::PublicType);
if(!isset($public_paths[$publicPath]))
$public_paths[$publicPath] = $strategy;
Log::debug(sprintf("Presentation::clearMediaUploads marking as deleted %s/%s ", $publicPath, $mediaUpload->getFilename()));
$strategy->markAsDeleted($publicPath, $mediaUpload->getFilename());
}
}
foreach($private_paths as $path => $strategy){
Log::debug(sprintf("Presentation::clearMediaUploads marking as deleted path ( private) %s.", $path));
$strategy->markAsDeleted($path);
}
foreach($public_paths as $path => $strategy){
Log::debug(sprintf("Presentation::clearMediaUploads as deleted path ( public ) %s.", $path));
$strategy->markAsDeleted($path);
}
}
}
}

View File

@ -514,48 +514,8 @@ final class PresentationService
$presentation_id
));
$mediaUploads = $presentation->getMediaUploads();
$presentation->clearMediaUploads();
if ($mediaUploads->count()) {
Log::debug(sprintf("PresentationService::deletePresentation processing media uploads"));
$private_paths = [];
$public_paths = [];
foreach ($mediaUploads as $mediaUpload) {
$mediaUploadType = $mediaUpload->getMediaUploadType();
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPrivateStorageType());
if (!is_null($strategy)) {
$privatePath = $mediaUpload->getPath(IStorageTypesConstants::PrivateType);
if(!isset($private_paths[$privatePath]))
$private_paths[$privatePath] = $strategy;
Log::debug(sprintf("PresentationService::deletePresentation marking as deleted %s/%s ", $privatePath, $mediaUpload->getFilename()));
$strategy->markAsDeleted($privatePath, $mediaUpload->getFilename());
}
$strategy = FileUploadStrategyFactory::build($mediaUploadType->getPublicStorageType());
if (!is_null($strategy)) {
$publicPath = $mediaUpload->getPath(IStorageTypesConstants::PublicType);
if(!isset($public_paths[$publicPath]))
$public_paths[$publicPath] = $strategy;
Log::debug(sprintf("PresentationService::deletePresentation marking as deleted %s/%s ", $publicPath, $mediaUpload->getFilename()));
$strategy->markAsDeleted($publicPath, $mediaUpload->getFilename());
}
}
foreach($private_paths as $path => $strategy){
Log::debug(sprintf("PresentationService::deletePresentation marking as deleted path ( private) %s.", $path));
$strategy->markAsDeleted($path);
}
foreach($public_paths as $path => $strategy){
Log::debug(sprintf("PresentationService::deletePresentation marking as deleted path ( public ) %s.", $path));
$strategy->markAsDeleted($path);
}
}
$summit->removeEvent($presentation);
});

View File

@ -1102,6 +1102,11 @@ final class SummitService extends AbstractService implements ISummitService
if ($event->getSummit()->getIdentifier() !== $summit->getIdentifier())
throw new ValidationException(sprintf("event %s does not belongs to summit id %s", $event_id, $summit->getIdentifier()));
if($event instanceof Presentation){
$event->clearMediaUploads();
}
$this->event_repository->delete($event);
return true;