From 4e56f02e22b41d763355c673e4bf8115be87832f Mon Sep 17 00:00:00 2001 From: christophboecker Date: Wed, 21 Aug 2024 17:28:04 +0200 Subject: [PATCH 1/6] API und Cronjobs mit RexStan bearbeitet --- lang/da_da.lang | 4 ++-- lang/de_de.lang | 4 ++-- lang/el_el.lang | 4 ++-- lang/en_gb.lang | 4 ++-- lang/es_es.lang | 4 ++-- lang/fi_fi.lang | 4 ++-- lang/fr_fr.lang | 4 ++-- lang/it_it.lang | 4 ++-- lang/nl_nl.lang | 4 ++-- lang/no_no.lang | 4 ++-- lang/pl_pl.lang | 4 ++-- lang/ro_ro.lang | 4 ++-- lang/sv_se.lang | 4 ++-- lang/tr_tr.lang | 4 ++-- lang/uk_uk.lang | 4 ++-- lib/Api/Restful.php | 22 +++++++++++----------- lib/Api/Rss.php | 13 ++++++++----- lib/Cronjob/Publish.php | 3 +++ lib/Cronjob/Sync.php | 25 +++++++++++++++++++------ 19 files changed, 71 insertions(+), 52 deletions(-) diff --git a/lang/da_da.lang b/lang/da_da.lang index af1404f..587d874 100644 --- a/lang/da_da.lang +++ b/lang/da_da.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s indlæg er blevet offentliggjort med succes. -neues_entry_publish_error = %s indlæg kunne ikke offentliggøres. +neues_entry_publish_success = %d indlæg er blevet offentliggjort med succes. +neues_entry_publish_error = %d indlæg kunne ikke offentliggøres. neues_entry_publish_cronjob = Offentliggør planlagte indlæg. (Aktuelt) diff --git a/lang/de_de.lang b/lang/de_de.lang index dfcff3d..5194572 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -100,8 +100,8 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s Beiträge wurden erfolgreich veröffentlicht. -neues_entry_publish_error = %s Beiträge konnten nicht veröffentlicht werden. +neues_entry_publish_success = %d Beiträge wurden erfolgreich veröffentlicht. +neues_entry_publish_error = %d Beiträge konnten nicht veröffentlicht werden. neues_entry_publish_cronjob = Geplante Beiträge veröffentlichen. (Aktuelles) neues_entry_sync_error = Fehler beim Synchronisieren der Beiträge. diff --git a/lang/el_el.lang b/lang/el_el.lang index 5f21a60..bdb673b 100644 --- a/lang/el_el.lang +++ b/lang/el_el.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s Καταχωρήσεις δημοσιεύτηκαν επιτυχώς. -neues_entry_publish_error = %s Καταχωρήσεις δεν μπόρεσαν να δημοσιευτούν. +neues_entry_publish_success = %d Καταχωρήσεις δημοσιεύτηκαν επιτυχώς. +neues_entry_publish_error = %d Καταχωρήσεις δεν μπόρεσαν να δημοσιευτούν. neues_entry_publish_cronjob = Δημοσίευση προγραμματισμένων καταχωρήσεων. (Νέα) diff --git a/lang/en_gb.lang b/lang/en_gb.lang index f4d02ec..491c9f9 100644 --- a/lang/en_gb.lang +++ b/lang/en_gb.lang @@ -91,6 +91,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s posts have been successfully published. -neues_entry_publish_error = %s posts could not be published. +neues_entry_publish_success = %d posts have been successfully published. +neues_entry_publish_error = %d posts could not be published. neues_entry_publish_cronjob = Publish planned posts. (Current) diff --git a/lang/es_es.lang b/lang/es_es.lang index b762028..e05a00a 100644 --- a/lang/es_es.lang +++ b/lang/es_es.lang @@ -90,6 +90,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s entradas se han publicado con éxito. -neues_entry_publish_error = %s entradas no se pudieron publicar. +neues_entry_publish_success = %d entradas se han publicado con éxito. +neues_entry_publish_error = %d entradas no se pudieron publicar. neues_entry_publish_cronjob = Publicar entradas planificadas. (Actual) diff --git a/lang/fi_fi.lang b/lang/fi_fi.lang index 19db27e..4845413 100644 --- a/lang/fi_fi.lang +++ b/lang/fi_fi.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s artikkelia on julkaistu onnistuneesti. -neues_entry_publish_error = %s artikkelia ei voitu julkaista. +neues_entry_publish_success = %d artikkelia on julkaistu onnistuneesti. +neues_entry_publish_error = %d artikkelia ei voitu julkaista. neues_entry_publish_cronjob = Julkaise suunnitellut artikkelit. (Uutiset) diff --git a/lang/fr_fr.lang b/lang/fr_fr.lang index 51f1029..9c9537f 100644 --- a/lang/fr_fr.lang +++ b/lang/fr_fr.lang @@ -91,6 +91,6 @@ neues_docs_restful_api = API RESTful YForm # Cronjob -neues_entry_publish_success = %s articles ont été publiés avec succès. -neues_entry_publish_error = %s articles n'ont pas pu être publiés. +neues_entry_publish_success = %d articles ont été publiés avec succès. +neues_entry_publish_error = %d articles n'ont pas pu être publiés. neues_entry_publish_cronjob = Publier des articles planifiés. (Actuel) diff --git a/lang/it_it.lang b/lang/it_it.lang index 2fc7ba4..79e1092 100644 --- a/lang/it_it.lang +++ b/lang/it_it.lang @@ -91,6 +91,6 @@ neues_docs_restful_api = YForm API RESTful # Cronjob -neues_entry_publish_success = %s articoli sono stati pubblicati con successo. -neues_entry_publish_error = %s articoli non sono stati pubblicati. +neues_entry_publish_success = %d articoli sono stati pubblicati con successo. +neues_entry_publish_error = %d articoli non sono stati pubblicati. neues_entry_publish_cronjob = Pubblica articoli pianificati. (Corrente) diff --git a/lang/nl_nl.lang b/lang/nl_nl.lang index daba4f9..085963e 100644 --- a/lang/nl_nl.lang +++ b/lang/nl_nl.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s berichten zijn succesvol gepubliceerd. -neues_entry_publish_error = %s berichten konden niet worden gepubliceerd. +neues_entry_publish_success = %d berichten zijn succesvol gepubliceerd. +neues_entry_publish_error = %d berichten konden niet worden gepubliceerd. neues_entry_publish_cronjob = Geplande berichten publiceren. (Nieuws) diff --git a/lang/no_no.lang b/lang/no_no.lang index c40494a..fabcfbf 100644 --- a/lang/no_no.lang +++ b/lang/no_no.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s innlegg har blitt publisert. -neues_entry_publish_error = %s innlegg kunne ikke publiseres. +neues_entry_publish_success = %d innlegg har blitt publisert. +neues_entry_publish_error = %d innlegg kunne ikke publiseres. neues_entry_publish_cronjob = Publiser planlagte innlegg. (Aktuelt) diff --git a/lang/pl_pl.lang b/lang/pl_pl.lang index c107c12..955ea2d 100644 --- a/lang/pl_pl.lang +++ b/lang/pl_pl.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s wpisów zostało pomyślnie opublikowanych. -neues_entry_publish_error = %s wpisów nie udało się opublikować. +neues_entry_publish_success = %d wpisów zostało pomyślnie opublikowanych. +neues_entry_publish_error = %d wpisów nie udało się opublikować. neues_entry_publish_cronjob = Publikowanie zaplanowanych wpisów. (Aktualności) diff --git a/lang/ro_ro.lang b/lang/ro_ro.lang index 2802e1b..74d603d 100644 --- a/lang/ro_ro.lang +++ b/lang/ro_ro.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s articole au fost publicate cu succes. -neues_entry_publish_error = %s articole nu au putut fi publicate. +neues_entry_publish_success = %d articole au fost publicate cu succes. +neues_entry_publish_error = %d articole nu au putut fi publicate. neues_entry_publish_cronjob = Publică articolele planificate. (Noutăți) diff --git a/lang/sv_se.lang b/lang/sv_se.lang index d89a151..e812190 100644 --- a/lang/sv_se.lang +++ b/lang/sv_se.lang @@ -90,6 +90,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s inlägg har publicerats framgångsrikt. -neues_entry_publish_error = %s inlägg kunde inte publiceras. +neues_entry_publish_success = %d inlägg har publicerats framgångsrikt. +neues_entry_publish_error = %d inlägg kunde inte publiceras. neues_entry_publish_cronjob = Publicera planerade inlägg. diff --git a/lang/tr_tr.lang b/lang/tr_tr.lang index 86f69a8..9811f19 100644 --- a/lang/tr_tr.lang +++ b/lang/tr_tr.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s giriş başarıyla yayınlandı. -neues_entry_publish_error = %s giriş yayınlanamadı. +neues_entry_publish_success = %d giriş başarıyla yayınlandı. +neues_entry_publish_error = %d giriş yayınlanamadı. neues_entry_publish_cronjob = Planlanan girişleri yayınla. (Yeni) diff --git a/lang/uk_uk.lang b/lang/uk_uk.lang index 65f92e7..f28dbb6 100644 --- a/lang/uk_uk.lang +++ b/lang/uk_uk.lang @@ -93,6 +93,6 @@ neues_docs_restful_api = YForm RESTful API # Cronjob -neues_entry_publish_success = %s записів було успішно опубліковано. -neues_entry_publish_error = %s записів не вдалося опублікувати. +neues_entry_publish_success = %d записів було успішно опубліковано. +neues_entry_publish_error = %d записів не вдалося опублікувати. neues_entry_publish_cronjob = Опублікувати заплановані записи. (Новини) diff --git a/lib/Api/Restful.php b/lib/Api/Restful.php index b25f0cc..84d127f 100644 --- a/lib/Api/Restful.php +++ b/lib/Api/Restful.php @@ -20,7 +20,7 @@ public static function init(): void 'query' => Entry::query(), 'get' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Entry' => [ + Entry::class => [ 'id', 'status', 'name', @@ -40,7 +40,7 @@ public static function init(): void 'updateuser', 'uuid', ], - 'FriendsOfRedaxo\Neues\Category' => [ + Category::class => [ 'id', 'name', 'image', @@ -51,7 +51,7 @@ public static function init(): void 'updateuser', 'uuid', ], - 'FriendsOfRedaxo\Neues\Author' => [ + Author::class => [ 'id', 'name', 'nickname', @@ -68,7 +68,7 @@ public static function init(): void ], 'post' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Entry' => [ + Entry::class => [ 'status', 'name', 'teaser', @@ -89,7 +89,7 @@ public static function init(): void ], 'delete' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Entry' => [ + Entry::class => [ 'id', ], ], @@ -108,7 +108,7 @@ public static function init(): void 'query' => Category::query(), 'get' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Category' => [ + Category::class => [ 'id', 'name', 'image', @@ -123,7 +123,7 @@ public static function init(): void ], 'post' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Category' => [ + Category::class => [ 'name', 'image', 'status', @@ -133,7 +133,7 @@ public static function init(): void ], 'delete' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Category' => [ + Category::class => [ 'id', ], ], @@ -152,7 +152,7 @@ public static function init(): void 'query' => Author::query(), 'get' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Author' => [ + Author::class => [ 'id', 'name', 'nickname', @@ -169,7 +169,7 @@ public static function init(): void ], 'post' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Author' => [ + Author::class => [ 'name', 'nickname', 'text', @@ -180,7 +180,7 @@ public static function init(): void ], 'delete' => [ 'fields' => [ - 'FriendsOfRedaxo\Neues\Author' => [ + Author::class => [ 'id', ], ], diff --git a/lib/Api/Rss.php b/lib/Api/Rss.php index be62c63..19d9846 100644 --- a/lib/Api/Rss.php +++ b/lib/Api/Rss.php @@ -28,14 +28,19 @@ public function execute(): rex_api_result $lang_id = rex_request('lang_id', 'int', null); $category_id = rex_request('category_id', 'int', null); - if ($category_id && $category = Category::get($category_id)) { + $category = null; + if(null !== $category_id) { + $category = Category::get($category_id); + } + + if (null !== $category) { $collection = Entry::findOnline($category_id); $filename = 'rss.neues.' . rex_string::normalize($category->getName()) . '.xml'; $description = 'RSS-FEED: ' . rex::getServerName() . ' | ' . rex_escape($category->getName()); } else { $collection = Entry::findOnline(); - $description = 'RSS-FEED: ' . rex::getServerName(); $filename = 'rss.neues.xml'; + $description = 'RSS-FEED: ' . rex::getServerName(); } rex_response::cleanOutputBuffers(); @@ -80,9 +85,7 @@ public static function createRssFeed(rex_yform_manager_collection $collection, $ $channel->addChild('description', $description); $channel->addChild('link', rex::getServer()); - // RexStan: Only booleans are allowed in &&, int given on the left side. - // TODO: klären was der Teil `$lang &&` bewirken soll und ggf. rauswerfen - if ($lang && $lang > 0) { + if ($lang > 0) { $channel->addChild('language', rex_clang::get($lang)->getCode()); } diff --git a/lib/Cronjob/Publish.php b/lib/Cronjob/Publish.php index 474bf7f..9946845 100644 --- a/lib/Cronjob/Publish.php +++ b/lib/Cronjob/Publish.php @@ -10,6 +10,9 @@ class Publish extends rex_cronjob { + /** + * @return bool + */ public function execute() { /* Collection von Neues-Einträgen, die noch nicht veröffentlicht sind, aber es sein sollten. (geplant) */ diff --git a/lib/Cronjob/Sync.php b/lib/Cronjob/Sync.php index cb1798c..ef8b76a 100644 --- a/lib/Cronjob/Sync.php +++ b/lib/Cronjob/Sync.php @@ -8,7 +8,6 @@ use rex_cronjob; use rex_i18n; use rex_socket; -use rex_socket_response; class Sync extends rex_cronjob { @@ -17,21 +16,28 @@ class Sync extends rex_cronjob 'author' => '/rest/neues/author/5.0.0/', 'entry' => '/rest/neues/entry/5.0.0/']; + /** + * @return bool + */ public function execute() { $data = []; - foreach ($this->rest_urls as $type => $url) { - $url = $this->getParam('url') . $url; - $token = $this->getParam('token'); - $status = $this->getParam('status'); + $baseUrl = $this->getParam('url'); + $token = $this->getParam('token'); + $status = $this->getParam('status'); + foreach ($this->rest_urls as $type => $url) { + $url = $baseUrl . $url; $socket = rex_socket::factoryUrl($url); $socket->addHeader('token', $token); - /** @var rex_socket_response $response */ $response = $socket->doGet(); if (!$response->isOk()) { + /** + * REVIEW: in 'neues_entry_sync_error' ist kein Platzhalter für den Code. Code überflüssig? + * TODO: reicht auch $this->setMessage(rex_i18n::msg('neues_entry_sync_error') ?? + */ $this->setMessage(sprintf(rex_i18n::msg('neues_entry_sync_error'), $response->getStatusCode())); return false; } @@ -106,6 +112,13 @@ public function execute() $neues_entry->setValue('updatedate', $entry['updatedate']); $neues_entry->save(); } + + /** + * REVIEW: Ist hier der letzte Status-Code wirklich erforderlich? Es wäre eh nur der der letzten Abfrage + * FIXME: Der Eintrag 'neues_entry_sync_success' kommt in den .lang-Dateien nicht vor. + * REXSTAN: Variable $response might not be defined. + * -> unwahrscheinlich, da es fix drei $data-Einträge gibt. Dennoch .... + */ $this->setMessage(sprintf(rex_i18n::msg('neues_entry_sync_success'), $response->getStatusCode())); return true; } From 0537f3e4d0589581bf65197ade62c351665806f7 Mon Sep 17 00:00:00 2001 From: christophboecker Date: Wed, 21 Aug 2024 15:49:04 +0000 Subject: [PATCH 2/6] Apply php-cs-fixer changes --- lib/Api/Rss.php | 2 +- lib/Cronjob/Sync.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Api/Rss.php b/lib/Api/Rss.php index 19d9846..e1eaf20 100644 --- a/lib/Api/Rss.php +++ b/lib/Api/Rss.php @@ -29,7 +29,7 @@ public function execute(): rex_api_result $category_id = rex_request('category_id', 'int', null); $category = null; - if(null !== $category_id) { + if (null !== $category_id) { $category = Category::get($category_id); } diff --git a/lib/Cronjob/Sync.php b/lib/Cronjob/Sync.php index ef8b76a..cf191e8 100644 --- a/lib/Cronjob/Sync.php +++ b/lib/Cronjob/Sync.php @@ -17,7 +17,7 @@ class Sync extends rex_cronjob 'entry' => '/rest/neues/entry/5.0.0/']; /** - * @return bool + * @return bool */ public function execute() { From e7d2622763f5ba205623001f8e9f37bd76c86a4e Mon Sep 17 00:00:00 2001 From: christophboecker Date: Thu, 22 Aug 2024 14:03:12 +0200 Subject: [PATCH 3/6] $domain mit Typ "string" --- lib/Api/Rss.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Api/Rss.php b/lib/Api/Rss.php index e1eaf20..36ffd5a 100644 --- a/lib/Api/Rss.php +++ b/lib/Api/Rss.php @@ -54,10 +54,8 @@ public function execute(): rex_api_result /** * @param rex_yform_manager_collection $collection * @api - * - * TODO: Parameter Domain wird nicht benutzt: Klären ob der weg kann. Type fehlt */ - public static function getRssFeed($collection, $domain, int $lang, string $description, string $filename): string|bool + public static function getRssFeed(rex_yform_manager_collection $collection, string $domain, int $lang, string $description, string $filename): string|bool { return self::createRssFeed($collection, $domain, $lang, $description, $filename); } @@ -73,10 +71,8 @@ public static function joinUrls(string $url1, string $url2): string /** * @param rex_yform_manager_collection $collection * @api - * - * TODO: Parameter Domain wird nicht benutzt: Klären ob der weg kann. Type fehlt */ - public static function createRssFeed(rex_yform_manager_collection $collection, $domain, int $lang, string $description, string $filename = 'rss.neues.xml'): string|bool + public static function createRssFeed(rex_yform_manager_collection $collection, string $domain, int $lang, string $description, string $filename = 'rss.neues.xml'): string|bool { $xml = new SimpleXMLElement(''); From 6220f0df8e8f95998f6bf4079a7ae78c30c31c2c Mon Sep 17 00:00:00 2001 From: christophboecker Date: Thu, 22 Aug 2024 15:20:37 +0200 Subject: [PATCH 4/6] Update lib/Api/Rss.php Co-authored-by: Alexander Walther --- lib/Api/Rss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Api/Rss.php b/lib/Api/Rss.php index 36ffd5a..ae3987e 100644 --- a/lib/Api/Rss.php +++ b/lib/Api/Rss.php @@ -72,7 +72,7 @@ public static function joinUrls(string $url1, string $url2): string * @param rex_yform_manager_collection $collection * @api */ - public static function createRssFeed(rex_yform_manager_collection $collection, string $domain, int $lang, string $description, string $filename = 'rss.neues.xml'): string|bool + public static function createRssFeed(rex_yform_manager_collection $collection, int $domain_id, int $lang, string $description, string $filename = 'rss.neues.xml'): string|bool { $xml = new SimpleXMLElement(''); From 2bae419b492965aff19862c612da5905bd780bb3 Mon Sep 17 00:00:00 2001 From: christophboecker Date: Thu, 22 Aug 2024 15:20:50 +0200 Subject: [PATCH 5/6] Update lib/Api/Rss.php Co-authored-by: Alexander Walther --- lib/Api/Rss.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Api/Rss.php b/lib/Api/Rss.php index ae3987e..28abc59 100644 --- a/lib/Api/Rss.php +++ b/lib/Api/Rss.php @@ -55,7 +55,7 @@ public function execute(): rex_api_result * @param rex_yform_manager_collection $collection * @api */ - public static function getRssFeed(rex_yform_manager_collection $collection, string $domain, int $lang, string $description, string $filename): string|bool + public static function getRssFeed(rex_yform_manager_collection $collection, int $domain_id, int $lang, string $description, string $filename): string|bool { return self::createRssFeed($collection, $domain, $lang, $description, $filename); } From 8cd579f907ea3672e4a5324fdb1f702fdc3a37b3 Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Thu, 22 Aug 2024 15:26:10 +0200 Subject: [PATCH 6/6] Update lib/Cronjob/Sync.php --- lib/Cronjob/Sync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cronjob/Sync.php b/lib/Cronjob/Sync.php index cf191e8..3e53350 100644 --- a/lib/Cronjob/Sync.php +++ b/lib/Cronjob/Sync.php @@ -35,7 +35,7 @@ public function execute() if (!$response->isOk()) { /** - * REVIEW: in 'neues_entry_sync_error' ist kein Platzhalter für den Code. Code überflüssig? + * TODO: in 'neues_entry_sync_error' Platzhalter für den Code. einfügen. * TODO: reicht auch $this->setMessage(rex_i18n::msg('neues_entry_sync_error') ?? */ $this->setMessage(sprintf(rex_i18n::msg('neues_entry_sync_error'), $response->getStatusCode()));