Changeset 6873 for trunk/admin/include
- Timestamp:
- Sep 9, 2010, 10:10:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r6664 r6873 132 132 // - all the links between categories and elements 133 133 // - all the favorites associated to elements 134 // @return number of deleted elements 134 135 function delete_elements($ids, $physical_deletion=false) 135 136 { 136 137 if (count($ids) == 0) 137 138 { 138 return ;139 return 0; 139 140 } 140 141 trigger_action('begin_delete_elements', $ids); … … 143 144 { 144 145 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 145 146 // we can currently delete physically only photo with no 147 // storage_category_id (added via pLoader) 148 // 149 // we assume that the element is a photo, with no representative 146 $new_ids=array(); 147 150 148 $query = ' 151 149 SELECT … … 153 151 path, 154 152 tn_ext, 155 has_high 153 has_high, 154 representative_ext 156 155 FROM '.IMAGES_TABLE.' 157 156 WHERE id IN ('.implode(',', $ids).') 158 AND storage_category_id IS NULL159 157 ;'; 160 158 $result = pwg_query($query); 161 159 while ($row = pwg_db_fetch_assoc($result)) 162 160 { 163 $file_path = $row['path']; 164 $thumbnail_path = get_thumbnail_path($row); 165 $high_path = null; 166 if (isset($row['has_high']) and get_boolean($row['has_high'])) 161 if (url_is_remote($row['path'])) 162 continue; 163 $files = array(); 164 $files[] = get_element_path($row); 165 if (!empty($row['tn_ext'])) 166 $files[] = get_thumbnail_path($row); 167 if (!empty($row['has_high']) and get_boolean($row['has_high'])) 168 $files[] = get_high_path($row); 169 if (!empty($row['representative_ext'])) 167 170 { 168 $high_path = get_high_path($row); 171 $pi = pathinfo($row['path']); 172 $file_wo_ext = get_filename_wo_extension($pi['basename']); 173 $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$element_info['representative_ext']; 169 174 } 170 175 171 foreach (array($file_path, $thumbnail_path, $high_path) as $path) 176 $ok = true; 177 foreach ($files as $path) 172 178 { 173 if (is set($path) and is_file($path) and !unlink($path))179 if (is_file($path) and !unlink($path)) 174 180 { 175 die('"'.$path.'" cannot be removed'); 181 $ok = false; 182 trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING); 183 break; 176 184 } 177 185 } 186 if ($ok) 187 $new_ids[] += $row['id']; 188 else 189 break; 190 } 191 $ids = $new_ids; 192 if (count($ids)==0) 193 { 194 return 0; 178 195 } 179 196 } … … 250 267 251 268 trigger_action('delete_elements', $ids); 269 return count($ids); 252 270 } 253 271
Note: See TracChangeset
for help on using the changeset viewer.