SAAS-624: Request to rest/media throws an exception if the data set is too large

This commit is contained in:
drigato 2015-03-04 16:26:35 -05:00
parent 1f6f880dad
commit df28b47b92
1 changed files with 18 additions and 6 deletions

View File

@ -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()