Verified Commit d11e143c authored by dockx thibault's avatar dockx thibault
Browse files

:sparkles: Feat(Snapshot) - automatic snapshot operational.

Automatic snapshot operational. Upon user modification,
object snapshotHander is instantiated and call  createSnapshot.
Showing with 4 additions and 60 deletions
+4 -60
...@@ -95,7 +95,6 @@ class SnapshotCreateDialog extends ManagementDialog ...@@ -95,7 +95,6 @@ class SnapshotCreateDialog extends ManagementDialog
return $recordedDataSources; return $recordedDataSources;
} }
/*! /*!
* \brief Get LDAP base to use for ACL checks * \brief Get LDAP base to use for ACL checks
*/ */
......
...@@ -387,6 +387,7 @@ class user extends simplePlugin ...@@ -387,6 +387,7 @@ class user extends simplePlugin
// Note : string values are stored in that array. // Note : string values are stored in that array.
if (isset($config->current['ENABLEAUTOMATICSNAPSHOTS']) && isset($config->current['ENABLESNAPSHOTS'])) { if (isset($config->current['ENABLEAUTOMATICSNAPSHOTS']) && isset($config->current['ENABLESNAPSHOTS'])) {
if (strtolower($config->current['ENABLEAUTOMATICSNAPSHOTS']) === 'true' && strtolower($config->current['ENABLESNAPSHOTS']) === 'true' ) { if (strtolower($config->current['ENABLEAUTOMATICSNAPSHOTS']) === 'true' && strtolower($config->current['ENABLESNAPSHOTS']) === 'true' ) {
$this->generateAutomaticSnapshot();
} }
} }
return parent::post_save(); return parent::post_save();
...@@ -395,66 +396,10 @@ class user extends simplePlugin ...@@ -395,66 +396,10 @@ class user extends simplePlugin
/* /*
* Create the snapshot object in case of automated snapshot. * Create the snapshot object in case of automated snapshot.
*/ */
public function generateSlaveTasks () public function generateAutomaticSnapshot ()
{ {
$emails = $this->attributesAccess['fdTasksEmailsFromDN']->getValue(); $snapshotHandler = new snapshotHandler();
// Ref is supposed to be the mail object CN in this class $snapshotHandler->createSnapshot($this->dn, 'automatic snapshot', 'USER', 'FD');
$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();
}
}
}
} }
......
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