Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a1f6ddc
Improve translation
eduardomozart Jan 27, 2025
4c1a124
Make "updatetheitem" translatable
eduardomozart Jan 27, 2025
f801a89
Translate on server-side instead of client-side
eduardomozart Jan 27, 2025
713de9e
Fix concatenation
eduardomozart Jan 27, 2025
9422c4e
Display getTypeName() on singular
eduardomozart Jan 27, 2025
4584ad2
Fix escape (see PR#601)
eduardomozart Jan 27, 2025
ece7c69
Fix string getTypeName translation
eduardomozart Jan 27, 2025
8d5c9f1
Translate 'Total updated' string
eduardomozart Jan 28, 2025
5158f17
Translate 'Total updated' string
eduardomozart Jan 28, 2025
0e6ccda
Update hook.php
eduardomozart Jan 29, 2025
804c990
Improves translation to support placeholders
eduardomozart Jan 29, 2025
871e36f
Fix tests
eduardomozart Jan 29, 2025
3a16478
Update collect.class.php
eduardomozart Jan 29, 2025
c30843b
Update taskjoblog.class.php
eduardomozart Jan 29, 2025
1562e18
Update communicationnetworkdiscovery.class.php
eduardomozart Jan 29, 2025
d94a4f2
Update communicationnetworkdiscovery.class.php
eduardomozart Jan 29, 2025
580a894
Update communicationnetworkinventory.class.php
eduardomozart Jan 29, 2025
75529f8
Update communicationnetworkinventory.class.php
eduardomozart Jan 29, 2025
d7c3f75
Update deploycommon.class.php
eduardomozart Jan 29, 2025
02af331
Update networkdiscovery.class.php
eduardomozart Jan 29, 2025
a8c60e4
Update networkdiscovery.class.php
eduardomozart Jan 29, 2025
64df83d
Update networkinventory.class.php
eduardomozart Jan 29, 2025
895977b
Update statediscovery.class.php
eduardomozart Jan 29, 2025
9471e76
Update stateinventory.class.php
eduardomozart Jan 29, 2025
02d4524
Update taskjoblog.class.php
eduardomozart Jan 29, 2025
0779738
Update statediscovery.class.php
eduardomozart Jan 29, 2025
570637f
Update taskjoblog.class.php
eduardomozart Jan 29, 2025
58d6162
Update taskjoblog.class.php
eduardomozart Jan 29, 2025
7334583
Update taskjoblog.class.php
eduardomozart Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ 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(),
'label' => sprintf(__("Number of %s"), __('Tasks', 'glpiinventory')),
],
'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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions inc/collect.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions inc/communicationnetworkdiscovery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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[] = "<br>[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[] = "<br>[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();
Expand Down
12 changes: 7 additions & 5 deletions inc/communicationnetworkinventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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',
'Total updated:' . $cnt
'Total updated:[[' . $cnt . ']]'
);
$response = ['response' => ['RESPONSE' => 'SEND']];
} elseif (isset($a_CONTENT->content->agent->start)) {
Expand Down Expand Up @@ -192,8 +194,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']];
Expand Down
2 changes: 1 addition & 1 deletion inc/communicationrest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions inc/deploycommon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion inc/inventorycomputeresx.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function prepareRun($taskjobs_id)
0,
'PluginGlpiinventoryInventoryComputerESX',
1,
"Unable to find agent to run this job"
"==unabletofindagent=="
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions inc/networkdiscovery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down
15 changes: 9 additions & 6 deletions inc/networkinventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions inc/statediscovery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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==")) {
Expand Down
4 changes: 2 additions & 2 deletions inc/stateinventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion inc/taskjob.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public function forceEnd()
0,
'',
1,
"Action cancelled by user"
"==actioncancelled=="
);
}
}
Expand Down
36 changes: 28 additions & 8 deletions inc/taskjoblog.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,34 +346,54 @@ 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 = [];
// Search for replace [[itemtype::items_id]] by link
preg_match_all("/\[\[(.*)\:\:(.*)\]\]/", $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)) {
$Class = new $classname();
$Class->getFromDB($matches[2][$num]);
$comment = str_replace($commentvalue, $Class->getLink(), $comment);
$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'),
'detail' => __('Detail', 'glpiinventory'),
'badtoken' => __('Agent communication error, impossible to start agent', 'glpiinventory'),
'agentcrashed' => __('Agent stopped/crashed', 'glpiinventory'),
'importdenied' => __('Import denied', 'glpiinventory')
'totalupdated' => __('Total updated:', '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);
}
}
return str_replace(",[", "<br/>[", $comment);
return str_replace([",[", "\\'"], ["<br/>[", "'"], $comment);
}
}
2 changes: 1 addition & 1 deletion inc/taskjobview.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public function submitForm($postvars)
0,
'',
1,
"Action cancelled by user"
"==actioncancelled=="
);
}
}
Expand Down
Loading