Changeset 2678


Ignore:
Timestamp:
Oct 7, 2008, 1:08:11 AM (16 years ago)
Author:
plg
Message:

feature 884 added: ability to delete photos uploaded via web API method
pwg.images.add, ie without storage_category_id. pLoader uses this method and
photos cannot be removed in any other way.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r2576 r2678  
    4141
    4242// +-----------------------------------------------------------------------+
     43// |                         deletion form submission                      |
     44// +-----------------------------------------------------------------------+
     45
     46if (isset($_POST['delete']))
     47{
     48  if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
     49  {
     50    $collection = array();
     51
     52    switch ($_POST['target_deletion'])
     53    {
     54      case 'all' :
     55      {
     56        $collection = $page['cat_elements_id'];
     57        break;
     58      }
     59      case 'selection' :
     60      {
     61        if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
     62        {
     63          array_push($page['errors'], l10n('Select at least one picture'));
     64        }
     65        else
     66        {
     67          $collection = $_POST['selection'];
     68        }
     69        break;
     70      }
     71    }
     72
     73    // filter selection on photos that have no storage_category_id (ie that
     74    // were added via pLoader)
     75    if (count($collection) > 0)
     76    {
     77      $query = '
     78SELECT
     79    id
     80  FROM '.IMAGES_TABLE.'
     81  WHERE id IN ('.implode(',', $collection).')
     82    AND storage_category_id IS NULL
     83;';
     84      $deletables = array_from_query($query, 'id');
     85
     86      if (count($deletables) > 0)
     87      {
     88        // what will be the categories to update? (to avoid orphan on
     89        // representative_picture_id)
     90        $query = '
     91SELECT
     92    category_id
     93  FROM '.IMAGE_CATEGORY_TABLE.'
     94  WHERE image_id IN ('.implode(',', $deletables).')
     95;';
     96        $categories_to_update = array_from_query($query, 'category_id');
     97         
     98        $physical_deletion = true;
     99        delete_elements($deletables, $physical_deletion);
     100
     101        update_category($categories_to_update);
     102
     103        array_push(
     104          $page['infos'],
     105          sprintf(
     106            l10n_dec(
     107              '%d photo was deleted',
     108              '%d photos were deleted',
     109              count($deletables)
     110              ),
     111            count($deletables)
     112            )
     113          );
     114      }
     115      else
     116      {
     117        array_push($page['errors'], l10n('No photo can be deleted'));
     118      }
     119    }
     120  }
     121  else
     122  {
     123    array_push($page['errors'], l10n('You need to confirm deletion'));
     124  }
     125}
     126
     127// +-----------------------------------------------------------------------+
    43128// |                       global mode form submission                     |
    44129// +-----------------------------------------------------------------------+
     
    236321
    237322$template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
     323
     324// +-----------------------------------------------------------------------+
     325// |                            deletion form                              |
     326// +-----------------------------------------------------------------------+
     327
     328// we can only remove photos that have no storage_category_id, in other
     329// word, it currently (Butterfly) means that the photo was added with
     330// pLoader
     331if (count($page['cat_elements_id']) > 0)
     332{
     333  $query = '
     334SELECT
     335    COUNT(*)
     336  FROM '.IMAGES_TABLE.'
     337  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
     338    AND storage_category_id IS NULL
     339;';
     340  list($counter) = mysql_fetch_row(pwg_query($query));
     341
     342  if ($counter > 0)
     343  {
     344    $template->assign('show_delete_form', true);
     345  }
     346}
    238347
    239348// +-----------------------------------------------------------------------+
  • trunk/admin/include/functions.php

    r2646 r2678  
    128128//    - all the links between categories and elements
    129129//    - all the favorites associated to elements
    130 function delete_elements($ids)
     130function delete_elements($ids, $physical_deletion=false)
    131131{
    132132  if (count($ids) == 0)
     
    135135  }
    136136  trigger_action('begin_delete_elements', $ids);
     137
     138  if ($physical_deletion)
     139  {
     140    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     141   
     142    // we can currently delete physically only photo with no
     143    // storage_category_id (added via pLoader)
     144    //
     145    // we assume that the element is a photo, with no representative
     146    $query = '
     147SELECT
     148    id,
     149    path,
     150    tn_ext,
     151    has_high
     152  FROM '.IMAGES_TABLE.'
     153  WHERE id IN ('.implode(',', $ids).')
     154    AND storage_category_id IS NULL
     155;';
     156    $result = pwg_query($query);
     157    while ($row = mysql_fetch_assoc($result))
     158    {
     159      $file_path = $row['path'];
     160      $thumbnail_path = get_thumbnail_path($row);
     161      $high_path = null;
     162      if (isset($row['has_high']) and get_boolean($row['has_high']))
     163      {
     164        $high_path = get_high_path($row);
     165      }
     166
     167      foreach (array($file_path, $thumbnail_path, $high_path) as $path)
     168      {
     169        if (isset($path) and !unlink($path))
     170        {
     171          die('"'.$path.'" cannot be removed');
     172        }
     173      }
     174    }
     175  }
    137176
    138177  // destruction of the comments on the image
  • trunk/admin/template/goto/element_set_global.tpl

    r2632 r2678  
    6666  </fieldset>
    6767
     68  {if $show_delete_form}
     69  <fieldset>
     70    <legend>{'Deletions'|@translate}</legend>
     71    <p style="font-style:italic">{'Note: Only deletes photos added with pLoader'|@translate}</p>
     72    <p>
     73      {'target'|@translate}
     74      <label><input type="radio" name="target_deletion" value="all" /> {'all'|@translate}</label>
     75      <label><input type="radio" name="target_deletion" value="selection" checked="checked" /> {'selection'|@translate}</label>
     76    </p>
     77    <p>
     78    <label><input type="checkbox" name="confirm_deletion" value="1" /> {'confirm'|@translate}</label>
     79    <input class="submit" type="submit" value="{'Delete selected photos'|@translate}" name="delete" {$TAG_INPUT_ENABLED}/>
     80    </p>
     81  </fieldset>
     82  {/if}
     83
    6884  <fieldset>
    6985
  • trunk/language/en_UK/admin.lang.php

    r2658 r2678  
    640640$lang['Unable to retrieve server informations since allow_url_fopen is disabled.'] = 'Unable to retrieve server informations since allow_url_fopen is disabled.';
    641641$lang['Quick Local Synchronization'] = 'Quick Local Synchronization';
     642$lang['No photo can be deleted'] = 'No photo can be deleted';
     643$lang['Note: Only deletes photos added with pLoader'] = 'Note: Only deletes photos added with pLoader';
     644$lang['Delete selected photos'] = 'Delete selected photos';
     645$lang['%d photo was deleted'] = '%d photo was deleted';
     646$lang['%d photos were deleted'] = '%d photos were deleted';
    642647?>
  • trunk/language/fr_FR/admin.lang.php

    r2658 r2678  
    639639$lang['Unable to retrieve server informations since allow_url_fopen is disabled.'] = 'Impossible de se connecter au server car la fonction allow_url_fopen est désactivée.';
    640640$lang['Quick Local Synchronization'] = 'Synchronisation Rapide';
     641$lang['No photo can be deleted'] = 'Aucune photo ne peut être supprimée';
     642$lang['Note: Only deletes photos added with pLoader'] = 'Note: seules les photos ajoutées via pLoader peuvent être supprimées';
     643$lang['Delete selected photos'] = 'Supprimer les photos';
     644$lang['%d photo was deleted'] = '%d photo a été supprimée';
     645$lang['%d photos were deleted'] = '%d photos ont été supprimées';
    641646?>
Note: See TracChangeset for help on using the changeset viewer.