From 31d42976043514041719fc923d1e19dd58bdb3be Mon Sep 17 00:00:00 2001 From: XavierGR Date: Thu, 14 Nov 2024 09:06:41 +0100 Subject: [PATCH 1/4] =?UTF-8?q?N=C2=B07726=20-=20Fatal=20error=20if=20a=20?= =?UTF-8?q?newsroom=20is=20sent=20without=20any=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/datamodel.core.xml | 6 ++++++ dictionaries/cs.dictionary.itop.core.php | 2 ++ dictionaries/da.dictionary.itop.core.php | 2 ++ dictionaries/de.dictionary.itop.core.php | 2 ++ dictionaries/en.dictionary.itop.core.php | 2 ++ dictionaries/es_cr.dictionary.itop.core.php | 2 ++ dictionaries/fr.dictionary.itop.core.php | 2 ++ dictionaries/hu.dictionary.itop.core.php | 2 ++ dictionaries/it.dictionary.itop.core.php | 2 ++ dictionaries/ja.dictionary.itop.core.php | 2 ++ dictionaries/nl.dictionary.itop.core.php | 2 ++ dictionaries/pl.dictionary.itop.core.php | 2 ++ dictionaries/pt_br.dictionary.itop.core.php | 2 ++ dictionaries/ru.dictionary.itop.core.php | 2 ++ dictionaries/sk.dictionary.itop.core.php | 2 ++ dictionaries/tr.dictionary.itop.core.php | 2 ++ dictionaries/zh_cn.dictionary.itop.core.php | 2 ++ 17 files changed, 38 insertions(+) diff --git a/core/datamodel.core.xml b/core/datamodel.core.xml index f993679045..bea18700ce 100644 --- a/core/datamodel.core.xml +++ b/core/datamodel.core.xml @@ -360,7 +360,13 @@ } else { foreach ($aRecipientsIds as $iRecipientId) { $oEvent = Combodo\iTop\Service\Notification\Event\EventNotificationNewsroomService::MakeEventFromAction($this, $iRecipientId, $oTrigger->GetKey(), $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass); + try { $oEvent->DBInsertNoReload(); + } catch(CoreCannotSaveObjectException $e) { + ExceptionLog::LogException($e); + $oEvent = Combodo\iTop\Service\Notification\Event\EventNotificationNewsroomService::MakeEventFromAction($this, $iRecipientId, $oTrigger->GetKey(), Dict::Format('Core:EventNotificationNewsroom:ErrorOnDBInsert'), Dict::Format('Core:EventNotificationNewsroom:ErrorNotificationNotSent'), $sUrl, $iObjectId, $sObjectClass); + $oEvent->DBInsertNoReload(); + } } } diff --git a/dictionaries/cs.dictionary.itop.core.php b/dictionaries/cs.dictionary.itop.core.php index 3e95c1cc43..c43f4d475f 100755 --- a/dictionaries/cs.dictionary.itop.core.php +++ b/dictionaries/cs.dictionary.itop.core.php @@ -807,6 +807,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Chybní příkaz, nebo příkaz skončil s chybou (např chybný název skriptu)', 'Core:ExecProcess:Code255' => 'PHP Error (parsing/runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Uplynulý čas ("%1$s")', diff --git a/dictionaries/da.dictionary.itop.core.php b/dictionaries/da.dictionary.itop.core.php index dc26d990f6..185db25be9 100644 --- a/dictionaries/da.dictionary.itop.core.php +++ b/dictionaries/da.dictionary.itop.core.php @@ -806,6 +806,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Forkert kommando eller kommandoen afsluttede med fejl (f.eks. forkert script navn)', 'Core:ExecProcess:Code255' => 'PHP Error (parsing, or runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Time elapsed (stored as "%1$s")~~', diff --git a/dictionaries/de.dictionary.itop.core.php b/dictionaries/de.dictionary.itop.core.php index fa214dfd37..1dd0b2f68a 100644 --- a/dictionaries/de.dictionary.itop.core.php +++ b/dictionaries/de.dictionary.itop.core.php @@ -808,6 +808,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Falscher Befehl oder Befehl mit Fehler beendet (z.B. falscher Skriptname).', 'Core:ExecProcess:Code255' => 'PHP-Fehler (Parsing oder Laufzeit)', 'Core:ExplainWTC:ElapsedTime' => 'Abgelaufene Zeit (gespeichert als \"%1$s\")', diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 8bca06e4a6..ea41deadb1 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -514,6 +514,8 @@ 'Class:EventNotificationNewsroom/Attribute:read_date+' => '', 'Class:EventNotificationNewsroom/Attribute:contact_id' => 'Contact', 'Class:EventNotificationNewsroom/Attribute:contact_id+' => '', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification', )); // diff --git a/dictionaries/es_cr.dictionary.itop.core.php b/dictionaries/es_cr.dictionary.itop.core.php index 16f7273ab7..4450cdfc98 100644 --- a/dictionaries/es_cr.dictionary.itop.core.php +++ b/dictionaries/es_cr.dictionary.itop.core.php @@ -792,6 +792,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Comando equivocado o comando terminó con errores (ejem. nombre incorrecto de script)', 'Core:ExecProcess:Code255' => 'PHP Error (parsing, or runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Tiempo transcurrido (almacenado como \"%1$s\")', diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index e45f7f39e2..80e61b61ee 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -835,6 +835,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification non envoyée', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'Une erreur est survenue lors de l\'envoi de la notification', 'Core:ExecProcess:Code1' => 'Mauvaise commande ou commande se finissant avec des erreurs (e.g. mauvais nom de script)', 'Core:ExecProcess:Code255' => 'Erreur PHP (analyse de fichier, ou exécution)', 'Core:ExplainWTC:ElapsedTime' => 'Temps écoulé (enregistré dans "%1$s")', diff --git a/dictionaries/hu.dictionary.itop.core.php b/dictionaries/hu.dictionary.itop.core.php index 0f13da3f24..2c297c8b76 100755 --- a/dictionaries/hu.dictionary.itop.core.php +++ b/dictionaries/hu.dictionary.itop.core.php @@ -801,6 +801,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$d óra %2$d perc %3$d mp', 'Core:Duration_Minutes_Seconds' => '%1$d perc %2$d mp', 'Core:Duration_Seconds' => '%1$d mp', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Helytelen parancs vagy hibásan befejezett parancs (pl. helytelen szkriptnév)', 'Core:ExecProcess:Code255' => 'PHP hiba (parsing, vagy runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Eltelt idő (tárolva mint %1$s)', diff --git a/dictionaries/it.dictionary.itop.core.php b/dictionaries/it.dictionary.itop.core.php index a8c358f3d9..aaa3ba74a9 100644 --- a/dictionaries/it.dictionary.itop.core.php +++ b/dictionaries/it.dictionary.itop.core.php @@ -802,6 +802,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$sec', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Comando errato o comando finito con errori (es. errato nome dello script)', 'Core:ExecProcess:Code255' => 'Errore PHP (parsing o runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Tempo trascorso (memorizzato come \"%1$s\")', diff --git a/dictionaries/ja.dictionary.itop.core.php b/dictionaries/ja.dictionary.itop.core.php index 82e19a1815..6365357136 100644 --- a/dictionaries/ja.dictionary.itop.core.php +++ b/dictionaries/ja.dictionary.itop.core.php @@ -812,6 +812,8 @@ 'Core:ExplainWTC:StopWatch-TimeSpent' => 'Time spent for "%1$s"~~', 'Core:FriendlyName-Description' => 'Friendly name', 'Core:FriendlyName-Label' => 'Name', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:Placeholder:CannotBeResolved' => '(%1$s : cannot be resolved)~~', 'Core:SyncDataExchangeComment' => '(データ同期)', 'Core:SyncDataSourceAccessRestriction' => '管理者またはデータ·ソースに指定されたユーザーのみ、この操作を実行することができます。操作はキャンセルされました。', diff --git a/dictionaries/nl.dictionary.itop.core.php b/dictionaries/nl.dictionary.itop.core.php index 7c4e514bb6..6d6e29552b 100644 --- a/dictionaries/nl.dictionary.itop.core.php +++ b/dictionaries/nl.dictionary.itop.core.php @@ -804,6 +804,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Verkeerde commando of commando beëindigd met fouten (bijvoorbeeld verkeerde scriptnaam)', 'Core:ExecProcess:Code255' => 'PHP Error (parsing, of runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Tijd voorbij (opgeslagen als "%1$s")', diff --git a/dictionaries/pl.dictionary.itop.core.php b/dictionaries/pl.dictionary.itop.core.php index afac1a3cf5..11f5ec9515 100644 --- a/dictionaries/pl.dictionary.itop.core.php +++ b/dictionaries/pl.dictionary.itop.core.php @@ -803,6 +803,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Niewłaściwe polecenie lub polecenie zakończone błędami (np. zła nazwa skryptu)', 'Core:ExecProcess:Code255' => 'Błąd PHP (parsowanie lub środowisko uruchomieniowe)', 'Core:ExplainWTC:ElapsedTime' => 'Czas, który upłynął (przechowywany jako "%1$s")', diff --git a/dictionaries/pt_br.dictionary.itop.core.php b/dictionaries/pt_br.dictionary.itop.core.php index 340b8a6430..1f04ff704a 100644 --- a/dictionaries/pt_br.dictionary.itop.core.php +++ b/dictionaries/pt_br.dictionary.itop.core.php @@ -801,6 +801,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Comando incorreto ou comando terminou com erros (por exemplo, nome do script errado)', 'Core:ExecProcess:Code255' => 'Erro PHP (parsing, ou runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Tempo decorrido (armazenado como \"%1$s\")', diff --git a/dictionaries/ru.dictionary.itop.core.php b/dictionaries/ru.dictionary.itop.core.php index 816c20f502..cac2d6edcc 100644 --- a/dictionaries/ru.dictionary.itop.core.php +++ b/dictionaries/ru.dictionary.itop.core.php @@ -806,6 +806,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$d ч %2$d мин %3$d с', 'Core:Duration_Minutes_Seconds' => '%1$d мин %2$d с', 'Core:Duration_Seconds' => '%1$d с', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Неверная команда или команда завершена с ошибкой (возможно, неверное имя скрипта)', 'Core:ExecProcess:Code255' => 'Ошибка PHP (parsing, or runtime)', 'Core:ExplainWTC:ElapsedTime' => 'Time elapsed (stored as "%1$s")', diff --git a/dictionaries/sk.dictionary.itop.core.php b/dictionaries/sk.dictionary.itop.core.php index 784039d884..83a8251b41 100644 --- a/dictionaries/sk.dictionary.itop.core.php +++ b/dictionaries/sk.dictionary.itop.core.php @@ -825,6 +825,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Nesprávny príkaz alebo príkaz skončil s chybami (napr. nesprávne meno skriptu)', 'Core:ExecProcess:Code255' => 'PHP chyba (pri parsovaní, alebo počas behu)', 'Core:ExplainWTC:ElapsedTime' => 'Time elapsed (stored as "%1$s")~~', diff --git a/dictionaries/tr.dictionary.itop.core.php b/dictionaries/tr.dictionary.itop.core.php index 9df114c0b3..95226c1491 100644 --- a/dictionaries/tr.dictionary.itop.core.php +++ b/dictionaries/tr.dictionary.itop.core.php @@ -806,6 +806,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => 'Yanlış komut veya komut hataları ile bitti (örneğin, yanlış senaryo adı)', 'Core:ExecProcess:Code255' => 'PHP hatası (ayrıştırma veya çalışma zamanı)', 'Core:ExplainWTC:ElapsedTime' => 'Geçen zaman (\"%1$s\" olarak saklanır)', diff --git a/dictionaries/zh_cn.dictionary.itop.core.php b/dictionaries/zh_cn.dictionary.itop.core.php index a6406d76d4..3fa64b0af7 100644 --- a/dictionaries/zh_cn.dictionary.itop.core.php +++ b/dictionaries/zh_cn.dictionary.itop.core.php @@ -822,6 +822,8 @@ 'Core:Duration_Hours_Minutes_Seconds' => '%1$dh %2$dmin %3$ds', 'Core:Duration_Minutes_Seconds' => '%1$dmin %2$ds', 'Core:Duration_Seconds' => '%1$ds', + 'Core:EventNotificationNewsroom:ErrorNotificationNotSent' => 'Notification not sent~~', + 'Core:EventNotificationNewsroom:ErrorOnDBInsert' => 'An error occurred while saving the notification~~', 'Core:ExecProcess:Code1' => '命令错误或命令执行出错 (例如错误的脚本名称)', 'Core:ExecProcess:Code255' => 'PHP错误 (解析, 或运行时)', 'Core:ExplainWTC:ElapsedTime' => '耗时 (储存为 "%1$s")', From f7c0ae14c13bd847bd2c07912433a69e7db6ed13 Mon Sep 17 00:00:00 2001 From: XavierGR Date: Thu, 14 Nov 2024 09:32:29 +0100 Subject: [PATCH 2/4] =?UTF-8?q?N=C2=B07707=20-=20Newsroom=20user=20prefere?= =?UTF-8?q?nce=20display=20counter=20not=20changeable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/preferences.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/preferences.php b/pages/preferences.php index a5495291c3..a7773ee48e 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -871,7 +871,7 @@ function GetToastsPositionFieldBlock(): iUIBlock if ($iNewsroomDisplaySize > 20) { $iNewsroomDisplaySize = 20; } - $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', $iNewsroomDisplaySize); + $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', 7); if ($iCurrentDisplaySize != $iNewsroomDisplaySize) { // Save the preference only if it differs from the current (or default) value appUserPreferences::SetPref('newsroom_display_size', $iNewsroomDisplaySize); From c36e6609dca6bb57cc6ab64d0f3dbb2f735fd8ac Mon Sep 17 00:00:00 2001 From: "xavier.guiboud-ribaud@combodo.com" Date: Fri, 22 Nov 2024 11:55:26 +0100 Subject: [PATCH 3/4] 7707 - replace hardcoded values for min, max and default newsroom display size with constants --- pages/preferences.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pages/preferences.php b/pages/preferences.php index a7773ee48e..8b34380270 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -33,6 +33,10 @@ require_once(APPROOT.'/application/startup.inc.php'); IssueLog::Trace('----- Request: '.utils::GetRequestUri(), LogChannels::WEB_REQUEST); +const MAX_NEWSROOM_DISPLAY_SIZE = 20; +const MIN_NEWSROOM_DISPLAY_SIZE = 1; +const DEFAULT_NEWSROOM_DISPLAY_SIZE = 7; + /** * Displays the user's changeable preferences * @param $oP WebPage The web page used for the output @@ -269,10 +273,10 @@ function ValidateOtherSettings() $sNewsroomHtml = ''; $sNewsroomHtml .= '
'; - $iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', 7); + $iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); - if ($iNewsroomDisplaySize < 1) $iNewsroomDisplaySize = 1; - if ($iNewsroomDisplaySize > 20) $iNewsroomDisplaySize = 20; + if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE; + if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE; $sInput = ''; $sIcon = ''; $sNewsroomHtml .= Dict::Format('UI:Newsroom:DisplayAtMost_X_Messages', $sInput, $sIcon); @@ -852,6 +856,8 @@ function GetToastsPositionFieldBlock(): iUIBlock DisplayPreferences($oPage); break; case 'apply_newsroom_preferences': + + $iCountProviders = 0; $oUser = UserRights::GetUserObject(); /** @var iNewsroomProvider[] $aProviders */ @@ -864,14 +870,14 @@ function GetToastsPositionFieldBlock(): iUIBlock } $bNewsroomEnabled = (MetaModel::GetConfig()->Get('newsroom_enabled') !== false); if ($bNewsroomEnabled && ($iCountProviders > 0)) { - $iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', 7); - if ($iNewsroomDisplaySize < 1) { - $iNewsroomDisplaySize = 1; + $iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); + if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) { + $iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE; } - if ($iNewsroomDisplaySize > 20) { - $iNewsroomDisplaySize = 20; + if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) { + $iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE; } - $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', 7); + $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); if ($iCurrentDisplaySize != $iNewsroomDisplaySize) { // Save the preference only if it differs from the current (or default) value appUserPreferences::SetPref('newsroom_display_size', $iNewsroomDisplaySize); From 17d0a769cf34981c2864775fdeb9dc66e13f8852 Mon Sep 17 00:00:00 2001 From: "xavier.guiboud-ribaud@combodo.com" Date: Mon, 25 Nov 2024 13:40:57 +0100 Subject: [PATCH 4/4] 7707 Rename and move constants --- pages/preferences.php | 22 +++++++++---------- .../Newsroom/iTopNewsroomController.php | 4 ++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pages/preferences.php b/pages/preferences.php index 8b34380270..707cf19eb1 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -24,6 +24,7 @@ use Combodo\iTop\Application\WebPage\ErrorPage; use Combodo\iTop\Application\WebPage\iTopWebPage; use Combodo\iTop\Application\WebPage\WebPage; +use Combodo\iTop\Controller\Newsroom\iTopNewsroomController; use Combodo\iTop\Controller\Notifications\NotificationsCenterController; use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery; use Combodo\iTop\Service\Router\Router; @@ -33,9 +34,6 @@ require_once(APPROOT.'/application/startup.inc.php'); IssueLog::Trace('----- Request: '.utils::GetRequestUri(), LogChannels::WEB_REQUEST); -const MAX_NEWSROOM_DISPLAY_SIZE = 20; -const MIN_NEWSROOM_DISPLAY_SIZE = 1; -const DEFAULT_NEWSROOM_DISPLAY_SIZE = 7; /** * Displays the user's changeable preferences @@ -273,10 +271,10 @@ function ValidateOtherSettings() $sNewsroomHtml = ''; $sNewsroomHtml .= ''; - $iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); + $iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE); - if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE; - if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE; + if ($iNewsroomDisplaySize < iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE) $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE; + if ($iNewsroomDisplaySize > iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE) $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE; $sInput = ''; $sIcon = ''; $sNewsroomHtml .= Dict::Format('UI:Newsroom:DisplayAtMost_X_Messages', $sInput, $sIcon); @@ -870,14 +868,14 @@ function GetToastsPositionFieldBlock(): iUIBlock } $bNewsroomEnabled = (MetaModel::GetConfig()->Get('newsroom_enabled') !== false); if ($bNewsroomEnabled && ($iCountProviders > 0)) { - $iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); - if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) { - $iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE; + $iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE); + if ($iNewsroomDisplaySize < iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE) { + $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE; } - if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) { - $iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE; + if ($iNewsroomDisplaySize > iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE) { + $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE; } - $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE); + $iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE); if ($iCurrentDisplaySize != $iNewsroomDisplaySize) { // Save the preference only if it differs from the current (or default) value appUserPreferences::SetPref('newsroom_display_size', $iNewsroomDisplaySize); diff --git a/sources/Controller/Newsroom/iTopNewsroomController.php b/sources/Controller/Newsroom/iTopNewsroomController.php index 5d737da60a..134af6c31b 100644 --- a/sources/Controller/Newsroom/iTopNewsroomController.php +++ b/sources/Controller/Newsroom/iTopNewsroomController.php @@ -48,6 +48,10 @@ class iTopNewsroomController extends Controller { public const ROUTE_NAMESPACE = 'itopnewsroom'; + public const DEFAULT_NEWSROOM_DISPLAY_SIZE = 7; + public const DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE = 1; + public const DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE = 20; + /** * @return iTopWebPage