From eb984c2f4ca143dd95ad1a3a403c84818d20ec45 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Sun, 19 Jun 2011 11:31:00 +0200 Subject: [PATCH] Moved redundant code into single function, refs #814 Signed-off-by: Florian Aders (EleRas) --- .../froxlor/function.getFilesystemQuota.php | 53 +++++++++++++++++++ scripts/jobs/cron_tasks.php | 27 +--------- scripts/jobs/cron_traffic.php | 28 +--------- 3 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 lib/functions/froxlor/function.getFilesystemQuota.php diff --git a/lib/functions/froxlor/function.getFilesystemQuota.php b/lib/functions/froxlor/function.getFilesystemQuota.php new file mode 100644 index 00000000..ef0471c6 --- /dev/null +++ b/lib/functions/froxlor/function.getFilesystemQuota.php @@ -0,0 +1,53 @@ + (2011-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +function getFilesystemQuota() +{ + global $settings; + if ($settings['system']['diskquota_enabled']) + { + # Fetch all quota in the desired partition + exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); + + $usedquota = array(); + foreach ($repquota as $tmpquota) + { + # Let's see if the line matches a quota - line + if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) + { + # It matches - put it into an array with userid as key (for easy lookup later) + $usedquota[$matches[1]] = array( + 'block' => array( + 'used' => $matches[2], + 'soft' => $matches[3], + 'hard' => $matches[4], + 'grace' => $matches[5] + ), + 'file' => array( + 'used' => $matches[6], + 'soft' => $matches[7], + 'hard' => $matches[8], + 'grace' => $matches[9] + ), + ); + } + } + + return $usedquota; + } + return false; +} \ No newline at end of file diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 8c40e00b..079bd00c 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -471,32 +471,7 @@ while($row = $db->fetch_array($result_tasks)) fwrite($debugHandler, ' cron_tasks: Task10 started - setting filesystem quota' . "\n"); $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 started - setting filesystem quota'); - # Fetch all quota in the desired partition - exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota); - - $usedquota = array(); - foreach ($repquota as $tmpquota) - { - # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) - { - # It matches - put it into an array with userid as key (for easy lookup later) - $usedquota[$matches[1]] = array( - 'block' => array( - 'used' => $matches[2], - 'soft' => $matches[3], - 'hard' => $matches[4], - 'grace' => $matches[5] - ), - 'file' => array( - 'used' => $matches[6], - 'soft' => $matches[7], - 'hard' => $matches[8], - 'grace' => $matches[9] - ), - ); - } - } + $usedquota = getFilesystemQuota(); # Select all customers Froxlor knows about $result = $db->query("SELECT `guid`, `loginname`, `diskspace` FROM `" . TABLE_PANEL_CUSTOMERS . "`;"); diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index 472f86eb..5eecf378 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -105,33 +105,9 @@ $db_root->close(); # We are using the file-system quota, this will speed up the diskusage - collection if ($settings['system']['diskquota_enabled']) { - # Fetch all quota in the desired partition - exec($settings['system']['diskquota_repquota_path'] . " -np " . $settings['system']['diskquota_customer_partition'], $repquota); - - $usedquota = array(); - foreach ($repquota as $tmpquota) - { - # Let's see if the line matches a quota - line - if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) - { - # It matches - put it into an array with userid as key (for easy lookup later) - $usedquota[$matches[1]] = array( - 'block' => array( - 'used' => $matches[2], - 'soft' => $matches[3], - 'hard' => $matches[4], - 'grace' => $matches[5] - ), - 'file' => array( - 'used' => $matches[6], - 'soft' => $matches[7], - 'hard' => $matches[8], - 'grace' => $matches[9] - ), - ); - } - } + $usedquota = getFilesystemQuota(); } + $result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC"); while($row = $db->fetch_array($result))