From fbf0ad4339a8736169cdaeabd850bacc9b78811f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 15 May 2015 14:32:58 +0200 Subject: [PATCH] Drop interface Browsable We're not required to handle objects of Zend_Paginator in any way, so creating such as part of a query is not necessary since QueryAdapter accepts any instance of QueryInterface. (gets enforced in the near future) refs #8339 --- application/controllers/ConfigController.php | 3 +- application/controllers/ListController.php | 2 +- library/Icinga/Data/Browsable.php | 20 ----------- library/Icinga/Data/QueryInterface.php | 2 +- library/Icinga/Data/SimpleQuery.php | 33 ------------------- library/Icinga/File/Csv.php | 4 +-- .../controllers/AlertsummaryController.php | 4 +-- .../controllers/ListController.php | 18 +++++----- .../controllers/ShowController.php | 8 ++--- .../views/scripts/list/comments.phtml | 2 +- .../views/scripts/list/downtimes.phtml | 2 +- 11 files changed, 21 insertions(+), 77 deletions(-) delete mode 100644 library/Icinga/Data/Browsable.php diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 370b8f5d0..77b5b66d9 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -128,8 +128,7 @@ class ConfigController extends Controller $this->view->modules = Icinga::app()->getModuleManager()->select() ->from('modules') ->order('enabled', 'desc') - ->order('name') - ->paginate(); + ->order('name'); $this->setupLimitControl(); $this->setupPaginationControl($this->view->modules); // TODO: Not working diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index ca7265f0e..4271e385a 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -51,7 +51,7 @@ class ListController extends Controller . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time . ' - (?[A-Za-z]+) - (?.*)(?!.)/msS' // loglevel, message ))); - $this->view->logData = $resource->select()->order('DESC')->paginate(); + $this->view->logData = $resource->select()->order('DESC'); $this->setupLimitControl(); $this->setupPaginationControl($this->view->logData); diff --git a/library/Icinga/Data/Browsable.php b/library/Icinga/Data/Browsable.php deleted file mode 100644 index a734a2680..000000000 --- a/library/Icinga/Data/Browsable.php +++ /dev/null @@ -1,20 +0,0 @@ -limitOffset; } - /** - * Paginate data - * - * Auto-detects pagination parameters from request when unset - * - * @param int $itemsPerPage Number of items per page - * @param int $pageNumber Current page number - * - * @return Zend_Paginator - */ - public function paginate($itemsPerPage = null, $pageNumber = null) - { - if ($itemsPerPage === null || $pageNumber === null) { - // Detect parameters from request - $request = Icinga::app()->getFrontController()->getRequest(); - if ($itemsPerPage === null) { - $itemsPerPage = $request->getParam('limit', 25); - } - if ($pageNumber === null) { - $pageNumber = $request->getParam('page', 0); - } - } - $this->limit($itemsPerPage, $pageNumber * $itemsPerPage); - $paginator = new Zend_Paginator(new QueryAdapter($this)); - $paginator->setItemCountPerPage($itemsPerPage); - $paginator->setCurrentPageNumber($pageNumber); - return $paginator; - } - /** * Retrieve an array containing all rows of the result set * diff --git a/library/Icinga/File/Csv.php b/library/Icinga/File/Csv.php index ee88262c3..5d9975bc7 100644 --- a/library/Icinga/File/Csv.php +++ b/library/Icinga/File/Csv.php @@ -3,15 +3,13 @@ namespace Icinga\File; -use Icinga\Data\Browsable; - class Csv { protected $query; protected function __construct() {} - public static function fromQuery(Browsable $query) + public static function fromQuery($query) { $csv = new Csv(); $csv->query = $query; diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index dcc805286..1dc3b137b 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -70,7 +70,7 @@ class Monitoring_AlertsummaryController extends Controller 'notification_state' ) ); - $this->view->notifications = $query->paginate(); + $this->view->notifications = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->notifications); @@ -493,7 +493,7 @@ class Monitoring_AlertsummaryController extends Controller $query->order('notification_start_time', 'desc'); - return $query->paginate(5); + return $query->limit(5); } /** diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index bec65ac9b..27f02f3f9 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -97,7 +97,7 @@ class Monitoring_ListController extends Controller ), $this->extraColumns())); $this->filterQuery($query); $this->applyRestriction('monitoring/hosts/filter', $query); - $this->view->hosts = $query->paginate(); + $this->view->hosts = $query; $this->view->stats = $this->backend->select()->from('statusSummary', array( 'hosts_total', @@ -181,7 +181,7 @@ class Monitoring_ListController extends Controller $query = $this->backend->select()->from('serviceStatus', $columns); $this->filterQuery($query); $this->applyRestriction('monitoring/services/filter', $query); - $this->view->services = $query->paginate(); + $this->view->services = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->services); @@ -246,7 +246,7 @@ class Monitoring_ListController extends Controller 'service_display_name' )); $this->filterQuery($query); - $this->view->downtimes = $query->paginate(); + $this->view->downtimes = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->downtimes); @@ -292,7 +292,7 @@ class Monitoring_ListController extends Controller 'service_display_name' )); $this->filterQuery($query); - $this->view->notifications = $query->paginate(); + $this->view->notifications = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->notifications); @@ -326,7 +326,7 @@ class Monitoring_ListController extends Controller 'contact_notify_host_downtime', )); $this->filterQuery($query); - $this->view->contacts = $query->paginate(); + $this->view->contacts = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->contacts); @@ -438,7 +438,7 @@ class Monitoring_ListController extends Controller 'service_display_name' )); $this->filterQuery($query); - $this->view->comments = $query->paginate(); + $this->view->comments = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->comments); @@ -498,7 +498,7 @@ class Monitoring_ListController extends Controller // TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and // service groups. We should separate them. $this->filterQuery($query); - $this->view->servicegroups = $query->paginate(); + $this->view->servicegroups = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->servicegroups); @@ -555,7 +555,7 @@ class Monitoring_ListController extends Controller // TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and // service groups. We should separate them. $this->filterQuery($query); - $this->view->hostgroups = $query->paginate(); + $this->view->hostgroups = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->hostgroups); @@ -594,7 +594,7 @@ class Monitoring_ListController extends Controller )); $this->filterQuery($query); - $this->view->history = $query->paginate(); + $this->view->history = $query; $this->setupLimitControl(); $this->setupPaginationControl($this->view->history); diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index c1522d2a1..8edb2a437 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -70,12 +70,12 @@ class Monitoring_ShowController extends Controller { $this->getTabs()->activate('history'); $this->view->object->fetchEventHistory(); - $this->view->history = $this->view->object->eventhistory->getQuery()->paginate($this->params->get('limit', 50)); + $this->view->history = $this->view->object->eventhistory; $this->handleFormatRequest($this->view->object->eventhistory); $this->fetchHostStats(); $this->setupLimitControl(); - $this->setupPaginationControl($this->view->history); + $this->setupPaginationControl($this->view->history, 50); } public function servicesAction() @@ -154,7 +154,7 @@ class Monitoring_ShowController extends Controller 'command_name' ))->where('contact_id', $contact->contact_id); - $this->view->commands = $commands->paginate(); + $this->view->commands = $commands; $notifications = $this->backend->select()->from('notification', array( 'host_name', @@ -168,7 +168,7 @@ class Monitoring_ShowController extends Controller )); $notifications->where('contact_object_id', $contact->contact_object_id); - $this->view->notifications = $notifications->paginate(); + $this->view->notifications = $notifications; $this->setupLimitControl(); $this->setupPaginationControl($this->view->notifications); } diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index f05adff1f..f8c4383bd 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -5,7 +5,7 @@ render('list/components/selectioninfo.phtml'); ?>
- getTotalItemCount() ?> translate('Comments') ?>: + translate('Comments') ?>:
sortBox; ?> limiter; ?> diff --git a/modules/monitoring/application/views/scripts/list/downtimes.phtml b/modules/monitoring/application/views/scripts/list/downtimes.phtml index 0d35b77cd..79a0e1b92 100644 --- a/modules/monitoring/application/views/scripts/list/downtimes.phtml +++ b/modules/monitoring/application/views/scripts/list/downtimes.phtml @@ -9,7 +9,7 @@ if (! $this->compact): ?> render('list/components/selectioninfo.phtml'); ?>
- getTotalItemCount() ?> translate('Downtimes') ?> + translate('Downtimes') ?>
sortBox; ?> limiter; ?>