diff --git a/include/management/snapshot/class_SnapshotCreateDialog.inc b/include/management/snapshot/class_SnapshotCreateDialog.inc index 9629eca40b4b573e4531c8052821dd076a748410..dab6b4f3f1e00d5459040db5928aebb14f2c52a6 100644 --- a/include/management/snapshot/class_SnapshotCreateDialog.inc +++ b/include/management/snapshot/class_SnapshotCreateDialog.inc @@ -149,7 +149,6 @@ class SnapshotCreateDialog extends ManagementDialog if (empty($this->snapshotSource)) { $this->snapshotSource = 'FD'; } - error_log($this->snapshotSource); $this->parent->createSnapshot($this->object_dn, $this->description, $this->snapshotSource); return []; } diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 35531802a2c968264821b0dfbc2935fc5f7a09d0..fe51e6d7488c37bc129128ffdf477b6986a54dee 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -375,7 +375,7 @@ class user extends simplePlugin function post_save () { - global $ui; + global $ui, $config; /* Update current locale settings, if we have edited ourselves */ if (isset($this->attrs['preferredLanguage']) && ($this->dn == $ui->dn)) { @@ -383,10 +383,81 @@ class user extends simplePlugin session::set('ui', $ui); session::set('Last_init_lang', 'update'); } - + // Verification is snapshot is enabled and automatic. + // 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' ) { + } + } return parent::post_save(); } + /* + * Create the snapshot object in case of automated snapshot. + */ + public function generateSlaveTasks () + { + $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(); + } + } + } + } + + function adapt_from_template (array $attrs, array $skip = []) { if ($this->uid != '') {