When a user deletes a file using IMCE that was associated with a gallery, the corresponding gallery entry row in the IMCE_gallery_items table is not deleted. This leads to the galleries showing little red 'x's where the pics used to be.

Comments

ernst’s picture

I have also this problem !!!!!!1

Some one out there that got a solution??

sdsheridan’s picture

I had to get this fixed in a hurry, so wound up hacking the imce.module code:

function imce_delete_file($set, $filename) {
  if (file_delete($set->dir.'/'.$filename)) {
    // Added the following to remove row from imce_gallery_items as well
    if (db_table_exists("{imce_gallery_items}")) { // if table exists, then imce_gallery is installed, need to clean up this table

      $del_imce_gall_item_row = "DELETE FROM {imce_gallery_items} WHERE uid = %d AND g_file_name = '%s'";

      $res_del = db_query( $del_imce_gall_item_row, $set->uid, $filename );

      if ( $res_del ) {
        if ( db_affected_rows() > 0 ) {
          drupal_set_message(t('File and gallery reference deleted successfully.'));
        }
        else {
          drupal_set_message(t('File deleted successfully.'));
        }
        $returnValue = TRUE;
      }
      else {
        drupal_set_message(t('Error deleting file. File gone but gallery listing remains.'), 'error');
        watchdog('imce', t( 'imce_delete_file failed to delete imce_gallery entry. uid:' . $set->uid . ', file:' . $filename . ', db_query result:' . $res_del . ', db_error:' . db_error() . ', affected rows:' . db_affected_rows()), WATCHDOG_ERROR);
        $returnValue = FALSE;
      }

    }

    // adjusted the following code to make more structured

    else {
      drupal_set_message(t('File deleted successfully.'));
      $returnValue = TRUE;
    }
  }
  else {
    drupal_set_message(t('Error deleting file.'), 'error');
    $returnValue = FALSE;
  }

  return $returnValue;
}

I'm not that happy with this solution as now I've introduced a dependency between the two modules I didn't really want. But I've not had time to figure out how to do it otherwise, although I'm sure there's a way. If anyone else has any suggestions, by all means, please do let me know.

shawn