Changeset 6873


Ignore:
Timestamp:
09/09/10 22:10:50 (9 years ago)
Author:
rvelices
Message:

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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r6363 r6873  
    7878    } 
    7979 
    80     // filter selection on photos that have no storage_category_id (ie that 
    81     // were added via pLoader) 
    8280    if (count($collection) > 0) 
    8381    { 
    84       $query = ' 
    85 SELECT 
    86     id 
    87   FROM '.IMAGES_TABLE.' 
    88   WHERE id IN ('.implode(',', $collection).') 
    89     AND storage_category_id IS NULL 
    90 ;'; 
    91       $deletables = array_from_query($query, 'id'); 
    92  
    93       if (count($deletables) > 0) 
    94       { 
    95         $physical_deletion = true; 
    96         delete_elements($deletables, $physical_deletion); 
    97  
     82      $deleted_count = delete_elements($collection, true); 
     83      if ($deleted_count > 0) 
     84      { 
    9885        array_push( 
    9986          $page['infos'], 
     
    10289              '%d photo was deleted', 
    10390              '%d photos were deleted', 
    104               count($deletables) 
     91              $deleted_count 
    10592              ), 
    106             count($deletables) 
     93            $deleted_count 
    10794            ) 
    10895          ); 
     
    322309// +-----------------------------------------------------------------------+ 
    323310 
    324 // we can only remove photos that have no storage_category_id, in other 
    325 // word, it currently (Butterfly) means that the photo was added with 
    326 // pLoader 
     311// we can only remove photos that are not remote 
    327312if (count($page['cat_elements_id']) > 0) 
    328313{ 
     
    332317  FROM '.IMAGES_TABLE.' 
    333318  WHERE id IN ('.implode(',', $page['cat_elements_id']).') 
    334     AND storage_category_id IS NULL 
     319    AND path NOT LIKE "http%" 
    335320;'; 
    336321  list($counter) = pwg_db_fetch_row(pwg_query($query)); 
  • 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 
  • trunk/admin/themes/default/template/element_set_global.tpl

    r6587 r6873  
    8686  <fieldset> 
    8787    <legend>{'Deletions'|@translate}</legend> 
    88 {if $ENABLE_SYNCHRONIZATION} 
    89     <p style="font-style:italic">{'Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'|@translate}</p> 
    90 {/if} 
    9188    <p> 
    9289      {'target'|@translate} 
  • trunk/language/en_UK/admin.lang.php

    r6698 r6873  
    607607$lang['Quick Local Synchronization'] = "Quick Local Synchronization"; 
    608608$lang['No photo can be deleted'] = "No photo can be deleted"; 
    609 $lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization."; 
    610609$lang['Delete selected photos'] = "Delete selected photos"; 
    611610$lang['%d photo was deleted'] = "%d photo deleted"; 
  • trunk/language/fr_CA/admin.lang.php

    r6676 r6873  
    618618$lang['Quick Local Synchronization'] = "Synchronisation rapide"; 
    619619$lang['No photo can be deleted'] = "Aucune photo ne peut être supprimée"; 
    620 $lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note : Cette suppression des photos ne s'applique pas pour les photos ajoutées à l'aide de la synchronisation (méthode classique par chargement FTP). Pour ces photos, supprimez-les de votre serveur et refaites une synchronisation."; 
    621620$lang['Delete selected photos'] = "Supprimer les photos sélectionnées"; 
    622621$lang['%d photo was deleted'] = "%d photo a été supprimée"; 
  • trunk/language/fr_FR/admin.lang.php

    r6736 r6873  
    608608$lang['Quick Local Synchronization'] = "Synchronisation Rapide"; 
    609609$lang['No photo can be deleted'] = "Aucune photo ne peut être supprimée"; 
    610 $lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note : Cette suppression des photos ne s'applique pas pour les photos ajoutées à l'aide de la synchronisation (méthode classique par chargement FTP). Pour ces photos, supprimez-les de votre serveur et refaites une synchronisation."; 
    611610$lang['Delete selected photos'] = "Supprimer les photos sélectionnées"; 
    612611$lang['%d photo was deleted'] = "%d photo a été supprimée"; 
  • trunk/language/hu_HU/admin.lang.php

    r6676 r6873  
    602602$lang['Quick Local Synchronization'] = 'Helyi szinkronizálás'; 
    603603$lang['No photo can be deleted'] = 'Nincs törölhető kép'; 
    604 $lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Megjegyzés: a képek törlése nem vonatkozik a szinkronizálással hozzáadott képekre. A szinkronizálással hozzáadott képeket törölni kell a fájlrendszerből, majd ismételt szinkronizálás szükséges."; 
    605604$lang['Delete selected photos'] = 'Kijelölt képek törlése'; 
    606605$lang['%d photo was deleted'] = '%d kép törölve'; 
  • trunk/language/pl_PL/admin.lang.php

    r6676 r6873  
    753753$lang['Who can see this photo?'] = 'Kto może oglądać o zdjęcie?'; 
    754754$lang['Pending Comments'] = 'Oczekujące komentarze'; 
    755 $lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = 'Info: usunięcie zdjęcia nie dotyczy zdjęć dodanych podczas synchroniazacji. Zdjęcia dodanew ten sposób należy usunąć z systemu plików, a następnie wykonać synchronizację.'; 
    756755$lang['In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'] = 'W twoim pliku php.ini, parametr upload_max_filesize (%sB) jest większy niż post_max_size (%sB), powinieneś zmienić toe ustawienia'; 
    757756$lang['Exif extension not available, admin should disable exif use'] = 'Rozszerzenie exif jest nie dostępne, administrato powinien usunąć korzystanie z exif'; 
Note: See TracChangeset for help on using the changeset viewer.