Skip to content

Commit b57bfe3

Browse files
committed
refactor: Change diffusion_sql::map_media to use get_url method instead of files_info data. Is more compatible with actual media diffusion value.
1 parent 1e15f73 commit b57bfe3

2 files changed

Lines changed: 21 additions & 54 deletions

File tree

core/diffusion/class.diffusion_sql.php

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,19 +4084,7 @@ public static function map_media(object $options, $dato) : ?string {
40844084
return null;
40854085
}
40864086

4087-
// process options. Expected an object as {"quality": "original"}
4088-
$process_options = $options->properties->options ?? null;
4089-
// Empty options. Stop processing
4090-
if (empty($process_options)) {
4091-
return null;
4092-
}
4093-
4094-
// transformations
4095-
$file_path = null;
4096-
4097-
// component. Create a component to get the correct defaults
40984087
try {
4099-
41004088
$tipo = $options->component->tipo;
41014089
$model = RecordObj_dd::get_modelo_name_by_tipo($tipo,true);
41024090
$component = component_common::get_instance(
@@ -4107,54 +4095,35 @@ public static function map_media(object $options, $dato) : ?string {
41074095
DEDALO_DATA_NOLAN, // string lang
41084096
$options->component->section_tipo // string section_tipo
41094097
);
4110-
4111-
$default_quality = $component->get_default_quality();
4112-
$default_extension = $component->get_extension();
4113-
41144098
} catch (Exception $e) {
41154099
debug_log(__METHOD__
4116-
. " Error on resolve custom path " . PHP_EOL
4100+
. " Error on load component " . PHP_EOL
41174101
. ' exception: ' . $e->getMessage() . PHP_EOL
41184102
. ' options : ' . json_encode($options, JSON_PRETTY_PRINT)
41194103
, logger::DEBUG
41204104
);
41214105
return null;
41224106
}
41234107

4124-
// 1 - Quality/extension. Filters available files by quality and extension
4125-
// Sample to get '/image/original/0/rsc37_rsc176_1.jpg' from '/image/1.5MB/0/rsc37_rsc176_1.jpg'
4126-
// {
4127-
// "process_dato": "diffusion_sql::map_media",
4128-
// "options": {
4129-
// "quality": "original",
4130-
// "extension": "jpg"
4131-
// }
4132-
// }
4133-
// }
4134-
// select desired quality for the list if available
4135-
$found = array_find((array)$files_info, function($el) use ($process_options, $default_quality, $default_extension){
4136-
4137-
return $el->quality === ($process_options->quality ?? $default_quality) &&
4138-
strtolower($el->extension) === strtolower($process_options->extension ?? $default_extension);
4139-
});
4140-
if (empty($found) || empty($found->file_path)) {
4141-
// quality do not exists
4142-
return null;
4108+
// process options. Expected an object as {"quality": "original"}
4109+
$process_options = $options->properties->options ?? null;
4110+
// Empty options. Stop processing
4111+
if (empty($process_options)) {
4112+
return $component->get_diffusion_value();
41434113
}
4144-
$file_path = $found->file_path;
41454114

4146-
// 2 - Replace. Replaces file path string using PHP regex replacements.
4147-
// Sample to get 'rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg'
4148-
// {
4149-
// "process_dato": "diffusion_sql::map_media",
4150-
// "options": {
4151-
// "replace": {
4152-
// "regex": "~.*/~",
4153-
// "substitution": ""
4154-
// }
4155-
// }
4156-
// }
4157-
// replace (regex). Use delimiters '~' as ~.*/~
4115+
// transformations
4116+
$file_path = null;
4117+
4118+
// component. Create a component to get the correct defaults
4119+
$quality = $process_options->quality ?? $component->get_default_quality();
4120+
$extension = $process_options->extension ?? $component->get_extension();
4121+
4122+
// 1 - Quality/Extension. Builds the URL based on given quality and extension when provided.
4123+
$component->set_extension($extension);
4124+
$file_path = $component->get_url($quality);
4125+
4126+
// 2 - Replace (regex). Use delimiters '~' as ~.*/~
41584127
if (isset($process_options->replace)) {
41594128
try {
41604129
$file_path = preg_replace(
@@ -4172,7 +4141,7 @@ public static function map_media(object $options, $dato) : ?string {
41724141
}
41734142
}
41744143

4175-
// 3 - prefix. Prepends a string to the file path
4144+
// 3 - Prefix. Prepends a string to the file path
41764145
// Sample to get 'http://dedalo.dev/media/rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg'
41774146
// {
41784147
// "process_dato": "diffusion_sql::map_media",

docs/diffusion/diffusion_config_properties.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Split date range
242242

243243
Map media files path
244244
>Process the media file path of the component to perform regex, select custom quality, prepend a domain, etc.
245-
>Please note that the processing is cumulative and the order is as follows: quality, extension, replace, prefix.
245+
>Please note that the processing is cumulative and the order is as follows: quality/extension, replace, prefix.
246246
>
247247
##### direct
248248

@@ -272,7 +272,7 @@ Map media files path
272272
#### replace
273273
>
274274
>Perform a regular expression replacement on the file path. Use '~' as delimiters as '\~.*/\~'.
275-
Sample:
275+
Sample: (replacement to get 'rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg')
276276

277277
```json
278278
{
@@ -283,8 +283,6 @@ Sample:
283283
}
284284
```
285285

286-
Replacement to get 'rsc37_rsc176_1.jpg' from '/pdf/original/0/rsc37_rsc176_1.jpg'
287-
288286
#### prefix
289287
>
290288
>Prepends the value to the file path as '<http://domain.org/media/>' + 'file_path.jpg'.

0 commit comments

Comments
 (0)