You are here

function photos_file_del in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 photos.module \photos_file_del()

Photos - image removal.

3 calls to photos_file_del()
photos_editlist_submit in inc/photos.edit.inc
Submit modifications to existing images.
photos_edit_confirm_delete_submit in inc/photos.edit.inc
Submit confirm delete photo.
photos_node_delete in ./photos.module
Implements hook_node_delete().

File

./photos.module, line 1497
Implementation of photos.module.

Code

function photos_file_del($fid, $filepath = 0, $count = 0) {
  if (!$filepath) {
    if ($count) {
      $file = file_load($fid);
      $file->pid = db_select('photos_image', 'p')
        ->fields('p', array(
        'pid',
      ))
        ->condition('fid', $fid)
        ->execute()
        ->fetchField();
      $filepath = $file->uri;
    }
    else {
      $filepath = db_query('SELECT uri FROM {file_managed} WHERE fid = :fid', array(
        ':fid' => $fid,
      ))
        ->fetchField();
    }
  }
  if ($filepath) {
    if (variable_get('photos_comment', 0)) {
      $result = db_select('photos_comment', 'v')
        ->fields('v', array(
        'cid',
      ))
        ->condition('v.fid', $fid)
        ->execute();
      foreach ($result as $cids) {
        comment_delete($cids->cid);
      }
    }
    db_delete('photos_image')
      ->condition('fid', $fid)
      ->execute();
    db_delete('photos_node')
      ->condition('fid', $fid)
      ->execute();
    db_delete('photos_comment')
      ->condition('fid', $fid)
      ->execute();
    if ($count) {
      photos_set_count('node_node', $file->pid);
      photos_set_count('node_album', $file->pid);
      photos_set_count('user_image', $file->uid);
      if (module_exists('comment')) {
        _comment_update_node_statistics($file->pid);
      }
    }
    if (empty($file)) {
      $file = file_load($fid);
    }
    if (empty($file->pid)) {
      $file->pid = db_select('photos_image', 'p')
        ->fields('p', array(
        'pid',
      ))
        ->condition('fid', $file->fid)
        ->execute()
        ->fetchField();
    }
    file_usage_delete($file, 'photos', 'node', $file->pid);
    file_delete($file);
    return TRUE;
  }
  else {
    return FALSE;
  }
}