Skip to content

Commit cf7af7b

Browse files
authored
Merge pull request #152 from FriendsOfREDAXO/copilot/fix-121
Add optional media prefix setting to sync cronjob
2 parents e47d4a9 + 7cc50fc commit cf7af7b

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

lang/de_de.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ neues_entry_sync_cronjob_neues_category_id = Standard-Kategorie
119119
neues_entry_sync_cronjob_neues_author_id = Standard-Autor
120120
neues_entry_sync_cronjob_media_category_id = Import in Medienpool-Kategorie
121121
neues_entry_sync_cronjob_x_per_page = Anzahl der letzten Beiträge
122+
neues_entry_sync_cronjob_media_prefix = Medien mit Präfix
122123
neues_entry_sync_cronjob_success = %s Beiträge wurden erfolgreich synchronisiert (Erstellt: %s, aktualisiert %s).

lang/en_gb.lang

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,15 @@ neues_docs_restful_api = YForm RESTful API
9898
neues_entry_publish_success = %d posts have been successfully published.
9999
neues_entry_publish_error = %d posts could not be published.
100100
neues_entry_publish_cronjob = Publish planned posts. (Current)
101+
102+
neues_entry_sync_error = Error synchronizing posts.
103+
neues_entry_sync_cronjob = [📰 News] Retrieve posts, categories and authors from another REDAXO installation
104+
neues_entry_sync_cronjob_url = URL of the REDAXO installation
105+
neues_entry_sync_cronjob_token = RESTful API token
106+
neues_entry_sync_cronjob_status = Status value
107+
neues_entry_sync_cronjob_neues_category_id = Default category
108+
neues_entry_sync_cronjob_neues_author_id = Default author
109+
neues_entry_sync_cronjob_media_category_id = Import to media pool category
110+
neues_entry_sync_cronjob_x_per_page = Number of recent posts
111+
neues_entry_sync_cronjob_media_prefix = Media with prefix
112+
neues_entry_sync_cronjob_success = %s posts were successfully synchronized (Created: %s, updated %s).

lib/Cronjob/Sync.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ public function createEntry(array $current): void
108108

109109
/* Titelbild abrufen und speichern */
110110
$updated_image = '';
111-
$targetname = $entry_data['uuid'] . '_' . $entry_data['image'];
112-
if ($this->createMedia($entry_data['image'])) {
111+
$prefix = $this->getParam('media_prefix') ? $entry_data['uuid'] . '_' : '';
112+
$targetname = $prefix . $entry_data['image'];
113+
if ($this->createMedia($entry_data['image'], $prefix)) {
113114
$updated_image = $targetname;
114115
}
115116
$entry->setValue('image', $updated_image);
@@ -119,8 +120,8 @@ public function createEntry(array $current): void
119120
$images = array_filter(explode(',', $entry_data['images']));
120121
$updated_images = [];
121122
foreach ($images as $image) {
122-
$targetname = $entry_data['uuid'] . '_' . $image;
123-
if ($this->createMedia($image, $targetname)) {
123+
$targetname = $prefix . $image;
124+
if ($this->createMedia($image, $prefix)) {
124125
$updated_images[] = $targetname;
125126
}
126127
}
@@ -187,9 +188,9 @@ public function createAuthor(array $current): Author
187188
return $author;
188189
}
189190

190-
public function createMedia(string $filename, ?string $prefix = null): bool
191+
public function createMedia(string $filename, string $prefix = ''): bool
191192
{
192-
$targetname = rex_string::normalize($prefix) . $filename;
193+
$targetname = rex_string::normalize($prefix . $filename);
193194
if ('' === $filename) {
194195
return false;
195196
}
@@ -281,6 +282,15 @@ public function getParamFields()
281282
'type' => 'text',
282283
'attributes' => ['type' => 'number', 'min' => 1],
283284
],
285+
[
286+
'name' => 'media_prefix',
287+
'label' => rex_i18n::msg('neues_entry_sync_cronjob_media_prefix'),
288+
'type' => 'select',
289+
'options' => [
290+
'1' => rex_i18n::msg('neues_entry_sync_cronjob_media_prefix_yes'),
291+
'0' => rex_i18n::msg('neues_entry_sync_cronjob_media_prefix_no'),
292+
],
293+
],
284294
];
285295

286296
return $fields;

0 commit comments

Comments
 (0)