diff --git a/application/controllers/ItemsController.php b/application/controllers/ItemsController.php index 3d567ce41b..373b7bad72 100644 --- a/application/controllers/ItemsController.php +++ b/application/controllers/ItemsController.php @@ -214,29 +214,31 @@ public function batchEditAction() $delete = (boolean) $this->_getParam('submit-batch-delete'); + $params = json_decode($this->_getParam('params'), true) ?: array(); + unset($params['admin']); + unset($params['module']); + unset($params['controller']); + unset($params['action']); + unset($params['submit_search']); + unset($params['page']); + $redirectTo = 'items/browse'. (empty($params) ? '' : '?'. http_build_query($params)); + $batchAll = (boolean) $this->_getParam('batch-all'); // Process all searched items. if ($batchAll) { - $params = json_decode($this->_getParam('params'), true) ?: array(); - unset($params['admin']); - unset($params['module']); - unset($params['controller']); - unset($params['action']); - unset($params['submit_search']); - unset($params['page']); $totalRecords = $this->_helper->db->count($params); if (empty($totalRecords)) { $this->_helper->flashMessenger(__('No item to batch edit.'), 'error'); - $this->_helper->redirector('browse', 'items', null, $params); + $this->_helper->redirector->gotoUrl($redirectTo); return; } // Special check to avoid the deletion of all the base. if ($delete && total_records('Item') == $totalRecords) { $this->_helper->flashMessenger(__('The deletion of all items is forbidden.'), 'error'); - $this->_helper->redirector('browse', 'items', null, $params); + $this->_helper->redirector->gotoUrl($redirectTo); return; } @@ -253,7 +255,7 @@ public function batchEditAction() $itemIds = $this->_getParam('items'); if (empty($itemIds)) { $this->_helper->flashMessenger(__('You must choose some items to batch edit.'), 'error'); - $this->_helper->redirector('browse', 'items'); + $this->_helper->redirector->gotoUrl($redirectTo); return; } @@ -278,6 +280,7 @@ public function batchEditSaveAction() return $this->_batchEditAllSave(); } + $redirectToSelection = true; $itemIds = $this->_getParam('items'); if ($itemIds) { $metadata = $this->_getParam('metadata'); @@ -354,6 +357,7 @@ public function batchEditSaveAction() $dispatcher->send('Job_ItemBatchEdit', $options); if ($delete) { + $redirectToSelection = false; $message = __('The items were successfully deleted!'); } else { $message = __('The items were successfully changed!'); @@ -364,7 +368,11 @@ public function batchEditSaveAction() $this->_helper->flashMessenger(__('No item to batch edit.'), 'error'); } - $this->_helper->redirector('browse', 'items'); + if ($redirectToSelection && !empty($itemIds)) { + $this->_helper->redirector->gotoUrl('items/browse?'. http_build_query(array('range' => implode(',', (array) $itemIds)))); + } else { + $this->_helper->redirector('browse', 'items'); + } } /** @@ -372,6 +380,7 @@ public function batchEditSaveAction() */ protected function _batchEditAllSave() { + $redirectToSelection = true; // Get the record ids filtered to Omeka_Db_Table::applySearchFilters(). $params = json_decode($this->_getParam('params'), true) ?: array(); $totalRecords = $this->_helper->db->count($params); @@ -419,6 +428,7 @@ protected function _batchEditAllSave() $dispatcher->sendLongRunning('Job_ItemBatchEditAll', $options); if ($delete) { + $redirectToSelection = false; $message = __('The items are checked and deleted one by one in the background.'); } else { $message = __('The items are checked and changed one by one in the background.'); @@ -430,6 +440,10 @@ protected function _batchEditAllSave() $this->_helper->flashMessenger(__('No item to batch edit.'), 'error'); } - $this->_helper->redirector('browse', 'items'); + if ($redirectToSelection && !empty($params)) { + $this->_helper->redirector->gotoUrl('items/browse?'. http_build_query($params)); + } else { + $this->_helper->redirector('browse', 'items'); + } } } diff --git a/application/tests/suite/Controllers/ItemsController/BatchEditTest.php b/application/tests/suite/Controllers/ItemsController/BatchEditTest.php index 895843538c..1ee714effb 100644 --- a/application/tests/suite/Controllers/ItemsController/BatchEditTest.php +++ b/application/tests/suite/Controllers/ItemsController/BatchEditTest.php @@ -193,7 +193,7 @@ public function testBatchEditSaveSuperUser() $this->assertEquals(3, count($item->getTags())); } - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("The items were successfully changed!", $messages['success']); @@ -221,7 +221,7 @@ public function testBatchEditSaveAdminUser() $this->assertEquals(3, count($item->getTags())); } - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("The items were successfully changed!", $messages['success']); @@ -255,7 +255,7 @@ public function testBatchEditContributorUserSaveAllowedData() $this->assertEquals(3, count($item->getTags())); } - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("The items were successfully changed!", $messages['success']); @@ -274,7 +274,7 @@ public function testBatchEditContributorUserSaveDisallowedData() $this->_makePost(); $this->dispatch('/items/batch-edit-save'); - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("User is not allowed", $messages['error'][0]); @@ -303,7 +303,11 @@ public function testBatchDeletePermissions($userRole, $succeeds) $this->_authenticateUser($this->_users[$userRole]); $this->_makePost($post); $this->dispatch('/items/batch-edit-save'); - $this->assertRedirectTo('/items/browse'); + if ($succeeds) { + $this->assertRedirectTo('/items/browse'); + } else { + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); + } $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); @@ -354,7 +358,7 @@ public function testBatchEditMakeNotPublicNotFeatured() $this->assertFalse($item->isFeatured()); } - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("The items were successfully changed!", $messages['success']); @@ -396,7 +400,7 @@ public function testBatchEditRemoveMetadata() $this->assertNull($item->item_type_id); } - $this->assertRedirectTo('/items/browse'); + $this->assertRedirectTo('/items/browse?range='.urlencode(implode(',', $itemIds))); $flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); $messages = $flash->getCurrentMessages(); $this->assertContains("The items were successfully changed!", $messages['success']);