LSaddon :: dyngroup: add update_dyngroup_members_cache CLI command

This commit is contained in:
Benjamin Renard 2024-06-05 12:30:06 +02:00
parent 151b229c3d
commit 4235c05b12
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
4 changed files with 112 additions and 6 deletions

View file

@ -72,7 +72,18 @@ function LSaddon_dyngroup_support() {
LScli :: add_command(
'update_dyngroups_members_cache',
'cli_updateDynGroupsMembersCache',
'Update dynamic groups members cache'
___('Update dynamic groups members cache'),
null,
___('Update members cache of all dynamic groups.')
);
LScli :: add_command(
'update_dyngroup_members_cache',
'cli_updateDynGroupMembersCache',
___('Update dynamic group members cache'),
'[dn] [dn]...',
___('Update members cache of one (or multiple) dynamic group specifed by DN.'),
true,
'cli_updateDynGroupMembersCache_autocompleter'
);
}
@ -362,3 +373,64 @@ if (php_sapi_name() != 'cli')
function cli_updateDynGroupsMembersCache($command_args) {
return updateDynGroupsMembersCache();
}
/**
* CLI command to update one dynamic group members cache
* @param array<string> $command_args Command arguments
* @return bool
*/
function cli_updateDynGroupMembersCache($command_args) {
$log = LSlog :: get_logger('LSaddon_dyngroup');
if (!LSsession :: loadLSobject(DYNGROUP_OBJECT_TYPE))
$log -> fatal('Fail to load dyngroup object type');
// Get dyn group
$dyngroup_class = constant('DYNGROUP_OBJECT_TYPE');
$error = false;
foreach ($command_args as $dn) {
$dyngroup = new $dyngroup_class();
if (!$dyngroup->loadData($dn)) {
$log -> error("Fail to load dynamic groupe '$dn'");
$error = true;
continue;
}
$name = $dyngroup->getDisplayName();
if (updateDynGroupMembersCache($dyngroup, false)) {
$log -> info("Dynamic group $name ($dn) members cache updated.");
}
else {
$log -> error("Fail to update dynamic group $name ($dn) members cache.");
$error = true;
}
}
return !$error;
}
/**
* Args autocompleter for CLI update_dyngroup_members_cache command
*
* @param array<string> $comp_words List of already typed words of the command
* @param int $comp_word_num The command word number to autocomplete
* @param string $comp_word The command word to autocomplete
* @param array<string> $opts List of global available options
*
* @return array<string> List of available options for the word to autocomplete
**/
function cli_updateDynGroupMembersCache_autocompleter(
$comp_words, $comp_word_num, $comp_word, $opts
) {
$dns = [];
$opts = LScli :: autocomplete_LSobject_dn(
constant('DYNGROUP_OBJECT_TYPE'),
$comp_word
);
foreach ($comp_words as $idx => $dn) {
if ($idx == $comp_word_num) continue;
$key = array_search($dn, $opts);
if ($key !== false) unset($opts[$key]);
}
return $opts;
}

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2024-04-04 15:14+0200\n"
"PO-Revision-Date: 2024-06-05 12:29+0200\n"
"Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n"
@ -370,7 +370,25 @@ msgstr ""
"Groupes dynamiques : Impossible d'analyser la valeur de l'attribut %{attr} : "
"nombre de parties invalide."
#: includes/addons/LSaddons.dyngroup.php:338
#: includes/addons/LSaddons.dyngroup.php:75
msgid "Update dynamic groups members cache"
msgstr "Mettre à jour le cache des membres des groupes dynamiques"
#: includes/addons/LSaddons.dyngroup.php:77
msgid "Update members cache of all dynamic groups."
msgstr "Mettre à jour le cache des membres de tous les groupes dynamiques."
#: includes/addons/LSaddons.dyngroup.php:82
msgid "Update dynamic group members cache"
msgstr "Mettre à jour le cache des membres d'un groupe dynamique"
#: includes/addons/LSaddons.dyngroup.php:84
msgid "Update members cache of one (or multiple) dynamic group specifed by DN."
msgstr ""
"Mettre à jour le cache des membres d'un (ou plusieurs) groupe dynamique "
"spécifié par son DN."
#: includes/addons/LSaddons.dyngroup.php:349
msgid ""
"Members cache of %{count} dynamic group(s) have been updated because thes "
"were potentially impacted by your changes."
@ -378,7 +396,7 @@ msgstr ""
"Le cache des membres de %{count} groupe(s) dynamique(s) as été mis à jour "
"suite à vos modifications qui les impactaient potentiellement."
#: includes/addons/LSaddons.dyngroup.php:345
#: includes/addons/LSaddons.dyngroup.php:356
msgid ""
"Members cache of %{count} dynamic group(s) have NOT been updated but thes "
"were potentially impacted by your changes. A delay of some minutes could be "

View file

@ -291,13 +291,29 @@ msgstr ""
msgid "Dynamic groups: Fail to parse %{attr} value : invalid number of parts."
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:338
#: includes/addons/LSaddons.dyngroup.php:75
msgid "Update dynamic groups members cache"
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:77
msgid "Update members cache of all dynamic groups."
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:82
msgid "Update dynamic group members cache"
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:84
msgid "Update members cache of one (or multiple) dynamic group specifed by DN."
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:349
msgid ""
"Members cache of %{count} dynamic group(s) have been updated because thes "
"were potentially impacted by your changes."
msgstr ""
#: includes/addons/LSaddons.dyngroup.php:345
#: includes/addons/LSaddons.dyngroup.php:356
msgid ""
"Members cache of %{count} dynamic group(s) have NOT been updated but thes "
"were potentially impacted by your changes. A delay of some minutes could be "