From d11e143c0de1bdda29a0a67c7313c62bc8907803 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Tue, 11 Apr 2023 17:27:21 +0100 Subject: [PATCH] :sparkles: Feat(Snapshot) - automatic snapshot operational. Automatic snapshot operational. Upon user modification, object snapshotHander is instantiated and call createSnapshot. --- .../snapshot/class_SnapshotCreateDialog.inc | 1 - plugins/personal/generic/class_user.inc | 63 ++----------------- 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/include/management/snapshot/class_SnapshotCreateDialog.inc b/include/management/snapshot/class_SnapshotCreateDialog.inc index dab6b4f3f..3b07182fd 100644 --- a/include/management/snapshot/class_SnapshotCreateDialog.inc +++ b/include/management/snapshot/class_SnapshotCreateDialog.inc @@ -95,7 +95,6 @@ class SnapshotCreateDialog extends ManagementDialog return $recordedDataSources; } - /*! * \brief Get LDAP base to use for ACL checks */ diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index fe51e6d74..1f42530c4 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -387,6 +387,7 @@ class user extends simplePlugin // Note : string values are stored in that array. if (isset($config->current['ENABLEAUTOMATICSNAPSHOTS']) && isset($config->current['ENABLESNAPSHOTS'])) { if (strtolower($config->current['ENABLEAUTOMATICSNAPSHOTS']) === 'true' && strtolower($config->current['ENABLESNAPSHOTS']) === 'true' ) { + $this->generateAutomaticSnapshot(); } } return parent::post_save(); @@ -395,66 +396,10 @@ class user extends simplePlugin /* * Create the snapshot object in case of automated snapshot. */ - public function generateSlaveTasks () + public function generateAutomaticSnapshot () { - $emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue(); - // Ref is supposed to be the mail object CN in this class - $ref = $this->attributesAccess['fdTasksMailObject']->getValue(); - $from = $this->attributesAccess['fdTasksEmailSender']->getValue(); - // Incremental id allowing creation of different CN for sub tasks - $id = 0; - - // Take the attribute from the other tabs - attribute cannot be null or unset by default - $schedule = $this->parent->getBaseObject()->fdTasksScheduleDate ?? NULL; - - if (isset($emails) && !empty($emails)) { - foreach ($emails as $email) { - $id ++; - - // Here we create the object taskGranular - $tabObject = objects::create('TasksGranular'); - - // remove 'dn' keeping only 'cn' - $rmDn = preg_replace('/(?=,).*/', '', $this->dn); - - // only take the cn without dc - preg_match('/cn=(.*)/', $rmDn, $matches); - - $subTaskName = $matches[1].'-SubTask-'.$id; - - $values['tasksGranular'] = [ - "cn" => $subTaskName, - "fdTasksGranularType" => 'Mail Object', - "fdTasksGranularMaster" => $this->dn, - "fdTasksGranularMail" => $email, - "fdTasksGranularSchedule" => $schedule, - "fdTasksGranularRef" => $ref, - "fdTasksGranularMailFrom" => $from - ]; - - foreach ($values as $tab => $tabvalues) { - if (!isset($tabObject->by_object[$tab])) { - echo "Error tab does not contains attributes values" .PHP_EOL; - } - $error = $tabObject->by_object[$tab]->deserializeValues($tabvalues); - if ($error !== TRUE) { - echo 'Error during deserializing' .$error .PHP_EOL; - } - - $tabObject->current = $tab; - $tabObject->update(); - $tabObject->loadTabs(); - } - - $errors = $tabObject->save(); - - // Showing errors should be better, enhancement here required. - if (!empty($errors)) { - $show_error = new SimplePluginError($this, htmlescape(sprintf(_('Error : "%s", already exist ! Editing existing tasks is forbidden.'), $subTaskName))); - $show_error->display(); - } - } - } + $snapshotHandler = new snapshotHandler(); + $snapshotHandler->createSnapshot($this->dn, 'automatic snapshot', 'USER', 'FD'); } -- GitLab