N°2039 N°7298 - Allow Actions to be asynchronous (#625)

* N°2039 - Allows Actions to be asynchronous

* Add unit test

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Apply suggestions from code review

* GetAsynchronousGlobalSetting is now static

* None of the async task for itop notification attribute should be null

* Rename follow_global_setting to user_global_setting

---------

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
This commit is contained in:
Stephen Abello
2024-03-01 09:27:56 +01:00
committed by GitHub
parent 90a5a7a9a7
commit 59129bc3ce
24 changed files with 402 additions and 36 deletions

View File

@@ -81,6 +81,7 @@ abstract class Action extends cmdbAbstractObject
MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("trigger_list",
array("linked_class" => "lnkTriggerAction", "ext_key_to_me" => "action_id", "ext_key_to_remote" => "trigger_id", "allowed_values" => null, "count_min" => 0, "count_max" => 0, "depends_on" => array(), "display_style" => 'property')));
MetaModel::Init_AddAttribute(new AttributeEnum("asynchronous", array("allowed_values" => new ValueSetEnum(['use_global_setting' => 'Use global settings','yes' => 'Yes' ,'no' => 'No']), "sql" => "asynchronous", "default_value" => 'use_global_setting', "is_null_allowed" => false, "depends_on" => array())));
// Display lists
// - Attributes to be displayed for the complete details
@@ -196,7 +197,20 @@ abstract class Action extends cmdbAbstractObject
}
/**
* @throws InvalidConfigParamException
* @param \Combodo\iTop\Application\WebPage\WebPage $oPage
*
* @throws \ApplicationException
* @throws \ArchivedObjectException
* @throws \ConfigException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \InvalidConfigParamException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
* @throws \ReflectionException
* @since 3.2.0 N°5472 method creation
*/
public function GetLastExecutionsTabContent(WebPage $oPage): void
@@ -227,6 +241,32 @@ abstract class Action extends cmdbAbstractObject
$oPage->AddUiBlock($oExecutionsListBlock);
}
/**
* Will be overloaded by the children classes to return the value of their global asynchronous setting (eg. `email_asynchronous` for `\ActionEmail`, `prefer_asynchronous` for `\ActionWebhook`, ...)
*
* @return bool true if the global setting for this kind of action if to be executed asynchronously, false otherwise.
* @since 3.2.0
*/
public static function GetAsynchronousGlobalSetting(): bool
{
return false;
}
/**
* @return bool true if that action instance should be executed asynchronously, otherwise false
* @throws \ArchivedObjectException
* @throws \CoreException
* @since 3.2.0
*/
public function IsAsynchronous(): bool
{
$sAsynchronous = $this->Get('asynchronous');
if ($sAsynchronous === 'use_global_setting') {
return static::GetAsynchronousGlobalSetting();
}
return $sAsynchronous === 'yes';
}
}
/**
@@ -381,6 +421,7 @@ class ActionEmail extends ActionNotification
),
'fieldset:ActionEmail:trigger' => array(
0 => 'trigger_list',
1 => 'asynchronous'
),
),
'col:col2' => array(
@@ -616,7 +657,7 @@ class ActionEmail extends ActionNotification
else
{
$aErrors = [];
$iRes = $oEmail->Send($aErrors, false, $oLog); // allow asynchronous mode
$iRes = $oEmail->Send($aErrors, $this->IsAsynchronous() ? Email::ENUM_SEND_FORCE_ASYNCHRONOUS : Email::ENUM_SEND_FORCE_SYNCHRONOUS, $oLog);
switch ($iRes)
{
case EMAIL_SEND_OK:
@@ -877,4 +918,13 @@ class ActionEmail extends ActionNotification
}
}
}
/**
* @inheritDoc
* @since 3.2.0
*/
public static function GetAsynchronousGlobalSetting(): bool
{
return utils::GetConfig()->Get('email_asynchronous');
}
}

View File

@@ -15,6 +15,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
use Combodo\iTop\Service\Notification\Event\EventiTopNotificationService;
/**
@@ -457,3 +458,87 @@ class AsyncSendEmail extends AsyncTask
return '';
}
}
/**
* An async notification to be sent to iTop users
* @since 3.2.0
*/
class AsyncSendiTopNotifications extends AsyncTask {
public static function Init()
{
$aParams = array
(
"category" => "core/cmdb",
"key_type" => "autoincrement",
"name_attcode" => "created",
"state_attcode" => "",
"reconc_keys" => array(),
"db_table" => "priv_async_send_itop_notifications",
"db_key_field" => "id",
"db_finalclass_field" => "",
);
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeText("recipients", array("allowed_values"=>null, "sql"=>"recipients", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "allowed_values"=>null, "sql"=>"action_id", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "allowed_values"=>null, "sql"=>"trigger_id", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeText("title", array("allowed_values"=>null, "sql"=>"title", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeText("message", array("allowed_values"=>null, "sql"=>"message", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeString("object_class", array("allowed_values"=>null, "sql"=>"object_class", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeText("url", array("allowed_values"=>null, "sql"=>"url", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeDateTime("date", array("allowed_values"=>null, "sql"=>"date", "default_value"=>null, "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
}
/**
* @throws \ArchivedObjectException
* @throws \CoreCannotSaveObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \CoreWarning
* @throws \MySQLException
* @throws \OQLException
*/
public static function AddToQueue(int $iActionId, int $iTriggerId, array $aRecipients, string $sMessage, string $sTitle, string $sUrl, int $iObjectId, ?string $sObjectClass): void
{
$oNew = new static();
$oNew->Set('action_id', $iActionId);
$oNew->Set('trigger_id', $iTriggerId);
$oNew->Set('recipients', json_encode($aRecipients));
$oNew->Set('message', $sMessage);
$oNew->Set('title', $sTitle);
$oNew->Set('url', $sUrl);
$oNew->Set('object_id', $iObjectId);
$oNew->Set('object_class', $sObjectClass);
$oNew->SetCurrentDate('date');
$oNew->DBInsert();
}
/**
* @inheritDoc
*/
public function DoProcess()
{
$oAction = MetaModel::GetObject('Action', $this->Get('action_id'));
$iTriggerId = $this->Get('trigger_id');
$aRecipients = json_decode($this->Get('recipients'));
$sMessage = $this->Get('message');
$sTitle = $this->Get('title');
$sUrl = $this->Get('url');
$iObjectId = $this->Get('object_id');
$sObjectClass = $this->Get('object_class');
$sDate = $this->Get('date');
foreach ($aRecipients as $iRecipientId)
{
$oEvent = EventiTopNotificationService::MakeEventFromAction($oAction, $iRecipientId, $iTriggerId, $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass, $sDate);
$oEvent->DBInsertNoReload();
}
return "Sent";
}
}

View File

@@ -1619,6 +1619,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'notifications.itop.send_asynchronously' => [
'type' => 'bool',
'description' => 'If true then iTop notifications will be sent asynchronously',
'default' => false,
'value' => false,
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'notifications.itop.newsroom_cache_time' => [
'type' => 'integer',
'description' => 'Duration in min between each fetch for notifications in newsroom',

View File

@@ -193,6 +193,9 @@
<item id="trigger_list">
<rank>10</rank>
</item>
<item id="asynchronous">
<rank>20</rank>
</item>
</items>
</item>
</items>
@@ -258,7 +261,23 @@
$oRecipientsSearch = DBObjectSearch::FromOQL($this->Get('recipients'));
$oRecipientsSearch->AllowAllData();
$oRecipientsSet = new DBObjectSet($oRecipientsSearch);
$bIsAsync = $this->IsAsynchronous();
[$sPreviousLanguage, $aPreviousPluginProperties] = $this->SetNotificationLanguage();
if($bIsAsync === true){
$aRecipients = [];
}
$sMessage = MetaModel::ApplyParams($this->Get('message'), $aContextArgs);
$sTitle = MetaModel::ApplyParams($this->Get('title'), $aContextArgs);
$sUrl = MetaModel::ApplyParams($this->Get('url'), $aContextArgs);
$iObjectId = 0;
$sObjectClass = null;
if (array_key_exists('this->object()', $aContextArgs)) {
$iObjectId = $aContextArgs['this->object()']->GetKey();
$sObjectClass = get_class($aContextArgs['this->object()']);
}
while ($oRecipient = $oRecipientsSet->Fetch()) {
// Skip recipients that have no users
if (get_class($oRecipient) === Person::class && UserRights::GetUserFromPerson($oRecipient) === null) {
@@ -267,45 +286,32 @@
if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oRecipient)) {
continue;
}
if (array_key_exists('this->object()', $aContextArgs)) {
$iObjectId = $aContextArgs['this->object()']->GetKey();
$sObjectClass = get_class($aContextArgs['this->object()']);
} else {
$iObjectId = 0;
$sObjectClass = null;
}
$oEvent = new EventiTopNotification();
$oEvent->Set('title', MetaModel::ApplyParams($this->Get('title'), $aContextArgs));
$oEvent->Set('message', MetaModel::ApplyParams($this->Get('message'), $aContextArgs));
// Compute icon
// - First check if one is defined on the action
if (false === $this->Get('icon')->IsEmpty()) {
$oIcon = $this->Get('icon');
}
// - Then, check if the action is for a DM object and if its class has an icon
elseif ($iObjectId > 0 && utils::IsNotNullOrEmptyString(MetaModel::GetClassIcon($sObjectClass, false))) {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(MetaModel::GetClassIcon($sObjectClass, false), $oEvent);
}
// - Otherwise, fallback on the compact logo of the application
else {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(\Combodo\iTop\Application\Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent);
}
$oEvent->Set('icon', $oIcon);
$oEvent->Set('priority', $this->Get('priority'));
$oEvent->Set('contact_id', $oRecipient->GetKey());
$oEvent->Set('trigger_id', $oTrigger->GetKey());
$oEvent->Set('action_id', $this->GetKey());
$iObjectId = array_key_exists('this->object()', $aContextArgs) ? $aContextArgs['this->object()']->GetKey() : 0;
$oEvent->Set('object_id', $iObjectId);
$oEvent->Set('url', MetaModel::ApplyParams($this->Get('url'), $aContextArgs));
$oEvent->DBInsertNoReload();
if($bIsAsync === true) {
$aRecipients[] = $oRecipient->GetKey();
} else {
$oEvent = Combodo\iTop\Service\Notification\Event\EventiTopNotificationService::MakeEventFromAction($this, $oRecipient->GetKey(), $oTrigger->GetKey(), $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
$oEvent->DBInsertNoReload();
}
\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient);
}
if ($bIsAsync === true) {
AsyncSendiTopNotifications::AddToQueue($this->GetKey(), $oTrigger->GetKey(), $aRecipients, $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
}
$this->SetNotificationLanguage($sPreviousLanguage, $aPreviousPluginProperties['language_code'] ?? null);
}
]]></code>
</method>
<method id="GetAsynchronousGlobalSetting">
<comment></comment>
<static>true</static>
<access>public</access>
<code><![CDATA[
public static function GetAsynchronousGlobalSetting(): bool
{
return utils::GetConfig()->Get('notifications.itop.send_asynchronously');
}
]]></code>
</method>
</methods>

View File

@@ -456,6 +456,11 @@ Dict::Add('CS CZ', 'Czech', 'Čeština', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Související triggery',
'Class:Action/Attribute:trigger_list+' => 'Triggery spojené s touto akcí',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Typ',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -454,6 +454,11 @@ Dict::Add('DA DA', 'Danish', 'Dansk', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Relaterede Triggere',
'Class:Action/Attribute:trigger_list+' => 'Triggers linked to this action~~',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Type',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -453,6 +453,11 @@ Dict::Add('DE DE', 'German', 'Deutsch', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Zugehörige Trigger',
'Class:Action/Attribute:trigger_list+' => 'Trigger, die mit dieser Aktion verknüpft sind',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Typ',
'Class:Action/Attribute:finalclass+' => 'Name der instanziierbaren Klasse',
'Action:WarningNoTriggerLinked' => 'Warnung, es ist kein Trigger mit dieser Aktion verknüpft. Die Aktion ist nicht aktiv solange nicht mindestens 1 Trigger verknüpft ist.',

View File

@@ -536,6 +536,11 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Related Triggers',
'Class:Action/Attribute:trigger_list+' => 'Triggers linked to this action',
'Class:Action/Attribute:asynchronous' => 'Asynchronous',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes',
'Class:Action/Attribute:asynchronous/Value:no' => 'No',
'Class:Action/Attribute:finalclass' => 'Action sub-class',
'Class:Action/Attribute:finalclass+' => 'Name of the final class',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.',

View File

@@ -455,6 +455,11 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array(
'Class:Action/Attribute:status/Value:disabled+' => 'Inactivo',
'Class:Action/Attribute:trigger_list' => 'Disparadores Relacionados',
'Class:Action/Attribute:trigger_list+' => 'Disparadores Asociados a esta Acción',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Clase',
'Class:Action/Attribute:finalclass+' => 'Clase',
'Action:WarningNoTriggerLinked' => 'Advertencia, ningún disparador está ligado a esta acción. No se activara hasta que tenga al menos una acción.',

View File

@@ -488,6 +488,11 @@ Dict::Add('FR FR', 'French', 'Français', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Déclencheurs liés',
'Class:Action/Attribute:trigger_list+' => 'Déclencheurs à l\'origine de cette action',
'Class:Action/Attribute:asynchronous' => 'Asynchrone',
'Class:Action/Attribute:asynchronous+' => 'L\'action est-elle exécutée en arrière plan ?',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Utiliser le paramétrage global',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Oui',
'Class:Action/Attribute:asynchronous/Value:no' => 'Non',
'Class:Action/Attribute:finalclass' => 'Sous-classe d\'Action',
'Class:Action/Attribute:finalclass+' => 'Nom de la classe instanciable',
'Action:WarningNoTriggerLinked' => 'Attention, aucun déclencheur n\'est associé à l\'action. Elle ne sera pas active tant qu\'elle n\'en aura pas au moins 1.',

View File

@@ -454,6 +454,11 @@ Dict::Add('HU HU', 'Hungarian', 'Magyar', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Kapcsolódó eseményindítók',
'Class:Action/Attribute:trigger_list+' => 'Eseményindítók amik ehhez a művelethez vannak rendelve',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Művelet típus',
'Class:Action/Attribute:finalclass+' => 'A végleges osztály neve',
'Action:WarningNoTriggerLinked' => 'Figyelmeztetés, nincs a művelethez kapcsolódó eseményindító. Addig nem lesz aktív, amíg legalább 1 nem lesz.',

View File

@@ -454,6 +454,11 @@ Dict::Add('IT IT', 'Italian', 'Italiano', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Triggers correlati',
'Class:Action/Attribute:trigger_list+' => 'Triggers colleagati a questa azione',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Tipo',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -452,6 +452,11 @@ Dict::Add('JA JP', 'Japanese', '日本語', array(
'Class:Action/Attribute:status/Value:disabled+' => '非アクティブ',
'Class:Action/Attribute:trigger_list' => '関連トリガー',
'Class:Action/Attribute:trigger_list+' => 'このアクションにリンクされたトリガー',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'タイプ',
'Class:Action/Attribute:finalclass+' => 'タイプ',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -460,6 +460,11 @@ Dict::Add('NL NL', 'Dutch', 'Nederlands', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Gerelateerde triggers',
'Class:Action/Attribute:trigger_list+' => 'Triggers gelinkt aan deze actie',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Type',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Opgelet: er is geen trigger gelinkt aan deze actie. Zonder minstens 1 actieve trigger zal de actie nooit uitgevoerd worden.',

View File

@@ -453,6 +453,11 @@ Dict::Add('PL PL', 'Polish', 'Polski', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Powiązane wyzwalacze',
'Class:Action/Attribute:trigger_list+' => 'Wyzwalacze powiązane z działaniem',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Podklasa działania',
'Class:Action/Attribute:finalclass+' => 'Nazwa ostatniej klasy',
'Action:WarningNoTriggerLinked' => 'Ostrzeżenie, żaden wyzwalacz nie jest powiązany z akcją. Nie będzie aktywny, dopóki nie będzie miał co najmniej 1.',

View File

@@ -454,6 +454,11 @@ Dict::Add('PT BR', 'Brazilian', 'Brazilian', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Gatilhos relacionados',
'Class:Action/Attribute:trigger_list+' => 'Gatilhos associadas à esta ação',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Tipo',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Aviso, nenhum gatilho está associado à ação. Não será ativo até que esta ação tenha pelo menos um gatilho associado',

View File

@@ -441,6 +441,11 @@ Dict::Add('RU RU', 'Russian', 'Русский', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Связанные триггеры',
'Class:Action/Attribute:trigger_list+' => 'Триггеры, которые запускают данное действие',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Тип',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -451,6 +451,11 @@ Dict::Add('SK SK', 'Slovak', 'Slovenčina', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'Súvisiace spúštače',
'Class:Action/Attribute:trigger_list+' => 'Triggers linked to this action~~',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Typ',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -462,6 +462,11 @@ Dict::Add('TR TR', 'Turkish', 'Türkçe', array(
'Class:Action/Attribute:status/Value:disabled+' => '',
'Class:Action/Attribute:trigger_list' => 'İlgili tetikleyiciler',
'Class:Action/Attribute:trigger_list+' => 'İşleme bağlı tetikleyici',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => 'Tip',
'Class:Action/Attribute:finalclass+' => '',
'Action:WarningNoTriggerLinked' => 'Warning, no trigger is linked to the action. It will not be active until it has at least 1.~~',

View File

@@ -535,6 +535,11 @@ Dict::Add('ZH CN', 'Chinese', '简体中文', array(
'Class:Action/Attribute:status/Value:disabled+' => '停用',
'Class:Action/Attribute:trigger_list' => '相关的触发器',
'Class:Action/Attribute:trigger_list+' => '此操作关联的触发器',
'Class:Action/Attribute:asynchronous' => 'Asynchronous~~',
'Class:Action/Attribute:asynchronous+' => 'Whether this action should be executed in background or not~~',
'Class:Action/Attribute:asynchronous/Value:use_global_setting' => 'Use global setting~~',
'Class:Action/Attribute:asynchronous/Value:yes' => 'Yes~~',
'Class:Action/Attribute:asynchronous/Value:no' => 'No~~',
'Class:Action/Attribute:finalclass' => '操作类型',
'Class:Action/Attribute:finalclass+' => '根本属性的名称',
'Action:WarningNoTriggerLinked' => '警告, 此动作没有关联任何触发器. 至少关联1个触发器才会启用.',

View File

@@ -26,6 +26,7 @@ return array(
'Archive_Tar' => $vendorDir . '/pear/archive_tar/Archive/Tar.php',
'ArchivedObjectException' => $baseDir . '/application/exceptions/ArchivedObjectException.php',
'AsyncSendEmail' => $baseDir . '/core/asynctask.class.inc.php',
'AsyncSendiTopNotifications' => $baseDir . '/core/asynctask.class.inc.php',
'AsyncTask' => $baseDir . '/core/asynctask.class.inc.php',
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'AttributeApplicationLanguage' => $baseDir . '/core/attributedef.class.inc.php',
@@ -495,6 +496,7 @@ return array(
'Combodo\\iTop\\Service\\Links\\LinksBulkDataPostProcessor' => $baseDir . '/sources/Service/Links/LinksBulkDataPostProcessor.php',
'Combodo\\iTop\\Service\\Module\\ModuleService' => $baseDir . '/sources/Service/Module/ModuleService.php',
'Combodo\\iTop\\Service\\Notification\\Event\\EventiTopNotificationGC' => $baseDir . '/sources/Service/Notification/Event/EventiTopNotificationGC.php',
'Combodo\\iTop\\Service\\Notification\\Event\\EventiTopNotificationService' => $baseDir . '/sources/Service/Notification/Event/EventiTopNotificationService.php',
'Combodo\\iTop\\Service\\Notification\\NotificationsRepository' => $baseDir . '/sources/Service/Notification/NotificationsRepository.php',
'Combodo\\iTop\\Service\\Notification\\NotificationsService' => $baseDir . '/sources/Service/Notification/NotificationsService.php',
'Combodo\\iTop\\Service\\Router\\Exception\\RouteNotFoundException' => $baseDir . '/sources/Service/Router/Exception/RouteNotFoundException.php',

View File

@@ -401,6 +401,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
'Archive_Tar' => __DIR__ . '/..' . '/pear/archive_tar/Archive/Tar.php',
'ArchivedObjectException' => __DIR__ . '/../..' . '/application/exceptions/ArchivedObjectException.php',
'AsyncSendEmail' => __DIR__ . '/../..' . '/core/asynctask.class.inc.php',
'AsyncSendiTopNotifications' => __DIR__ . '/../..' . '/core/asynctask.class.inc.php',
'AsyncTask' => __DIR__ . '/../..' . '/core/asynctask.class.inc.php',
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'AttributeApplicationLanguage' => __DIR__ . '/../..' . '/core/attributedef.class.inc.php',
@@ -870,6 +871,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
'Combodo\\iTop\\Service\\Links\\LinksBulkDataPostProcessor' => __DIR__ . '/../..' . '/sources/Service/Links/LinksBulkDataPostProcessor.php',
'Combodo\\iTop\\Service\\Module\\ModuleService' => __DIR__ . '/../..' . '/sources/Service/Module/ModuleService.php',
'Combodo\\iTop\\Service\\Notification\\Event\\EventiTopNotificationGC' => __DIR__ . '/../..' . '/sources/Service/Notification/Event/EventiTopNotificationGC.php',
'Combodo\\iTop\\Service\\Notification\\Event\\EventiTopNotificationService' => __DIR__ . '/../..' . '/sources/Service/Notification/Event/EventiTopNotificationService.php',
'Combodo\\iTop\\Service\\Notification\\NotificationsRepository' => __DIR__ . '/../..' . '/sources/Service/Notification/NotificationsRepository.php',
'Combodo\\iTop\\Service\\Notification\\NotificationsService' => __DIR__ . '/../..' . '/sources/Service/Notification/NotificationsService.php',
'Combodo\\iTop\\Service\\Router\\Exception\\RouteNotFoundException' => __DIR__ . '/../..' . '/sources/Service/Router/Exception/RouteNotFoundException.php',

View File

@@ -0,0 +1,72 @@
<?php
namespace Combodo\iTop\Service\Notification\Event;
use Action;
use Combodo\iTop\Application\Branding;
use EventiTopNotification;
use MetaModel;
use utils;
/**
* Class EventiTopNotificationService
*
* Service to create EventiTopNotification objects from various sources.
*
* @package Combodo\iTop\Service\Notification\Event
* @since 3.2.0
* @api
*/
class EventiTopNotificationService {
/**
* @param \Action $oAction
* @param int $iContactId
* @param int $iTriggerId
* @param string $sMessage
* @param string $sTitle
* @param string $sUrl
* @param int $iObjectId
* @param string|null $sObjectClass
* @param string|null $sDate
*
* @return \EventiTopNotification
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/
public static function MakeEventFromAction(Action $oAction, int $iContactId, int $iTriggerId, string $sMessage, string $sTitle, string $sUrl, int $iObjectId, ?string $sObjectClass, string|null $sDate = null): EventiTopNotification
{
$oEvent = new EventiTopNotification();
$oEvent->Set('title', $sTitle);
$oEvent->Set('message', $sMessage);
// Compute icon
// - First check if one is defined on the action
if (false === $oAction->Get('icon')->IsEmpty()) {
$oIcon = $oAction->Get('icon');
}
// - Then, check if the action is for a DM object and if its class has an icon
elseif ($iObjectId > 0 && utils::IsNotNullOrEmptyString(MetaModel::GetClassIcon($sObjectClass, false))) {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(MetaModel::GetClassIcon($sObjectClass, false), $oEvent);
}
// - Otherwise, fallback on the compact logo of the application
else {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent);
}
$oEvent->Set('icon', $oIcon);
$oEvent->Set('priority', $oAction->Get('priority'));
$oEvent->Set('contact_id', $iContactId);
$oEvent->Set('trigger_id', $iTriggerId);
$oEvent->Set('action_id', $oAction->GetKey());
$oEvent->Set('object_id', $iObjectId);
$oEvent->Set('url', $sUrl);
if ($sDate !== null) {
$oEvent->Set('date', $sDate);
} else {
$oEvent->SetCurrentDate('date');
}
return $oEvent;
}
}

View File

@@ -318,4 +318,65 @@ HTML
],
];
}
/**
* @dataProvider asynchronousValuesContentProvider
*/
public function testAsynchronousValues($sActionAsyncValue, $sConfigAsyncValue, $sExpectedValue)
{
$oConfig = utils::GetConfig();
$sCurrentEmailAsync = $oConfig->Get('email_asynchronous');
$oConfig->Set('email_asynchronous', $sConfigAsyncValue);
$oActionEmail = MetaModel::NewObject('ActionEmail', [
'name' => 'Test action',
'status' => 'disabled',
'from' => 'unit-test@openitop.org',
'subject' => 'Test subject',
'body' => 'Test body',
'asynchronous' => $sActionAsyncValue,
]);
self::assertEquals($sExpectedValue, $oActionEmail->IsAsynchronous());
$oConfig->Set('email_asynchronous', $sCurrentEmailAsync);
}
public function asynchronousValuesContentProvider()
{
return [
'ActionEmail is asynchronous' => [
'yes',
false,
true
],
'ActionEmail is not asynchronous' => [
'no',
true,
false
],
'ActionEmail is asynchronous and config is asynchronous' => [
'yes',
true,
true
],
'ActionEmail is not asynchronous and config is not asynchronous' => [
'no',
false,
false
],
'ActionEmail follows global settings, config is not asynchronous' => [
'use_global_setting',
false,
false
],
'ActionEmail follows global settings, config is asynchronous' => [
'use_global_setting',
true,
true
],
];
}
}