From a1f6ddcad8c2a31874231eeecd1c6732516a4dea Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:01:50 -0300 Subject: [PATCH 01/29] Improve translation This is a revision of PR#601. When translating on client-side, the translation may fail for some items (e.g. "updatetheitem" strings) because it creates a string on-the-fly (e.g. "Update the item Computer", "Update the item Network Device"). Also, when translating on client-side, it creates some artifacts when calling the ``$Class->getLink()`` call because the link are escaped and isn't rendered as HTML on client-side. --- inc/taskjoblog.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 37aa5e6cdd..841175c12b 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -347,6 +347,8 @@ public function getDivState($state, $type = 'div') public static function convertComment($comment) { $matches = []; + // Attempt to translate fixed strings (e.g. error messages, see PR#601) + $comment = __($comment, 'glpiinventory'); // Search for replace [[itemtype::items_id]] by link preg_match_all("/\[\[(.*)\:\:(.*)\]\]/", $comment, $matches); foreach ($matches[0] as $num => $commentvalue) { @@ -354,7 +356,7 @@ public static function convertComment($comment) if ($classname != '' && class_exists($classname)) { $Class = new $classname(); $Class->getFromDB($matches[2][$num]); - $comment = str_replace($commentvalue, $Class->getLink(), $comment); + $comment = $Class->getTypeName() + " " + str_replace($commentvalue, $Class->getLink(), $comment); } } if (strstr($comment, "==")) { From 4c1a124b8acc55ee8696fb23ba80592aabee7c05 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:03:50 -0300 Subject: [PATCH 02/29] Make "updatetheitem" translatable --- inc/communicationnetworkinventory.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/communicationnetworkinventory.class.php b/inc/communicationnetworkinventory.class.php index fd80a0cbcd..2e854bcf71 100644 --- a/inc/communicationnetworkinventory.class.php +++ b/inc/communicationnetworkinventory.class.php @@ -192,8 +192,8 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) } else { $item = $inventory->getMainAsset()->getItem(); $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = - '[==detail==] ==updatetheitem== ' . $item->getTypeName() . - ' [[' . $item::getType() . '::' . $item->fields['id'] . ']]'; + '[==detail==] ==updatetheitem== ' . + '[[' . $item::getType() . '::' . $item->fields['id'] . ']]'; $this->addtaskjoblog(); } $response = ['response' => ['RESPONSE' => 'SEND']]; From f801a89fb54a655d93833bd1637cc8ab30ca9693 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:10:31 -0300 Subject: [PATCH 03/29] Translate on server-side instead of client-side --- js/taskjobs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/taskjobs.js b/js/taskjobs.js index eef88b6b98..33e88dc01f 100644 --- a/js/taskjobs.js +++ b/js/taskjobs.js @@ -423,7 +423,7 @@ function agents_chart(chart_id) { "" + "" + log['log.date'] +""+ "" + taskjobs.logstatuses_names[log['log.state']] +""+ - "" + __(log['log.comment'], 'glpiinventory') +""+ + "" + log['log.comment'] +""+ "" ); }); From 713de9ef01454ceb1d277611796c239aec41fed1 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:18:06 -0300 Subject: [PATCH 04/29] Fix concatenation --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 841175c12b..98c466d25f 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -356,7 +356,7 @@ public static function convertComment($comment) if ($classname != '' && class_exists($classname)) { $Class = new $classname(); $Class->getFromDB($matches[2][$num]); - $comment = $Class->getTypeName() + " " + str_replace($commentvalue, $Class->getLink(), $comment); + $comment = $Class->getTypeName() . " " . str_replace($commentvalue, $Class->getLink(), $comment); } } if (strstr($comment, "==")) { From 9422c4ead09df4ab895971c953aa61ffe3a87d14 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:28:38 -0300 Subject: [PATCH 05/29] Display getTypeName() on singular --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 98c466d25f..5713d7c2b3 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -356,7 +356,7 @@ public static function convertComment($comment) if ($classname != '' && class_exists($classname)) { $Class = new $classname(); $Class->getFromDB($matches[2][$num]); - $comment = $Class->getTypeName() . " " . str_replace($commentvalue, $Class->getLink(), $comment); + $comment = $Class->getTypeName(1) . " " . str_replace($commentvalue, $Class->getLink(), $comment); } } if (strstr($comment, "==")) { From 4584ad2d61dfb1c396510e3038f4814473001591 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:29:59 -0300 Subject: [PATCH 06/29] Fix escape (see PR#601) --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 5713d7c2b3..f13fad6690 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -376,6 +376,6 @@ public static function convertComment($comment) $comment = str_replace($commentvalue, $a_text[$matches[1][$num]], $comment); } } - return str_replace(",[", "
[", $comment); + return str_replace([",[", "\\'"], ["
[", "'"], $comment); } } From ece7c6967504e9ae0446d9f7d11c5cbbfc2daf5d Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:45:00 -0300 Subject: [PATCH 07/29] Fix string getTypeName translation --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index f13fad6690..2fa517fb38 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -356,7 +356,7 @@ public static function convertComment($comment) if ($classname != '' && class_exists($classname)) { $Class = new $classname(); $Class->getFromDB($matches[2][$num]); - $comment = $Class->getTypeName(1) . " " . str_replace($commentvalue, $Class->getLink(), $comment); + $comment = str_replace($commentvalue, $Class->getTypeName(1) . " " . $Class->getLink(), $comment); } } if (strstr($comment, "==")) { From 8d5c9f1caa828d45a2cb1089dbefd16b5581ec10 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Tue, 28 Jan 2025 20:46:25 -0300 Subject: [PATCH 08/29] Translate 'Total updated' string --- inc/taskjoblog.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 2fa517fb38..d943fec73b 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -370,6 +370,7 @@ public static function convertComment($comment) 'detail' => __('Detail', 'glpiinventory'), 'badtoken' => __('Agent communication error, impossible to start agent', 'glpiinventory'), 'agentcrashed' => __('Agent stopped/crashed', 'glpiinventory'), + 'totalupdated' => __('Total updated:', 'glpiinventory'), 'importdenied' => __('Import denied', 'glpiinventory') ]; foreach ($matches[0] as $num => $commentvalue) { From 5158f179a383756ba2f53b7e78f6ef55223e57d8 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Tue, 28 Jan 2025 20:47:01 -0300 Subject: [PATCH 09/29] Translate 'Total updated' string --- inc/communicationnetworkinventory.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/communicationnetworkinventory.class.php b/inc/communicationnetworkinventory.class.php index 2e854bcf71..3d09040b4e 100644 --- a/inc/communicationnetworkinventory.class.php +++ b/inc/communicationnetworkinventory.class.php @@ -129,7 +129,7 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) $agent->fields['id'], 'Agent', '0', - 'Total updated:' . $cnt + '==totalupdated==' . $cnt ); $response = ['response' => ['RESPONSE' => 'SEND']]; } elseif (isset($a_CONTENT->content->agent->start)) { From 0e6ccda765e7208b49e65ca8cf4c327a1ad36855 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:32:25 -0300 Subject: [PATCH 10/29] Update hook.php --- hook.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hook.php b/hook.php index 7405b3cc2f..3b7c780f0b 100644 --- a/hook.php +++ b/hook.php @@ -113,7 +113,7 @@ function plugin_glpiinventory_hook_dashboard_cards($cards) $counters = [ 'agent' => [ 'itemtype' => Agent::getType(), - 'label' => sprintf(__("Number of %s"), Agent::getTypeName(2)), + 'label' => sprintf(__("Number of %s"), Agent::getTypeName(Session::getPluralNumber())), ], 'task' => [ 'itemtype' => PluginGlpiinventoryTask::getType(), @@ -121,11 +121,11 @@ function plugin_glpiinventory_hook_dashboard_cards($cards) ], 'unmanaged' => [ 'itemtype' => Unmanaged::getType(), - 'label' => sprintf(__("Number of %s"), Unmanaged::getTypeName(2)), + 'label' => sprintf(__("Number of %s"), Unmanaged::getTypeName(Session::getPluralNumber())), ], 'computer' => [ 'itemtype' => Computer::getType(), - 'label' => sprintf(__("%s inventoried", "glpiinventory"), Computer::getTypeName(2)), + 'label' => sprintf(__("%s inventoried", "glpiinventory"), Computer::getTypeName(Session::getPluralNumber())), 'apply_filters' => [ 'link' => 'AND', 'field' => 42, @@ -135,7 +135,7 @@ function plugin_glpiinventory_hook_dashboard_cards($cards) ], 'printer' => [ 'itemtype' => Printer::getType(), - 'label' => sprintf(__("%s inventoried", "glpiinventory"), Printer::getTypeName(2)), + 'label' => sprintf(__("%s inventoried", "glpiinventory"), Printer::getTypeName(Session::getPluralNumber())), 'apply_filters' => [ 'link' => 'AND', 'field' => 72, @@ -145,7 +145,7 @@ function plugin_glpiinventory_hook_dashboard_cards($cards) ], 'networkequipement' => [ 'itemtype' => NetworkEquipment::getType(), - 'label' => sprintf(__("%s inventoried", "glpiinventory"), NetworkEquipment::getTypeName(2)), + 'label' => sprintf(__("%s inventoried", "glpiinventory"), NetworkEquipment::getTypeName(Session::getPluralNumber())), 'apply_filters' => [ 'link' => 'AND', 'field' => 72, @@ -155,7 +155,7 @@ function plugin_glpiinventory_hook_dashboard_cards($cards) ], 'phone' => [ 'itemtype' => Phone::getType(), - 'label' => sprintf(__("%s inventoried", "glpiinventory"), Phone::getTypeName(2)), + 'label' => sprintf(__("%s inventoried", "glpiinventory"), Phone::getTypeName(Session::getPluralNumber())), 'apply_filters' => [ 'link' => 'AND', 'field' => 72, From 804c99072432f2ed141bac2b5ef997e7efdd3ff2 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Tue, 28 Jan 2025 23:54:29 -0300 Subject: [PATCH 11/29] Improves translation to support placeholders --- inc/collect.class.php | 1 + inc/communicationnetworkdiscovery.class.php | 8 ++++-- inc/communicationnetworkinventory.class.php | 8 ++++-- inc/communicationrest.class.php | 2 +- inc/deploycommon.class.php | 1 + inc/inventorycomputeresx.class.php | 2 +- inc/networkdiscovery.class.php | 6 ++-- inc/networkinventory.class.php | 15 ++++++---- inc/statediscovery.class.php | 4 +-- inc/stateinventory.class.php | 4 +-- inc/taskjob.class.php | 2 +- inc/taskjoblog.class.php | 31 ++++++++++++++++----- inc/taskjobview.class.php | 2 +- 13 files changed, 57 insertions(+), 29 deletions(-) diff --git a/inc/collect.class.php b/inc/collect.class.php index 99dc3f56ac..087905c208 100644 --- a/inc/collect.class.php +++ b/inc/collect.class.php @@ -457,6 +457,7 @@ public function prepareRun($taskjobs_id) //get agent if for this computer $agents_id = $agent->getFromDBByCrit(['itemtype' => 'Computer', 'items_id' => $computer_id]); if ($agents_id === false) { + $msg = __('No agent found for %1$s', 'glpiinventory'); $jobstates_id = $jobstate->add($c_input); $jobstate->changeStatusFinish( $jobstates_id, diff --git a/inc/communicationnetworkdiscovery.class.php b/inc/communicationnetworkdiscovery.class.php index 37d9e28dec..1e2279e407 100644 --- a/inc/communicationnetworkdiscovery.class.php +++ b/inc/communicationnetworkdiscovery.class.php @@ -77,11 +77,12 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array && (!isset($a_CONTENT->content->agent->exit)) ) { $nb_devices = 1; + $msg = __('%1$s devices found', 'glpiinventory'); $_SESSION['plugin_glpiinventory_taskjoblog']['taskjobs_id'] = $a_CONTENT->jobid; $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = PluginGlpiinventoryTaskjoblog::TASK_RUNNING; - $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . ' ==devicesfound=='; + $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '[[' . $nb_devices . ']] devices found'; $this->addtaskjoblog(); } } @@ -112,11 +113,12 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array ); $message = sprintf( - __('Processed: %1$s Created: %2$s Updated: %3$s', 'glpiinventory'), + 'Processed: %1$s Created: %2$s Updated: %3$s', $updated + $created, $created, $updated ); + $translatable_message = __('Processed: %1$s Created: %2$s Updated: %3$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $a_CONTENT->jobid, $agent->fields['id'], @@ -150,7 +152,7 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array } $itemtype_discovered = $refused = $inventory->getMainAsset()->getItemtype(); if ($itemtype_discovered == Computer::class) { - $a_text[] = "
[info]: " . __("If a real 'computer' please install agent on it (glpiinventory plugin is not design for this) otherwise check SNMP credentials from the IP range"); + $a_text[] = "
[info]: " . __("If a real 'computer' please install agent on it (glpiinventory plugin is not design for this) otherwise check SNMP credentials from the IP range", "glpiinventory"); } $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '==importdenied== ' . implode(", ", $a_text); $this->addtaskjoblog(); diff --git a/inc/communicationnetworkinventory.class.php b/inc/communicationnetworkinventory.class.php index 3d09040b4e..b6d6388d9a 100644 --- a/inc/communicationnetworkinventory.class.php +++ b/inc/communicationnetworkinventory.class.php @@ -99,13 +99,14 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) $_SESSION['glpi_plugin_glpiinventory_processnumber'] = $a_CONTENT->jobid; if ((!isset($a_CONTENT->content->agent->start)) && (!isset($a_CONTENT->content->agent->end)) && (!isset($a_CONTENT->content->agent->exit))) { $nb_devices = 1; + $msg = __('%1$s devices queried', 'glpiinventory'); $_SESSION['plugin_glpiinventory_taskjoblog']['taskjobs_id'] = $a_CONTENT->jobid; $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = '6'; - $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . - ' ==devicesqueried=='; + $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '[[' . $nb_devices . ']]' . + ' devices queried'; $this->addtaskjoblog(); } @@ -124,12 +125,13 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) ] ); + $msg = __('Total updated:%1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $a_CONTENT->jobid, $agent->fields['id'], 'Agent', '0', - '==totalupdated==' . $cnt + 'Total updated:[[' . $cnt . ']]' ); $response = ['response' => ['RESPONSE' => 'SEND']]; } elseif (isset($a_CONTENT->content->agent->start)) { diff --git a/inc/communicationrest.class.php b/inc/communicationrest.class.php index a54afcefbf..2ba901a1db 100644 --- a/inc/communicationrest.class.php +++ b/inc/communicationrest.class.php @@ -208,7 +208,7 @@ public static function updateLog($params = []) $p = []; $p['machineid'] = ''; //DeviceId $p['uuid'] = ''; //Task uuid - $p['msg'] = 'ok'; //status of the task + $p['msg'] = ''; //status of the task $p['code'] = ''; //current step of processing $p['sendheaders'] = true; diff --git a/inc/deploycommon.class.php b/inc/deploycommon.class.php index 2ff418d03f..eb7bc5d3fb 100644 --- a/inc/deploycommon.class.php +++ b/inc/deploycommon.class.php @@ -263,6 +263,7 @@ public function prepareRun($taskjob_id, $definitions_filter = null) $agent->getFromDBByCrit(['itemtype' => 'Computer', 'items_id' => $computer_id]); $agents_id = $agent->fields['id'] ?? false; if ($agents_id === false) { + $msg = __('No agent found for %1$s', 'glpiinventory'); $jobstates_id = $jobstate->add($c_input); $jobstate->changeStatusFinish( $jobstates_id, diff --git a/inc/inventorycomputeresx.class.php b/inc/inventorycomputeresx.class.php index 9f8231ca01..c64cd8f8d9 100644 --- a/inc/inventorycomputeresx.class.php +++ b/inc/inventorycomputeresx.class.php @@ -99,7 +99,7 @@ public function prepareRun($taskjobs_id) 0, 'PluginGlpiinventoryInventoryComputerESX', 1, - "Unable to find agent to run this job" + "==unabletofindagent==" ); } } diff --git a/inc/networkdiscovery.class.php b/inc/networkdiscovery.class.php index 68a226243a..a31fe46ee7 100644 --- a/inc/networkdiscovery.class.php +++ b/inc/networkdiscovery.class.php @@ -121,7 +121,7 @@ public function prepareRun($taskjobs_id) 0, 'PluginGlpiinventoryIPRange', 1, - "Unable to find agent to run this job" + "==unabletofindagent==" ); $input_taskjob = []; $input_taskjob['id'] = $pfTaskjob->fields['id']; @@ -154,7 +154,7 @@ public function prepareRun($taskjobs_id) 0, 'PluginGlpiinventoryIPRange', 1, - "Unable to find agent to run this job" + "==unabletofindagent==" ); $input_taskjob = []; $input_taskjob['id'] = $pfTaskjob->fields['id']; @@ -277,6 +277,7 @@ public function run($jobstate) $iprange_attrs['ENTITY'] = $pfIPRange->fields["entities_id"]; if ($changestate == '0') { + $msg = __('%1$s threads %2$s timeout', 'glpiinventory'); $pfTaskjobstate->changeStatus($pfTaskjobstate->fields['id'], 1); $pfTaskjoblog->addTaskjoblog( $pfTaskjobstate->fields['id'], @@ -288,6 +289,7 @@ public function run($jobstate) ); $changestate = $pfTaskjobstate->fields['id']; } else { + $msg = __('Merged with %1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $pfTaskjobstate->fields['id'], $taskjobstatedatas['items_id'], diff --git a/inc/networkinventory.class.php b/inc/networkinventory.class.php index 7822be86bd..f920bdf5ab 100644 --- a/inc/networkinventory.class.php +++ b/inc/networkinventory.class.php @@ -286,6 +286,7 @@ public function prepareRun($taskjobs_id) $itemtype = 'NetworkEquipment'; } if (isset($a_devicesubnet[$subnet][$itemtype])) { + $msg = __('Unable to find agent to inventory this %1$s', 'glpiinventory'); foreach ($a_devicesubnet[$subnet][$itemtype] as $items_id => $num) { $a_input['itemtype'] = $itemtype; $a_input['items_id'] = $items_id; @@ -304,7 +305,7 @@ public function prepareRun($taskjobs_id) '', 1, "Unable to find agent to inventory " . - "this " . $itemtype + "this [[" . $itemtype . "::" . $items_id . "]]" ); $a_input['state'] = 1; } @@ -338,7 +339,7 @@ public function prepareRun($taskjobs_id) 0, '', 1, - "Unable to find agent to run this job" + "==unabletofindagent==" ); $input_taskjob = []; $input_taskjob['id'] = $pfTaskjob->fields['id']; @@ -382,7 +383,7 @@ public function run($jobstate) $jobstate->fields['items_id'], $jobstate->fields['itemtype'], 1, - "Device have no ip" + "==devicenoip==" ); // Return an empty list to avoid adding an option with no data in the joblist return []; @@ -418,23 +419,25 @@ public function run($jobstate) $device_attrs['AUTHSNMP_ID'] = $a_extended['snmpcredentials_id']; if ($changestate == '0') { + $msg = __('%1$s threads %2$s timeout', 'glpiinventory'); $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1); $pfTaskjoblog->addTaskjoblog( $taskjobstatedatas['id'], '0', 'Agent', '1', - $param_attrs['THREADS_QUERY'] . ' threads ' . - $param_attrs['TIMEOUT'] . ' timeout' + '[[' . $param_attrs['THREADS_QUERY'] . ']] threads ' . + '[[' . $param_attrs['TIMEOUT'] . ']] timeout' ); $changestate = $pfTaskjobstate->fields['id']; } else { + $msg = __('Merged with %1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, - "Merged with " . $changestate + "Merged with [[" . $changestate . "]]" ); } // Only keep required snmp credentials diff --git a/inc/statediscovery.class.php b/inc/statediscovery.class.php index aad1e2b0c9..6124538b7f 100644 --- a/inc/statediscovery.class.php +++ b/inc/statediscovery.class.php @@ -233,8 +233,8 @@ public function display($options = []) foreach ($a_taskjobstates as $datastate) { $a_taskjoblog = $pfTaskjoblog->find(['plugin_glpiinventory_taskjobstates_id' => $datastate['id']]); foreach ($a_taskjoblog as $taskjoblog) { - if (strstr($taskjoblog['comment'], " ==devicesfound==")) { - $nb_found += str_replace(" ==devicesfound==", "", $taskjoblog['comment']); + if (strstr($taskjoblog['comment'], " devices found")) { + $nb_found += str_replace(" devices found", "", $taskjoblog['comment']); } elseif (strstr($taskjoblog['comment'], "==importdenied==")) { $notimporteddevices++; } elseif (strstr($taskjoblog['comment'], "==updatetheitem==")) { diff --git a/inc/stateinventory.class.php b/inc/stateinventory.class.php index 53ad4d3b87..ca7d7b4d0a 100644 --- a/inc/stateinventory.class.php +++ b/inc/stateinventory.class.php @@ -170,8 +170,8 @@ public function display($options = []) foreach ($a_taskjobstates as $datastate) { $a_taskjoblog = $pfTaskjoblog->find(['plugin_glpiinventory_taskjobstates_id' => $datastate['id']]); foreach ($a_taskjoblog as $taskjoblog) { - if (strstr($taskjoblog['comment'], " ==devicesqueried==")) { - $nb_query += str_replace(" ==devicesqueried==", "", $taskjoblog['comment']); + if (strstr($taskjoblog['comment'], " devices queried")) { + $nb_query += str_replace(" devices queried", "", $taskjoblog['comment']); } elseif (strstr($taskjoblog['comment'], " No response from remote host")) { $nb_errors++; } elseif ($taskjoblog['state'] == "1") { diff --git a/inc/taskjob.class.php b/inc/taskjob.class.php index 719edf0c1c..a0242a84c0 100644 --- a/inc/taskjob.class.php +++ b/inc/taskjob.class.php @@ -731,7 +731,7 @@ public function forceEnd() 0, '', 1, - "Action cancelled by user" + "==actioncancelled==" ); } } diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index d943fec73b..d39f3508a5 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -346,24 +346,38 @@ public function getDivState($state, $type = 'div') */ public static function convertComment($comment) { - $matches = []; // Attempt to translate fixed strings (e.g. error messages, see PR#601) $comment = __($comment, 'glpiinventory'); - // Search for replace [[itemtype::items_id]] by link - preg_match_all("/\[\[(.*)\:\:(.*)\]\]/", $comment, $matches); + + $matches = []; + + // Attempt to translate non-fixed strings (e.g. "Unable to find agent to inventory [[NetworkDevice]]" turns into "Unable to find agent to inventory %1") + // preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); + preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); + foreach ($matches[0] as $num => $commentvalue) { + $comment = str_replace($commentvalue, '%' . $num+1 . '$s', $comment); + } + + // Translates the non-fixed string + $comment = __($comment, 'glpiinventory'); + + // Re-do the translated string (e.g. "Não foi possível encontrar o agente para inventário [[NetDevice]]" in pt-BR) foreach ($matches[0] as $num => $commentvalue) { + $comment = str_replace('%' . $num+1 . '$s', $commentvalue, $comment); + // Search for replace [[itemtype::items_id]] by link $classname = $matches[1][$num]; if ($classname != '' && class_exists($classname)) { $Class = new $classname(); - $Class->getFromDB($matches[2][$num]); + $Class->getFromDB($matches[3][$num]); $comment = str_replace($commentvalue, $Class->getTypeName(1) . " " . $Class->getLink(), $comment); + } else { + $comment = str_replace($commentvalue, $matches[1][$num], $comment); } } + if (strstr($comment, "==")) { preg_match_all("/==([\w\d]+)==/", $comment, $matches); $a_text = [ - 'devicesqueried' => __('devices queried', 'glpiinventory'), - 'devicesfound' => __('devices found', 'glpiinventory'), 'addtheitem' => __('Add the item', 'glpiinventory'), 'updatetheitem' => __('Update the item', 'glpiinventory'), 'inventorystarted' => __('Inventory started', 'glpiinventory'), @@ -371,7 +385,10 @@ public static function convertComment($comment) 'badtoken' => __('Agent communication error, impossible to start agent', 'glpiinventory'), 'agentcrashed' => __('Agent stopped/crashed', 'glpiinventory'), 'totalupdated' => __('Total updated:', 'glpiinventory'), - 'importdenied' => __('Import denied', 'glpiinventory') + 'importdenied' => __('Import denied', 'glpiinventory'), + 'devicenoip' => __('Device have no ip', 'glpiinventory'), + 'unabletofindagent' => __('Unable to find agent to run this job', 'glpiinventory'), + 'actioncancelled' => __('Action cancelled by user', 'glpiinventory') ]; foreach ($matches[0] as $num => $commentvalue) { $comment = str_replace($commentvalue, $a_text[$matches[1][$num]], $comment); diff --git a/inc/taskjobview.class.php b/inc/taskjobview.class.php index 4cdb3613e6..1f85d62224 100644 --- a/inc/taskjobview.class.php +++ b/inc/taskjobview.class.php @@ -1033,7 +1033,7 @@ public function submitForm($postvars) 0, '', 1, - "Action cancelled by user" + "==actioncancelled==" ); } } From 871e36f39b2efacdd4d69b0e0e865c13652c0bc0 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:06:01 -0300 Subject: [PATCH 12/29] Fix tests --- inc/taskjoblog.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index d39f3508a5..df0e7903d6 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -355,7 +355,7 @@ public static function convertComment($comment) // preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); foreach ($matches[0] as $num => $commentvalue) { - $comment = str_replace($commentvalue, '%' . $num+1 . '$s', $comment); + $comment = str_replace($commentvalue, '%' . ($num + 1) . '$s', $comment); } // Translates the non-fixed string @@ -363,7 +363,7 @@ public static function convertComment($comment) // Re-do the translated string (e.g. "Não foi possível encontrar o agente para inventário [[NetDevice]]" in pt-BR) foreach ($matches[0] as $num => $commentvalue) { - $comment = str_replace('%' . $num+1 . '$s', $commentvalue, $comment); + $comment = str_replace('%' . ($num + 1) . '$s', $commentvalue, $comment); // Search for replace [[itemtype::items_id]] by link $classname = $matches[1][$num]; if ($classname != '' && class_exists($classname)) { From 3a164783866ddab91065b67fc16fdafc4b90c252 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:49:10 -0300 Subject: [PATCH 13/29] Update collect.class.php --- inc/collect.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/collect.class.php b/inc/collect.class.php index 087905c208..74cb07f193 100644 --- a/inc/collect.class.php +++ b/inc/collect.class.php @@ -457,14 +457,13 @@ public function prepareRun($taskjobs_id) //get agent if for this computer $agents_id = $agent->getFromDBByCrit(['itemtype' => 'Computer', 'items_id' => $computer_id]); if ($agents_id === false) { - $msg = __('No agent found for %1$s', 'glpiinventory'); $jobstates_id = $jobstate->add($c_input); $jobstate->changeStatusFinish( $jobstates_id, 0, '', 1, - "No agent found for [[Computer::" . $computer_id . "]]" + "==noagentfound== [[Computer::" . $computer_id . "]]" ); } else { foreach ($definitions as $definition) { From c30843bdbf623db3adf51b78d9bbba8c092c884f Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:50:16 -0300 Subject: [PATCH 14/29] Update taskjoblog.class.php --- inc/taskjoblog.class.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index df0e7903d6..209706462f 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -351,19 +351,7 @@ public static function convertComment($comment) $matches = []; - // Attempt to translate non-fixed strings (e.g. "Unable to find agent to inventory [[NetworkDevice]]" turns into "Unable to find agent to inventory %1") - // preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); - preg_match_all("/\[\[(\w+)(\:\:(.*))?\]\]/", $comment, $matches); foreach ($matches[0] as $num => $commentvalue) { - $comment = str_replace($commentvalue, '%' . ($num + 1) . '$s', $comment); - } - - // Translates the non-fixed string - $comment = __($comment, 'glpiinventory'); - - // Re-do the translated string (e.g. "Não foi possível encontrar o agente para inventário [[NetDevice]]" in pt-BR) - foreach ($matches[0] as $num => $commentvalue) { - $comment = str_replace('%' . ($num + 1) . '$s', $commentvalue, $comment); // Search for replace [[itemtype::items_id]] by link $classname = $matches[1][$num]; if ($classname != '' && class_exists($classname)) { From 1562e185bd85f7df88cbb8c61c84f03c1509bcbb Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:07:48 -0300 Subject: [PATCH 15/29] Update communicationnetworkdiscovery.class.php --- inc/communicationnetworkdiscovery.class.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/inc/communicationnetworkdiscovery.class.php b/inc/communicationnetworkdiscovery.class.php index 1e2279e407..71f8a0902e 100644 --- a/inc/communicationnetworkdiscovery.class.php +++ b/inc/communicationnetworkdiscovery.class.php @@ -77,12 +77,11 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array && (!isset($a_CONTENT->content->agent->exit)) ) { $nb_devices = 1; - $msg = __('%1$s devices found', 'glpiinventory'); $_SESSION['plugin_glpiinventory_taskjoblog']['taskjobs_id'] = $a_CONTENT->jobid; $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = PluginGlpiinventoryTaskjoblog::TASK_RUNNING; - $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '[[' . $nb_devices . ']] devices found'; + $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . ' ==devices found=='; $this->addtaskjoblog(); } } @@ -113,12 +112,11 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array ); $message = sprintf( - 'Processed: %1$s Created: %2$s Updated: %3$s', + '==processed==: %1$s ==created==: %2$s ==updated==: %3$s', $updated + $created, $created, $updated ); - $translatable_message = __('Processed: %1$s Created: %2$s Updated: %3$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $a_CONTENT->jobid, $agent->fields['id'], From d94a4f2256a0526aa6d307fc5a13043b8632f69f Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:10:08 -0300 Subject: [PATCH 16/29] Update communicationnetworkdiscovery.class.php --- inc/communicationnetworkdiscovery.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/communicationnetworkdiscovery.class.php b/inc/communicationnetworkdiscovery.class.php index 71f8a0902e..070f674d65 100644 --- a/inc/communicationnetworkdiscovery.class.php +++ b/inc/communicationnetworkdiscovery.class.php @@ -81,7 +81,7 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = PluginGlpiinventoryTaskjoblog::TASK_RUNNING; - $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . ' ==devices found=='; + $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . ' ==devicesfound=='; $this->addtaskjoblog(); } } @@ -150,7 +150,7 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory): array } $itemtype_discovered = $refused = $inventory->getMainAsset()->getItemtype(); if ($itemtype_discovered == Computer::class) { - $a_text[] = "
[info]: " . __("If a real 'computer' please install agent on it (glpiinventory plugin is not design for this) otherwise check SNMP credentials from the IP range", "glpiinventory"); + $a_text[] = "
[==info==]: ==errrealcomputer=="; } $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '==importdenied== ' . implode(", ", $a_text); $this->addtaskjoblog(); From 580a8945b8c3438e193c7d1f0f5855d4c64e3ffa Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:11:16 -0300 Subject: [PATCH 17/29] Update communicationnetworkinventory.class.php --- inc/communicationnetworkinventory.class.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/inc/communicationnetworkinventory.class.php b/inc/communicationnetworkinventory.class.php index b6d6388d9a..4f98d6439f 100644 --- a/inc/communicationnetworkinventory.class.php +++ b/inc/communicationnetworkinventory.class.php @@ -99,14 +99,13 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) $_SESSION['glpi_plugin_glpiinventory_processnumber'] = $a_CONTENT->jobid; if ((!isset($a_CONTENT->content->agent->start)) && (!isset($a_CONTENT->content->agent->end)) && (!isset($a_CONTENT->content->agent->exit))) { $nb_devices = 1; - $msg = __('%1$s devices queried', 'glpiinventory'); $_SESSION['plugin_glpiinventory_taskjoblog']['taskjobs_id'] = $a_CONTENT->jobid; $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = '6'; $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '[[' . $nb_devices . ']]' . - ' devices queried'; + ' ==devicesqueried=='; $this->addtaskjoblog(); } @@ -125,13 +124,12 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) ] ); - $msg = __('Total updated:%1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $a_CONTENT->jobid, $agent->fields['id'], 'Agent', '0', - 'Total updated:[[' . $cnt . ']]' + '==totalupdated==:[[' . $cnt . ']]' ); $response = ['response' => ['RESPONSE' => 'SEND']]; } elseif (isset($a_CONTENT->content->agent->start)) { From 75529f8d4dd557baea7f823d5ac50be2448edb10 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:13:17 -0300 Subject: [PATCH 18/29] Update communicationnetworkinventory.class.php --- inc/communicationnetworkinventory.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/communicationnetworkinventory.class.php b/inc/communicationnetworkinventory.class.php index 4f98d6439f..c97c5cce53 100644 --- a/inc/communicationnetworkinventory.class.php +++ b/inc/communicationnetworkinventory.class.php @@ -104,8 +104,8 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) $_SESSION['plugin_glpiinventory_taskjoblog']['items_id'] = $agent->fields['id']; $_SESSION['plugin_glpiinventory_taskjoblog']['itemtype'] = 'Agent'; $_SESSION['plugin_glpiinventory_taskjoblog']['state'] = '6'; - $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = '[[' . $nb_devices . ']]' . - ' ==devicesqueried=='; + $_SESSION['plugin_glpiinventory_taskjoblog']['comment'] = $nb_devices . + ' ==devicesqueried=='; $this->addtaskjoblog(); } @@ -129,7 +129,7 @@ public function import($p_DEVICEID, $a_CONTENT, Inventory $inventory) $agent->fields['id'], 'Agent', '0', - '==totalupdated==:[[' . $cnt . ']]' + '==totalupdated==:' . $cnt ); $response = ['response' => ['RESPONSE' => 'SEND']]; } elseif (isset($a_CONTENT->content->agent->start)) { From d7c3f752104c7226408abdaba89fbafae1134cdd Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:13:57 -0300 Subject: [PATCH 19/29] Update deploycommon.class.php --- inc/deploycommon.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/deploycommon.class.php b/inc/deploycommon.class.php index eb7bc5d3fb..fe73c86934 100644 --- a/inc/deploycommon.class.php +++ b/inc/deploycommon.class.php @@ -263,14 +263,13 @@ public function prepareRun($taskjob_id, $definitions_filter = null) $agent->getFromDBByCrit(['itemtype' => 'Computer', 'items_id' => $computer_id]); $agents_id = $agent->fields['id'] ?? false; if ($agents_id === false) { - $msg = __('No agent found for %1$s', 'glpiinventory'); $jobstates_id = $jobstate->add($c_input); $jobstate->changeStatusFinish( $jobstates_id, 0, '', 1, - "No agent found for [[Computer::" . $computer_id . "]]" + "==noagentfound== [[Computer::" . $computer_id . "]]" ); } else { if ($agentmodule->isAgentCanDo('DEPLOY', $agents_id)) { From 02af3316655b1d1d3e89e4df00a22a32c86581a0 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:15:34 -0300 Subject: [PATCH 20/29] Update networkdiscovery.class.php --- inc/networkdiscovery.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inc/networkdiscovery.class.php b/inc/networkdiscovery.class.php index a31fe46ee7..df5432242c 100644 --- a/inc/networkdiscovery.class.php +++ b/inc/networkdiscovery.class.php @@ -277,15 +277,14 @@ public function run($jobstate) $iprange_attrs['ENTITY'] = $pfIPRange->fields["entities_id"]; if ($changestate == '0') { - $msg = __('%1$s threads %2$s timeout', 'glpiinventory'); $pfTaskjobstate->changeStatus($pfTaskjobstate->fields['id'], 1); $pfTaskjoblog->addTaskjoblog( $pfTaskjobstate->fields['id'], '0', 'Agent', '1', - $agent->fields["threads_networkdiscovery"] . ' threads ' . - $agent->fields["timeout_networkdiscovery"] . ' timeout' + $agent->fields["threads_networkdiscovery"] . ' ==threads== ' . + $agent->fields["timeout_networkdiscovery"] . ' ==timeout==' ); $changestate = $pfTaskjobstate->fields['id']; } else { From a8c60e43c6a6e38bf36a9d7687070c1e798ef7a1 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:16:25 -0300 Subject: [PATCH 21/29] Update networkdiscovery.class.php --- inc/networkdiscovery.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/networkdiscovery.class.php b/inc/networkdiscovery.class.php index df5432242c..2f0c545077 100644 --- a/inc/networkdiscovery.class.php +++ b/inc/networkdiscovery.class.php @@ -288,13 +288,12 @@ public function run($jobstate) ); $changestate = $pfTaskjobstate->fields['id']; } else { - $msg = __('Merged with %1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $pfTaskjobstate->fields['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, - "Merged with " . $changestate + "==mergedwith== " . $changestate ); } $iprange_credentials = new PluginGlpiinventoryIPRange_SNMPCredential(); From 64df83d8a3dd8b945bbe9e0a8c93dd7c81a0d893 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:20:36 -0300 Subject: [PATCH 22/29] Update networkinventory.class.php --- inc/networkinventory.class.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/inc/networkinventory.class.php b/inc/networkinventory.class.php index f920bdf5ab..0f1d33f855 100644 --- a/inc/networkinventory.class.php +++ b/inc/networkinventory.class.php @@ -286,7 +286,6 @@ public function prepareRun($taskjobs_id) $itemtype = 'NetworkEquipment'; } if (isset($a_devicesubnet[$subnet][$itemtype])) { - $msg = __('Unable to find agent to inventory this %1$s', 'glpiinventory'); foreach ($a_devicesubnet[$subnet][$itemtype] as $items_id => $num) { $a_input['itemtype'] = $itemtype; $a_input['items_id'] = $items_id; @@ -304,8 +303,8 @@ public function prepareRun($taskjobs_id) 0, '', 1, - "Unable to find agent to inventory " . - "this [[" . $itemtype . "::" . $items_id . "]]" + "==unabletofindagentitemtype== " . + "[[" . $itemtype . "::" . $items_id . "]]" ); $a_input['state'] = 1; } @@ -419,25 +418,23 @@ public function run($jobstate) $device_attrs['AUTHSNMP_ID'] = $a_extended['snmpcredentials_id']; if ($changestate == '0') { - $msg = __('%1$s threads %2$s timeout', 'glpiinventory'); $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1); $pfTaskjoblog->addTaskjoblog( $taskjobstatedatas['id'], '0', 'Agent', '1', - '[[' . $param_attrs['THREADS_QUERY'] . ']] threads ' . - '[[' . $param_attrs['TIMEOUT'] . ']] timeout' + $param_attrs['THREADS_QUERY'] . ' ==threads== ' . + $param_attrs['TIMEOUT'] . ' ==timeout==' ); $changestate = $pfTaskjobstate->fields['id']; } else { - $msg = __('Merged with %1$s', 'glpiinventory'); $pfTaskjobstate->changeStatusFinish( $taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, - "Merged with [[" . $changestate . "]]" + "==mergedwith== " . $changestate ); } // Only keep required snmp credentials From 895977b08f79703b1611c8374f74174199af21d3 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:21:05 -0300 Subject: [PATCH 23/29] Update statediscovery.class.php --- inc/statediscovery.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/statediscovery.class.php b/inc/statediscovery.class.php index 6124538b7f..e2cc51bf34 100644 --- a/inc/statediscovery.class.php +++ b/inc/statediscovery.class.php @@ -233,8 +233,8 @@ public function display($options = []) foreach ($a_taskjobstates as $datastate) { $a_taskjoblog = $pfTaskjoblog->find(['plugin_glpiinventory_taskjobstates_id' => $datastate['id']]); foreach ($a_taskjoblog as $taskjoblog) { - if (strstr($taskjoblog['comment'], " devices found")) { - $nb_found += str_replace(" devices found", "", $taskjoblog['comment']); + if (strstr($taskjoblog['comment'], " ==devicesfound==")) { + $nb_found += str_replace(" ==devices found==", "", $taskjoblog['comment']); } elseif (strstr($taskjoblog['comment'], "==importdenied==")) { $notimporteddevices++; } elseif (strstr($taskjoblog['comment'], "==updatetheitem==")) { From 9471e7691687551eb040dfb628de9316001c956b Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:21:23 -0300 Subject: [PATCH 24/29] Update stateinventory.class.php --- inc/stateinventory.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/stateinventory.class.php b/inc/stateinventory.class.php index ca7d7b4d0a..53ad4d3b87 100644 --- a/inc/stateinventory.class.php +++ b/inc/stateinventory.class.php @@ -170,8 +170,8 @@ public function display($options = []) foreach ($a_taskjobstates as $datastate) { $a_taskjoblog = $pfTaskjoblog->find(['plugin_glpiinventory_taskjobstates_id' => $datastate['id']]); foreach ($a_taskjoblog as $taskjoblog) { - if (strstr($taskjoblog['comment'], " devices queried")) { - $nb_query += str_replace(" devices queried", "", $taskjoblog['comment']); + if (strstr($taskjoblog['comment'], " ==devicesqueried==")) { + $nb_query += str_replace(" ==devicesqueried==", "", $taskjoblog['comment']); } elseif (strstr($taskjoblog['comment'], " No response from remote host")) { $nb_errors++; } elseif ($taskjoblog['state'] == "1") { From 02d4524c74088777c1890b53e4d61d7db4da0027 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:21:46 -0300 Subject: [PATCH 25/29] Update taskjoblog.class.php --- inc/taskjoblog.class.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 209706462f..bb4168b1e8 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -346,9 +346,6 @@ public function getDivState($state, $type = 'div') */ public static function convertComment($comment) { - // Attempt to translate fixed strings (e.g. error messages, see PR#601) - $comment = __($comment, 'glpiinventory'); - $matches = []; foreach ($matches[0] as $num => $commentvalue) { @@ -356,32 +353,41 @@ public static function convertComment($comment) $classname = $matches[1][$num]; if ($classname != '' && class_exists($classname)) { $Class = new $classname(); - $Class->getFromDB($matches[3][$num]); + $Class->getFromDB($matches[2][$num]); $comment = str_replace($commentvalue, $Class->getTypeName(1) . " " . $Class->getLink(), $comment); - } else { - $comment = str_replace($commentvalue, $matches[1][$num], $comment); } } - if (strstr($comment, "==")) { preg_match_all("/==([\w\d]+)==/", $comment, $matches); $a_text = [ + 'devicesqueried' => __('devices queried', 'glpiinventory'), + 'devicesfound' => __('devices found', 'glpiinventory'), 'addtheitem' => __('Add the item', 'glpiinventory'), 'updatetheitem' => __('Update the item', 'glpiinventory'), 'inventorystarted' => __('Inventory started', 'glpiinventory'), - 'detail' => __('Detail', 'glpiinventory'), + 'detail' => __('Details'), + 'info' => _n('Information', 'Informations', 1), 'badtoken' => __('Agent communication error, impossible to start agent', 'glpiinventory'), 'agentcrashed' => __('Agent stopped/crashed', 'glpiinventory'), - 'totalupdated' => __('Total updated:', 'glpiinventory'), 'importdenied' => __('Import denied', 'glpiinventory'), + 'totalupdated' => __('Total updated:', 'glpiinventory'), 'devicenoip' => __('Device have no ip', 'glpiinventory'), 'unabletofindagent' => __('Unable to find agent to run this job', 'glpiinventory'), - 'actioncancelled' => __('Action cancelled by user', 'glpiinventory') + 'unabletofindagentitemtype' => __('Unable to find agent to inventory this', 'glpiinventory'), + 'actioncancelled' => __('Action cancelled by user', 'glpiinventory'), + 'noagentfound' => __('No agent found for', 'glpiinventory'), + 'errrealcomputer' => __("If a real 'computer' please install agent on it (glpiinventory plugin is not design for this) otherwise check SNMP credentials from the IP range", "glpiinventory"), + 'mergedwith' => __('Merged with', 'glpiinventory'), + 'processed' => __('Processed', 'glpiinventory'), + 'created' => __('Created', 'glpiinventory'), + 'updated' => __('Updated', 'glpiinventory'), + 'threads' => __('threads', 'glpiinventory'), + 'timeout' => __('timeout', 'glpiinventory') ]; foreach ($matches[0] as $num => $commentvalue) { $comment = str_replace($commentvalue, $a_text[$matches[1][$num]], $comment); } } - return str_replace([",[", "\\'"], ["
[", "'"], $comment); + return str_replace([",[", "\\'"], ["
[", "'"], __($comment, 'glpiinventory'))); } } From 07797389ad56c80f33dd4e113bea5bae74d12e59 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:22:50 -0300 Subject: [PATCH 26/29] Update statediscovery.class.php --- inc/statediscovery.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/statediscovery.class.php b/inc/statediscovery.class.php index e2cc51bf34..aad1e2b0c9 100644 --- a/inc/statediscovery.class.php +++ b/inc/statediscovery.class.php @@ -234,7 +234,7 @@ public function display($options = []) $a_taskjoblog = $pfTaskjoblog->find(['plugin_glpiinventory_taskjobstates_id' => $datastate['id']]); foreach ($a_taskjoblog as $taskjoblog) { if (strstr($taskjoblog['comment'], " ==devicesfound==")) { - $nb_found += str_replace(" ==devices found==", "", $taskjoblog['comment']); + $nb_found += str_replace(" ==devicesfound==", "", $taskjoblog['comment']); } elseif (strstr($taskjoblog['comment'], "==importdenied==")) { $notimporteddevices++; } elseif (strstr($taskjoblog['comment'], "==updatetheitem==")) { From 570637f928b9746e6115c1b9e4f4eb662245042f Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:24:20 -0300 Subject: [PATCH 27/29] Update taskjoblog.class.php --- inc/taskjoblog.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index bb4168b1e8..0fbc1ddbab 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -347,9 +347,9 @@ public function getDivState($state, $type = 'div') public static function convertComment($comment) { $matches = []; - + // Search for replace [[itemtype::items_id]] by link + preg_match_all("/\[\[(.*)\:\:(.*)\]\]/", $comment, $matches); foreach ($matches[0] as $num => $commentvalue) { - // Search for replace [[itemtype::items_id]] by link $classname = $matches[1][$num]; if ($classname != '' && class_exists($classname)) { $Class = new $classname(); @@ -360,7 +360,7 @@ public static function convertComment($comment) if (strstr($comment, "==")) { preg_match_all("/==([\w\d]+)==/", $comment, $matches); $a_text = [ - 'devicesqueried' => __('devices queried', 'glpiinventory'), + 'devicesqueried' => __('devices queried', 'glpiinventory'), 'devicesfound' => __('devices found', 'glpiinventory'), 'addtheitem' => __('Add the item', 'glpiinventory'), 'updatetheitem' => __('Update the item', 'glpiinventory'), From 58d6162757e77e5e02cddd6e602f0ed4cbeb4862 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:27:29 -0300 Subject: [PATCH 28/29] Update taskjoblog.class.php --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 0fbc1ddbab..245bb6571c 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -388,6 +388,6 @@ public static function convertComment($comment) $comment = str_replace($commentvalue, $a_text[$matches[1][$num]], $comment); } } - return str_replace([",[", "\\'"], ["
[", "'"], __($comment, 'glpiinventory'))); + return str_replace([",[", "\\'"], ["
[", "'"], __($comment, 'glpiinventory')); } } From 73345838a8978dbccc64943a28c4324da69332af Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Thu, 30 Jan 2025 08:34:37 -0300 Subject: [PATCH 29/29] Update taskjoblog.class.php --- inc/taskjoblog.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/taskjoblog.class.php b/inc/taskjoblog.class.php index 245bb6571c..0736d0161e 100644 --- a/inc/taskjoblog.class.php +++ b/inc/taskjoblog.class.php @@ -366,7 +366,7 @@ public static function convertComment($comment) 'updatetheitem' => __('Update the item', 'glpiinventory'), 'inventorystarted' => __('Inventory started', 'glpiinventory'), 'detail' => __('Details'), - 'info' => _n('Information', 'Informations', 1), + 'info' => _n('Information', 'Information', 1), 'badtoken' => __('Agent communication error, impossible to start agent', 'glpiinventory'), 'agentcrashed' => __('Agent stopped/crashed', 'glpiinventory'), 'importdenied' => __('Import denied', 'glpiinventory'),