Changeset 8265
- Timestamp:
- Dec 23, 2010, 9:48:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r8247 r8265 53 53 // The function delete_categories deletes the categories identified by the 54 54 // (numeric) key of the array $ids. It also deletes (in the database) : 55 // - all the elements ofthe category (delete_elements, see further)55 // - all the elements physically linked to the category (delete_elements, see further) 56 56 // - all the links between elements and this category 57 57 // - all the restrictions linked to the category 58 58 // The function works recursively. 59 function delete_categories($ids) 59 // 60 // the $photo_deletion_mode is for photos virtually linked to the categorty 61 // * no_delete : delete no photo, may create orphans 62 // * delete_orphans : delete photos that are no longer linked to any category 63 // * force_delete : delete photos even if they are linked to another category 64 function delete_categories($ids, $photo_deletion_mode='no_delete') 60 65 { 61 66 if (count($ids) == 0) … … 68 73 $ids = get_subcat_ids($ids); 69 74 70 // destruction of all the related elements75 // destruction of all photos physically linked to the category 71 76 $query = ' 72 77 SELECT id … … 82 87 } 83 88 delete_elements($element_ids); 89 90 // now, should we delete photos that are virtually linked to the category? 91 if ('delete_orphans' == $photo_deletion_mode or 'force_delete' == $photo_deletion_mode) 92 { 93 $query = ' 94 SELECT 95 DISTINCT(image_id) 96 FROM '.IMAGE_CATEGORY_TABLE.' 97 WHERE category_id IN ('.implode(',', $ids).') 98 ;'; 99 $image_ids_linked = array_from_query($query, 'image_id'); 100 101 if ('delete_orphans' == $photo_deletion_mode) 102 { 103 $query = ' 104 SELECT 105 DISTINCT(image_id) 106 FROM '.IMAGE_CATEGORY_TABLE.' 107 WHERE image_id IN ('.implode(',', $image_ids_linked).') 108 AND category_id NOT IN ('.implode(',', $ids).') 109 ;'; 110 $image_ids_not_orphans = array_from_query($query, 'image_id'); 111 $image_ids_to_delete = array_diff($image_ids_linked, $image_ids_not_orphans); 112 } 113 114 if ('force_delete' == $photo_deletion_mode) 115 { 116 $image_ids_to_delete = $image_ids_linked; 117 } 118 119 delete_elements($image_ids_to_delete, true); 120 } 84 121 85 122 // destruction of the links between images and this category
Note: See TracChangeset
for help on using the changeset viewer.