Changeset 6873 for trunk/admin/include


Ignore:
Timestamp:
Sep 9, 2010, 10:10:50 PM (14 years ago)
Author:
rvelices
Message:

feature 1845 : be able to delete photos added through ftp synchronization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r6664 r6873  
    132132//    - all the links between categories and elements
    133133//    - all the favorites associated to elements
     134// @return number of deleted elements
    134135function delete_elements($ids, $physical_deletion=false)
    135136{
    136137  if (count($ids) == 0)
    137138  {
    138     return;
     139    return 0;
    139140  }
    140141  trigger_action('begin_delete_elements', $ids);
     
    143144  {
    144145    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
    150148    $query = '
    151149SELECT
     
    153151    path,
    154152    tn_ext,
    155     has_high
     153    has_high,
     154    representative_ext
    156155  FROM '.IMAGES_TABLE.'
    157156  WHERE id IN ('.implode(',', $ids).')
    158     AND storage_category_id IS NULL
    159157;';
    160158    $result = pwg_query($query);
    161159    while ($row = pwg_db_fetch_assoc($result))
    162160    {
    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']))
    167170      {
    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'];
    169174      }
    170175
    171       foreach (array($file_path, $thumbnail_path, $high_path) as $path)
     176      $ok = true;
     177      foreach ($files as $path)
    172178      {
    173         if (isset($path) and is_file($path) and !unlink($path))
     179        if (is_file($path) and !unlink($path))
    174180        {
    175           die('"'.$path.'" cannot be removed');
     181          $ok = false;
     182          trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING);
     183          break;
    176184        }
    177185      }
     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;
    178195    }
    179196  }
     
    250267
    251268  trigger_action('delete_elements', $ids);
     269  return count($ids);
    252270}
    253271
Note: See TracChangeset for help on using the changeset viewer.