mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
🎨 check-backup : improve code readability
move exit conditions on top to avoid if/else nightmare
This commit is contained in:
@@ -214,14 +214,31 @@ catch(Exception $e)
|
|||||||
$sZipArchiveFile = MakeArchiveFileName().'.tar.gz';
|
$sZipArchiveFile = MakeArchiveFileName().'.tar.gz';
|
||||||
echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n";
|
echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n";
|
||||||
|
|
||||||
if (file_exists($sZipArchiveFile))
|
if (!file_exists($sZipArchiveFile))
|
||||||
{
|
{
|
||||||
if ($aStat = stat($sZipArchiveFile))
|
RaiseAlarm("Missing backup file '$sZipArchiveFile'");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aStat = stat($sZipArchiveFile);
|
||||||
|
if (!$aStat)
|
||||||
{
|
{
|
||||||
|
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$iSize = (int)$aStat['size'];
|
$iSize = (int)$aStat['size'];
|
||||||
$iMIN = utils::ReadParam('check_size_min', 0);
|
$iMIN = utils::ReadParam('check_size_min', 0);
|
||||||
if ($iSize > $iMIN)
|
if ($iSize <= $iMIN)
|
||||||
{
|
{
|
||||||
|
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
echo "Found the archive\n";
|
echo "Found the archive\n";
|
||||||
$sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive
|
$sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive
|
||||||
if (file_exists($sOldArchiveFile))
|
if (file_exists($sOldArchiveFile))
|
||||||
@@ -248,20 +265,3 @@ if (file_exists($sZipArchiveFile))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RaiseAlarm("Missing backup file '$sZipArchiveFile'");
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user