Added BulkActionException to allow clean error feedback from bulk actions
This commit is contained in:
		
							parent
							
								
									7c32b1f7a8
								
							
						
					
					
						commit
						ac63992efa
					
				| @ -1,5 +1,8 @@ | ||||
| <?php declare(strict_types=1); | ||||
| 
 | ||||
| class BulkActionException extends SCoreException | ||||
| { | ||||
| } | ||||
| class BulkActionBlockBuildingEvent extends Event | ||||
| { | ||||
|     /** @var array  */ | ||||
| @ -166,13 +169,14 @@ class BulkActions extends Extension | ||||
| 
 | ||||
|             $action = $_POST['bulk_action']; | ||||
| 
 | ||||
|             try { | ||||
|                 $items = null; | ||||
|                 if (isset($_POST['bulk_selected_ids']) && !empty($_POST['bulk_selected_ids'])) { | ||||
|                     $data = json_decode($_POST['bulk_selected_ids']); | ||||
|                     if (empty($data)) { | ||||
|                     throw new SCoreException("No ids specified in bulk_selected_ids"); | ||||
|                         throw new BulkActionException("No ids specified in bulk_selected_ids"); | ||||
|                     } | ||||
|                 if (is_array($data)&&!empty($data)) { | ||||
|                     if (is_array($data) && !empty($data)) { | ||||
|                         $items = $this->yield_items($data); | ||||
|                     } | ||||
|                 } elseif (isset($_POST['bulk_query']) && $_POST['bulk_query'] != "") { | ||||
| @ -181,7 +185,7 @@ class BulkActions extends Extension | ||||
|                         $items = $this->yield_search_results($query); | ||||
|                     } | ||||
|                 } else { | ||||
|                 throw new SCoreException("No ids selected and no query present, cannot perform bulk operation on entire collection"); | ||||
|                     throw new BulkActionException("No ids selected and no query present, cannot perform bulk operation on entire collection"); | ||||
|                 } | ||||
| 
 | ||||
|                 $bae = new BulkActionEvent($action, $items); | ||||
| @ -189,6 +193,9 @@ class BulkActions extends Extension | ||||
|                 if (is_iterable($items)) { | ||||
|                     send_event($bae); | ||||
|                 } | ||||
|             } catch (BulkActionException $e) { | ||||
|                 log_error(BulkActionsInfo::KEY, $e->getMessage(), $e->getMessage()); | ||||
|             } | ||||
| 
 | ||||
|             if ($bae->redirect) { | ||||
|                 $page->set_mode(PageMode::REDIRECT); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user