From 63e2eda64b082cc7af854f9e10a5cb4cf0c0b7e6 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 14 Apr 2014 12:09:15 -0400 Subject: [PATCH] CC-5786: Quota Enforcement in the File Upload API Tweaked this so it will work on self-hosted instances --- .../application/controllers/PluploadController.php | 2 +- airtime_mvc/application/models/Systemstatus.php | 12 ++++++++++++ .../modules/rest/controllers/MediaController.php | 12 +++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/controllers/PluploadController.php b/airtime_mvc/application/controllers/PluploadController.php index a121bd7ec..abd03afc3 100644 --- a/airtime_mvc/application/controllers/PluploadController.php +++ b/airtime_mvc/application/controllers/PluploadController.php @@ -27,7 +27,7 @@ class PluploadController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']); $this->view->quotaLimitReached = false; - if (Application_Model_Preference::getDiskUsage() > Application_Model_Preference::getDiskQuota()) { + if (Application_Model_Systemstatus::isDiskOverQuota()) { $this->view->quotaLimitReached = true; } } diff --git a/airtime_mvc/application/models/Systemstatus.php b/airtime_mvc/application/models/Systemstatus.php index 4a0480a04..1185609f2 100644 --- a/airtime_mvc/application/models/Systemstatus.php +++ b/airtime_mvc/application/models/Systemstatus.php @@ -235,4 +235,16 @@ class Application_Model_Systemstatus return array_values($partitions); } + + public static function isDiskOverQuota() + { + $diskInfo = self::GetDiskInfo(); + $diskInfo = $diskInfo[0]; + $diskUsage = $diskInfo->totalSpace - $diskInfo->totalFreeSpace; + if ($diskUsage > $diskInfo->totalSpace) { + return true; + } + + return false; + } } diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index ffe09ba89..72fc067b1 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -120,7 +120,7 @@ class Rest_MediaController extends Zend_Rest_Controller return; } - if (!$this->isEnoughDiskSpace()) { + if (!$this->isDiskOverQuota()) { $this->getResponse() ->setHttpResponseCode(400) ->appendBody("ERROR: Disk Quota limit reached."); @@ -430,15 +430,9 @@ class Rest_MediaController extends Zend_Rest_Controller return $response; } - /** - * - * Checks if there is enough disk space to upload the file in question - * We allow one file to exceed to the disk quota so it is possible for the - * disk usage to be greater than the disk usage value - */ - private function isEnoughDiskSpace() + private function isDiskOverQuota() { - if (Application_Model_Preference::getDiskUsage() < Application_Model_Preference::GetDiskQuota()) { + if (Application_Model_Systemstatus::isDiskOverQuota()) { return true; } return false;