diff --git a/resources/inc/class.resources_bo.inc.php b/resources/inc/class.resources_bo.inc.php index c5feb3303f..0b5b7a31fb 100755 --- a/resources/inc/class.resources_bo.inc.php +++ b/resources/inc/class.resources_bo.inc.php @@ -128,6 +128,8 @@ class resources_bo $extra_cols[] = 'acc_count'; break; case self::DELETED: + $join = $acc_join; + $extra_cols[] = 'acc_count'; $filter[] = 'deleted IS NOT NULL'; break; default: @@ -229,7 +231,7 @@ class resources_bo if($resource['acc_count']) { $resource['class'] .= 'hasAccessories '; - $accessories = $this->get_acc_list($resource['res_id']); + $accessories = $this->get_acc_list($resource['res_id'],$query['filter2']==self::DELETED); foreach($accessories as $acc_id => $acc_name) { $resource['accessories'][] = array('acc_id' => $acc_id, 'name' => $this->link_title($acc_id)); @@ -414,7 +416,14 @@ class resources_bo $accessories = $this->get_acc_list($res_id); foreach($accessories as $acc_id => $name) { - $this->delete($acc_id); + // Don't purge already deleted accessories + $acc = $this->read($acc_id); + if(!$acc['deleted']) + { + $acc['deleted'] = time(); + $this->save($acc); + egw_link::unlink(0,'resources',$acc_id,'','','',true); + } } return false; } @@ -444,16 +453,18 @@ class resources_bo * * Cornelius Weiss * @param int $res_id id of resource + * @param boolean $deleted Include deleted accessories * @return array */ - function get_acc_list($res_id) + function get_acc_list($res_id,$deleted=false) { if($res_id < 1){return;} - $data = $this->so->search('','res_id,name','','','','','',$start,array('accessory_of' => $res_id),'',$need_full_no_count=true); + $data = $this->so->search('','res_id,name,deleted','','','','','',$start,array('accessory_of' => $res_id),'',$need_full_no_count=true); $acc_list = array(); if($data) { foreach($data as $num => $resource) { + if($resource['deleted'] && !$deleted) continue; $acc_list[$resource['res_id']] = $resource['name']; } } diff --git a/resources/inc/class.resources_ui.inc.php b/resources/inc/class.resources_ui.inc.php index 01e2e2a21b..c5daed3218 100755 --- a/resources/inc/class.resources_ui.inc.php +++ b/resources/inc/class.resources_ui.inc.php @@ -354,6 +354,8 @@ class resources_ui $action_msg = lang('restored'); foreach($checked as $n=>$id) { + // Extra data + if(!$id) continue; $resource = $this->bo->read($id); $resource['deleted'] = null; $this->bo->save($resource); @@ -365,6 +367,8 @@ class resources_ui $promoted_accessories = 0; foreach($checked as $n => &$id) { + // Extra data + if(!$id) continue; if($settings == 'promote') { // Handle a selected accessory @@ -396,6 +400,7 @@ class resources_ui // Remove checked accessories, deleting resource will remove them // We get an error if we try to delete them after they're gone $accessories = $this->bo->get_acc_list($id); + foreach($accessories as $acc_id => $name) { $checked_key = array_search($acc_id, $checked);