From df28b47b925032b09227b546c77789ea0d22219b Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 4 Mar 2015 16:26:35 -0500 Subject: [PATCH 1/7] SAAS-624: Request to rest/media throws an exception if the data set is too large --- .../rest/controllers/MediaController.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index acb0eeed7..c2f140666 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -14,15 +14,27 @@ class Rest_MediaController extends Zend_Rest_Controller public function indexAction() { - $files_array = array(); - foreach (CcFilesQuery::create()->find() as $file) - { - array_push($files_array, CcFiles::sanitizeResponse($file)); + $pager = CcFilesQuery::create()->paginate($page=1, $maxPerPage=50); + $numPages = $pager->getLastPage(); + + $nextPage = 1; + + while ($nextPage <= $numPages) { + $pager = CcFilesQuery::create()->paginate($page=$nextPage, $maxPerPage=50); + + $files = array(); + foreach($pager->getResults() as $file) { + array_push($files, CcFiles::sanitizeResponse($file)); + } + $this->getResponse()->appendBody(json_encode($files)); + unset($files); + + $nextPage +=1; + } $this->getResponse() - ->setHttpResponseCode(200) - ->appendBody(json_encode($files_array)); + ->setHttpResponseCode(200); /** TODO: Use this simpler code instead after we upgrade to Propel 1.7 (Airtime 2.6.x branch): $this->getResponse() From 62d6849d4e71062f6149aeb69de4e34f3a4d0928 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 5 Mar 2015 14:25:48 -0500 Subject: [PATCH 2/7] SAAS-624: Request to rest/media throws an exception if the data set is too large Added offset and limit parameters to /rest/media index action. --- .../rest/controllers/MediaController.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index c2f140666..6a116c13f 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -14,27 +14,31 @@ class Rest_MediaController extends Zend_Rest_Controller public function indexAction() { - $pager = CcFilesQuery::create()->paginate($page=1, $maxPerPage=50); - $numPages = $pager->getLastPage(); + $totalFileCount = BaseCcFilesQuery::create()->count(); - $nextPage = 1; + // Check if offset and limit were sent with request. + // Default limit to zero and offset to $totalFileCount + $offset = $this->_getParam('offset', 0); + $limit = $this->_getParam('limit', $totalFileCount); - while ($nextPage <= $numPages) { - $pager = CcFilesQuery::create()->paginate($page=$nextPage, $maxPerPage=50); - - $files = array(); - foreach($pager->getResults() as $file) { - array_push($files, CcFiles::sanitizeResponse($file)); - } - $this->getResponse()->appendBody(json_encode($files)); - unset($files); - - $nextPage +=1; + $query = CcFilesQuery::create() + ->filterByDbHidden(false) + ->filterByDbImportStatus(0) + ->setLimit($limit) + ->setOffset($offset); + $queryCount = $query->count(); + $queryResult = $query->find(); + $files_array = array(); + foreach ($queryResult as $file) + { + array_push($files_array, CcFiles::sanitizeResponse($file)); } - + $this->getResponse() - ->setHttpResponseCode(200); + ->setHttpResponseCode(200) + ->setHeader('X-TOTAL-COUNT', $queryCount) + ->appendBody(json_encode($files_array)); /** TODO: Use this simpler code instead after we upgrade to Propel 1.7 (Airtime 2.6.x branch): $this->getResponse() From 962f5d925d187a3bfaae4e96f7a62733559627d0 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 6 Mar 2015 09:32:14 -0500 Subject: [PATCH 3/7] SAAS-624: Request to rest/media throws an exception if the data set is too large Fixed small typo --- .../application/modules/rest/controllers/MediaController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 6a116c13f..5f41162ef 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -14,7 +14,7 @@ class Rest_MediaController extends Zend_Rest_Controller public function indexAction() { - $totalFileCount = BaseCcFilesQuery::create()->count(); + $totalFileCount = CcFilesQuery::create()->count(); // Check if offset and limit were sent with request. // Default limit to zero and offset to $totalFileCount From e315498a5cdeebb58aa0e3c929dd469f8edb071f Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 6 Mar 2015 12:21:51 -0500 Subject: [PATCH 4/7] SAAS-624: Request to rest/media throws an exception if the data set is too large Modified /rest/media to return items where file_exists = true --- .../application/modules/rest/controllers/MediaController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 5f41162ef..44d037e83 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -23,6 +23,7 @@ class Rest_MediaController extends Zend_Rest_Controller $query = CcFilesQuery::create() ->filterByDbHidden(false) + ->filterByDbFileExists(true) ->filterByDbImportStatus(0) ->setLimit($limit) ->setOffset($offset); From b398fea7e771fd1a6d63eb8e4b2caefa3d2387bc Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 10 Mar 2015 12:29:30 -0400 Subject: [PATCH 5/7] SAAS-628: Create script to update disk_usage for all Airtime pro stations --- .../controllers/UpgradeController.php | 1 + airtime_mvc/application/upgrade/Upgrades.php | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/airtime_mvc/application/controllers/UpgradeController.php b/airtime_mvc/application/controllers/UpgradeController.php index c9748467b..9af3dc1e9 100644 --- a/airtime_mvc/application/controllers/UpgradeController.php +++ b/airtime_mvc/application/controllers/UpgradeController.php @@ -19,6 +19,7 @@ class UpgradeController extends Zend_Controller_Action array_push($upgraders, new AirtimeUpgrader255()); array_push($upgraders, new AirtimeUpgrader259()); array_push($upgraders, new AirtimeUpgrader2510()); + array_push($upgraders, new AirtimeUpgrader2511()); $didWePerformAnUpgrade = false; try diff --git a/airtime_mvc/application/upgrade/Upgrades.php b/airtime_mvc/application/upgrade/Upgrades.php index 74b9a6d4d..31c602437 100644 --- a/airtime_mvc/application/upgrade/Upgrades.php +++ b/airtime_mvc/application/upgrade/Upgrades.php @@ -341,3 +341,44 @@ class AirtimeUpgrader2510 extends AirtimeUpgrader } } } + +class AirtimeUpgrader2511 extends AirtimeUpgrader +{ + protected function getSupportedVersions() { + return array ( + '2.5.10' + ); + } + + public function getNewVersion() { + return '2.5.11'; + } + + public function upgrade($dir = __DIR__) { + Cache::clear(); + assert($this->checkIfUpgradeSupported()); + + $newVersion = $this->getNewVersion(); + + try { + $this->toggleMaintenanceScreen(true); + Cache::clear(); + + // Begin upgrade + $queryResult = CcFilesQuery::create() + ->select(array('disk_usage')) + ->withColumn('SUM(CcFiles.filesize)', 'disk_usage') + ->find(); + $disk_usage = $queryResult[0]; + Application_Model_Preference::setDiskUsage($disk_usage); + + Application_Model_Preference::SetAirtimeVersion($newVersion); + Cache::clear(); + + $this->toggleMaintenanceScreen(false); + } catch(Exception $e) { + $this->toggleMaintenanceScreen(false); + throw $e; + } + } +} From 5b3edaa2ca61b141a497dd0e21850060de6be8e0 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 11 Mar 2015 13:25:27 -0400 Subject: [PATCH 6/7] Add order by clause to /rest/media index action --- .../application/modules/rest/controllers/MediaController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index 44d037e83..6a2cccd63 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -26,7 +26,8 @@ class Rest_MediaController extends Zend_Rest_Controller ->filterByDbFileExists(true) ->filterByDbImportStatus(0) ->setLimit($limit) - ->setOffset($offset); + ->setOffset($offset) + ->orderByDbId(); $queryCount = $query->count(); $queryResult = $query->find(); From 55ed21a15517ba44d7f740633748118722448f5c Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 11 Mar 2015 13:50:17 -0400 Subject: [PATCH 7/7] SAAS-606: Enable disk quota on Airtime Pro --- airtime_mvc/application/controllers/PluploadController.php | 5 ++--- airtime_mvc/application/models/airtime/CcFiles.php | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/controllers/PluploadController.php b/airtime_mvc/application/controllers/PluploadController.php index c3fa239e9..7c808140c 100644 --- a/airtime_mvc/application/controllers/PluploadController.php +++ b/airtime_mvc/application/controllers/PluploadController.php @@ -27,10 +27,9 @@ class PluploadController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'css/addmedia.css?'.$CC_CONFIG['airtime_version']); $this->view->quotaLimitReached = false; - // temporarily disabling disk quota until all file size values have been set - /*if (Application_Model_Systemstatus::isDiskOverQuota()) { + if (Application_Model_Systemstatus::isDiskOverQuota()) { $this->view->quotaLimitReached = true; - }*/ + } //Because uploads are done via AJAX (and we're not using Zend form for those), we manually add the CSRF //token in here. diff --git a/airtime_mvc/application/models/airtime/CcFiles.php b/airtime_mvc/application/models/airtime/CcFiles.php index 71e5f2ca6..029d21a15 100644 --- a/airtime_mvc/application/models/airtime/CcFiles.php +++ b/airtime_mvc/application/models/airtime/CcFiles.php @@ -78,11 +78,9 @@ class CcFiles extends BaseCcFiles { */ public static function createFromUpload($fileArray) { - /*temporarily disabling disk quota until all file sizes have ben set in the database. if (Application_Model_Systemstatus::isDiskOverQuota()) { throw new OverDiskQuotaException(); } - */ /* If full_path is set, the post request came from ftp. * Users are allowed to upload folders via ftp. If this is the case