Verified Commit 29bcd870 authored by dockx thibault's avatar dockx thibault
Browse files

:ambulance: Fix(Snapshots) error reported by AT

Fixes error reported by Automated Test.
Showing with 44 additions and 27 deletions
+44 -27
...@@ -91,7 +91,11 @@ class SnapshotCreateDialog extends ManagementDialog ...@@ -91,7 +91,11 @@ class SnapshotCreateDialog extends ManagementDialog
public function getLdapRecordedDataSources () : array public function getLdapRecordedDataSources () : array
{ {
global $config; global $config;
$recordedDataSources = $config->current['SNAPSHOTSOURCEDATA'];
$recordedDataSources = [];
if (isset($config->current['SNAPSHOTSOURCEDATA']) && !empty($config->current['SNAPSHOTSOURCEDATA'])) {
$recordedDataSources = $config->current['SNAPSHOTSOURCEDATA'];
}
return $recordedDataSources; return $recordedDataSources;
} }
......
...@@ -290,37 +290,50 @@ class SnapshotHandler ...@@ -290,37 +290,50 @@ class SnapshotHandler
{ {
global $config; global $config;
$snapMinRetention = $config->current['SNAPSHOTMINRETENTION']; // In case the snap configuration has not set any numbers
$snapRetentionDays = $config->current['SNAPSHOTRETENTIONDAYS']; if (isset($config->current['SNAPSHOTMINRETENTION']) && !empty($config->current['SNAPSHOTMINRETENTION'])) {
$snapMinRetention = $config->current['SNAPSHOTMINRETENTION'];
} else {
$snapMinRetention = 0;
}
if (isset($config->current['SNAPSHOTRETENTIONDAYS']) && !empty($config->current['SNAPSHOTRETENTIONDAYS'])) {
$snapRetentionDays = $config->current['SNAPSHOTRETENTIONDAYS'];
} else {
$snapRetentionDays = -1;
}
// calculate the epoch date on which snaps can be delete. // calculate the epoch date on which snaps can be delete.
$todayMinusRetention = time() - ($snapRetentionDays * 24 * 60 * 60); if ($snapRetentionDays !== 1) {
$snapDateToDelete = strtotime(date('Y-m-d H:i:s', $todayMinusRetention)); $todayMinusRetention = time() - ($snapRetentionDays * 24 * 60 * 60);
$snapDateToDelete = strtotime(date('Y-m-d H:i:s', $todayMinusRetention));
$dnSnapshotsList = $this->getSnapshots($dn, TRUE);
$snapToDelete = []; $dnSnapshotsList = $this->getSnapshots($dn, TRUE);
$snapCount = 0; $snapToDelete = [];
$snapCount = 0;
if (isset($dnSnapshotsList) && !empty($dnSnapshotsList)) {
foreach ($dnSnapshotsList as $snap) { // Generate an arrays with snapshot to delete due to overdate.
$snapCount += 1; if (isset($dnSnapshotsList) && !empty($dnSnapshotsList)) {
// let's keep seconds instead of nanosecs foreach ($dnSnapshotsList as $snap) {
$snapEpoch = preg_split('/-/', $snap['gosaSnapshotTimestamp'][0]); $snapCount += 1;
if ($snapEpoch[0] < $snapDateToDelete) { // let's keep seconds instead of nanosecs
$snapToDelete[] = $snap['dn']; $snapEpoch = preg_split('/-/', $snap['gosaSnapshotTimestamp'][0]);
if ($snapEpoch[0] < $snapDateToDelete) {
$snapToDelete[] = $snap['dn'];
}
} }
} }
}
// The not empty is not mandatory but is more ressource friendly // The not empty is not mandatory but is more ressource friendly
if (!empty($snapToDelete) && ($snapCount > $snapMinRetention)) { if (!empty($snapToDelete) && ($snapCount > $snapMinRetention)) {
$snapToKeep = $snapCount - $snapMinRetention; $snapToKeep = $snapCount - $snapMinRetention;
// Sort snapToDelete by old first DN timestamp is the only thing different. // Sort snapToDelete by old first DN timestamp is the only thing different.
sort($snapToDelete); sort($snapToDelete);
for ($i = 0; $i < $snapToKeep; $i++) { for ($i = 0; $i < $snapToKeep; $i++) {
// not empty required because array keeps on being iterated even if NULL object. // not empty required because array keeps on being iterated even if NULL object.
if (!empty($snapToDelete[$i])) { if (!empty($snapToDelete[$i])) {
$this->removeSnapshot($snapToDelete[$i]); $this->removeSnapshot($snapToDelete[$i]);
}
} }
} }
} }
......
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