Verified Commit 2f9fbc6f authored by dockx thibault's avatar dockx thibault
Browse files

:sparkles: feat(archive): add archiveTask class for managing resource archiving

Showing with 156 additions and 0 deletions
+156 -0
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2025 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
class archiveTask extends simplePlugin
{
protected $displayHeader = TRUE;
private $subStates;
static function plInfo (): array
{
return [
'plShortName' => _('Tasks Archive'),
'plDescription' => _('Tasks Archive Object'),
'plIcon' => 'geticon.php?context=mimetypes&icon=application-x-archive&size=48',
'plPriority' => 42,
'plObjectClass' => ['fdArchiveTasks'],
'plFilter' => '(objectClass=fdArchiveTasks)',
'plObjectType' => ['tasks'],
'plConflicts' => ['tasksMail', 'tasksLifeCycle', 'tasksNotifications', 'auditTasks'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()),
'plForeignKeys' => [],
];
}
static function getAttributesInfo (): array
{
return [
'section1' => [
'name' => _('SupAnn Resource Archiving Settings'),
'attrs' => [
new SelectAttribute(
_('Resource'), _('Supann resources'),
'fdArchiveTaskResource', TRUE, [], "None"
),
new SelectAttribute(
_('State'), _('Resource state'),
'fdArchiveTaskState', TRUE, [], "None"
),
new SelectAttribute(
_('Sub state'), _('Resource sub state'),
'fdArchiveTaskSubState', FALSE, [], "None"
),
]
],
'UserGroupSelection' => [
'name' => _('Recipients Users and/or Groups'),
'attrs' => [
new UsersGroupsRolesAttribute(
_('Monitored Members'), _('Users or Groups requiring monitoring for archiving.'),
'fdArchiveTaskMembers', TRUE
),
],
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
// SupAnn Status management
if (class_available('supannAccountStatus')) {
$this->setSupannStates();
}
}
/**
* @return void
* Note : Simply get the existing SupAnn states to the archive attributes.
*/
protected function setSupannStates (): void
{
global $config;
// Define the mandatory ones and get the remaining from configuration.
$resources = ['COMPTE' => _('Account'), 'MAIL' => _('Mail'), 'NONE' => _('None')];
foreach ($config->get_cfg_value('SupannRessourceLabels', []) as $line) {
list($resource, $label) = explode(':', $line, 2);
$resources[$resource] = $label;
}
$this->subStates = supannAccountStatus::getConfiguredSubstates(); // Keys are states and Values are subStates
$this->attributesAccess['fdArchiveTaskResource']->setChoices(array_keys($resources), array_values($resources));
$this->attributesAccess['fdArchiveTaskState']->setChoices(array_keys($this->subStates));
// Allows the sub states to be listed when state is modified.
$this->attributesAccess['fdArchiveTaskState']->setSubmitForm('updateFieldsChoices');
$this->updateFieldsChoices();
}
/**
* @return void
* Note : Update list of subStates which depends on the state selected
*/
function updateFieldsChoices ()
{
$subStatesList = $this->subStates[$this->attributesAccess['fdArchiveTaskState']->getValue()] ?? [];
$this->attributesAccess['fdArchiveTaskSubState']->setChoices(array_keys($subStatesList), array_values($subStatesList));
}
/**
* Generate slave tasks for archiving
*/
function generateSlaveTasks ()
{
$monitoredMembers = $this->attributesAccess['fdArchiveTaskMembers']->getValue();
$listOfDN = tasks::extractMembersFromGroups($monitoredMembers);
// Call the method from parent tasks object (first tab) to create sub-tasks.
$this->parent->getBaseObject()->createSlaveTasks($listOfDN, 'fdTasksGranularDN', NULL, 'Archive');
}
/**
* @return bool
*/
function update (): bool
{
parent::update();
return TRUE;
}
/**
* @return array
*/
function save (): array
{
// Verify if this task has to be executed upon saving.
$execTasks = $this->parent->getBaseObject()->fdSubTasksActivation ?? NULL;
if ($execTasks) {
$this->generateSlaveTasks();
}
return parent::save();
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment