diff --git a/ProcessMaker/Http/Controllers/Api/ProcessLaunchpadController.php b/ProcessMaker/Http/Controllers/Api/ProcessLaunchpadController.php index a25e7452e6..dfa57ef036 100644 --- a/ProcessMaker/Http/Controllers/Api/ProcessLaunchpadController.php +++ b/ProcessMaker/Http/Controllers/Api/ProcessLaunchpadController.php @@ -76,7 +76,8 @@ public function index(Request $request, Process $process) // Get the embed related $processes = Process::with('launchpad') ->with(['media' => function ($query) { - $query->orderBy('order_column', 'asc'); + $query->where('collection_name', '!=', Media::COLLECTION_SLIDESHOW) + ->orderBy('order_column', 'asc'); }]) ->with(['embed' => function ($query) { $query->orderBy('order_column', 'asc'); diff --git a/ProcessMaker/ImportExport/Exporters/ProcessExporter.php b/ProcessMaker/ImportExport/Exporters/ProcessExporter.php index 5a030af513..94a425902b 100644 --- a/ProcessMaker/ImportExport/Exporters/ProcessExporter.php +++ b/ProcessMaker/ImportExport/Exporters/ProcessExporter.php @@ -9,6 +9,7 @@ use ProcessMaker\ImportExport\Psudomodels\Signal; use ProcessMaker\ImportExport\Utils; use ProcessMaker\Models\Group; +use ProcessMaker\Models\Media; use ProcessMaker\Models\Process; use ProcessMaker\Models\ProcessCategory; use ProcessMaker\Models\Screen; @@ -67,7 +68,6 @@ public function export() : void $this->exportSubprocesses(); $this->exportProcessLaunchpad(); $this->exportMedia(); - $this->exportEmbed(); } @@ -437,7 +437,7 @@ public function importEmbed(): void */ public function exportMedia(): void { - $this->model->media->each(function ($media) { + $this->model->media->where('collection_name', '!=', Media::COLLECTION_SLIDESHOW)->each(function ($media) { $this->addDependent(DependentType::MEDIA, $media, MediaExporter::class); }); } diff --git a/ProcessMaker/Models/Media.php b/ProcessMaker/Models/Media.php index 98a2008270..36a3d43b0f 100644 --- a/ProcessMaker/Models/Media.php +++ b/ProcessMaker/Models/Media.php @@ -65,6 +65,8 @@ class Media extends MediaLibraryModel protected $table = 'media'; + const COLLECTION_SLIDESHOW = 'images_slideshow'; + /** * The attributes that are mass assignable. * @@ -119,6 +121,17 @@ public static function rules($existing = null) 'model_id', ]; + public function determineCollectionName(Process $process, $name) + { + // In order to differentiate them from other process-related images ['launchpad', 'slideshow'] + if ($name === 'launchpad') { + return $process->uuid . '_' . 'images_carousel'; + } elseif ($name === 'slideshow') { + return self::COLLECTION_SLIDESHOW; + } + return null; + } + /** * Override the default boot method to allow access to lifecycle hooks * @@ -184,10 +197,11 @@ public function getManagerUrlAttribute() * @param Process $process * @param array $properties * @param string $key + * @param string $mediaType * * @return void */ - public function saveProcessMedia(Process $process, $properties, $key = 'uuid') + public function saveProcessMedia(Process $process, $properties, $key = 'uuid', $mediaType = 'launchpad') { // Validate if the image smaller than 2MB $maxFileSize = 2 * 1024 * 1024; @@ -200,13 +214,18 @@ public function saveProcessMedia(Process $process, $properties, $key = 'uuid') if ($mediaCount > 4) { return; } - // Get information to save - $collectionName = $process->uuid . '_images_carousel'; + // Get collection name to save + $collectionName = self::determineCollectionName($process, $mediaType); + // Check if exist $exist = $process->media()->where($key, $properties[$key])->exists(); if (!$exist) { // Store the images related move to MEDIA $process->addMediaFromBase64($properties['url']) - ->withCustomProperties(['type' => $properties['type']]) + ->withCustomProperties([ + 'media_type' => $mediaType, + 'type' => $properties['type'], + 'node_id' => $properties['node_id'], + ]) ->toMediaCollection($collectionName); } }