Ignore:
Timestamp:
Feb 11, 2011, 11:57:23 PM (13 years ago)
Author:
plg
Message:

feature 2189 added: ability to update a photo (the JPEG/PNG file) with
pwg.images.addSimple, simply by adding an $image_id as argument.

File:
1 edited

Legend:

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

    r8967 r9191  
    167167}
    168168
    169 // The function delete_elements deletes the elements identified by the
    170 // (numeric) values of the array $ids. It also deletes (in the database) :
    171 //    - all the comments related to elements
    172 //    - all the links between categories and elements
    173 //    - all the favorites associated to elements
    174 // @return number of deleted elements
    175 function delete_elements($ids, $physical_deletion=false)
     169// Deletes all files (on disk) related to given image ids
     170// @return image ids where files are deleted successfully
     171function delete_element_files($ids)
    176172{
    177173  if (count($ids) == 0)
     
    179175    return 0;
    180176  }
    181   trigger_action('begin_delete_elements', $ids);
    182 
    183   if ($physical_deletion)
    184   {
    185     include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    186     $new_ids=array();
    187 
    188     $query = '
     177
     178  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     179 
     180  $new_ids = array();
     181
     182  $query = '
    189183SELECT
    190184    id,
     
    196190  WHERE id IN ('.implode(',', $ids).')
    197191;';
    198     $result = pwg_query($query);
    199     while ($row = pwg_db_fetch_assoc($result))
    200     {
    201       if (url_is_remote($row['path']))
    202         continue;
    203       $files = array();
    204       $files[] = get_element_path($row);
    205       if (!empty($row['tn_ext']))
    206         $files[] = get_thumbnail_path($row);
    207       if (!empty($row['has_high']) and get_boolean($row['has_high']))
    208         $files[] = get_high_path($row);
    209       if (!empty($row['representative_ext']))
     192  $result = pwg_query($query);
     193  while ($row = pwg_db_fetch_assoc($result))
     194  {
     195    if (url_is_remote($row['path']))
     196    {
     197      continue;
     198    }
     199   
     200    $files = array();
     201    $files[] = get_element_path($row);
     202
     203    if (!empty($row['tn_ext']))
     204    {
     205      $files[] = get_thumbnail_path($row);
     206    }
     207   
     208    if (!empty($row['has_high']) and get_boolean($row['has_high']))
     209    {
     210      $files[] = get_high_path($row);
     211    }
     212   
     213    if (!empty($row['representative_ext']))
     214    {
     215      $pi = pathinfo($row['path']);
     216      $file_wo_ext = get_filename_wo_extension($pi['basename']);
     217      $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$row['representative_ext'];
     218    }
     219
     220    $ok = true;
     221    foreach ($files as $path)
     222    {
     223      if (is_file($path) and !unlink($path))
    210224      {
    211         $pi = pathinfo($row['path']);
    212         $file_wo_ext = get_filename_wo_extension($pi['basename']);
    213         $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$element_info['representative_ext'];
     225        $ok = false;
     226        trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING);
     227        break;
    214228      }
    215 
    216       $ok = true;
    217       foreach ($files as $path)
    218       {
    219         if (is_file($path) and !unlink($path))
    220         {
    221           $ok = false;
    222           trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING);
    223           break;
    224         }
    225       }
    226       if ($ok)
    227         $new_ids[] += $row['id'];
    228       else
    229         break;
    230     }
    231     $ids = $new_ids;
     229    }
     230   
     231    if ($ok)
     232    {
     233      $new_ids[] += $row['id'];
     234    }
     235    else
     236    {
     237      break;
     238    }
     239  }
     240  return $new_ids;
     241}
     242
     243// The function delete_elements deletes the elements identified by the
     244// (numeric) values of the array $ids. It also deletes (in the database) :
     245//    - all the comments related to elements
     246//    - all the links between categories and elements
     247//    - all the favorites associated to elements
     248// @return number of deleted elements
     249function delete_elements($ids, $physical_deletion=false)
     250{
     251  if (count($ids) == 0)
     252  {
     253    return 0;
     254  }
     255  trigger_action('begin_delete_elements', $ids);
     256
     257  if ($physical_deletion)
     258  {
     259    $ids = delete_element_files($ids);
    232260    if (count($ids)==0)
    233261    {
Note: See TracChangeset for help on using the changeset viewer.