Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions ProcessMaker/ImportExport/Exporters/ProcessExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,6 @@ public function export() : void
$this->exportSubprocesses();
$this->exportProcessLaunchpad();
$this->exportMedia();

$this->exportEmbed();
}

Expand Down Expand Up @@ -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);
});
}
Expand Down
27 changes: 23 additions & 4 deletions ProcessMaker/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Media extends MediaLibraryModel

protected $table = 'media';

const COLLECTION_SLIDESHOW = 'images_slideshow';

/**
* The attributes that are mass assignable.
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down