Localizer node copy adding new images, old will be deleted

Jurjen de Vries - November 27, 2007 - 22:51
Project:Localizer
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

1. CCK version = 5.x-1.6-1
2. imagefield version = 5.x.-1.1
3. permissions for your tmp and files directory. = 777
4. download method = public
5. imagefield configuration = can't find config
6. expected results = not to delete an image that was added into another node
7. the unexpected actual results =

I'm using Localizer for translations of nodes. When I was creating a new node with language Dutch I've added an image. After that I made a copy of the node to a new node with the localizer function 'create translation'. Because the image is a little difference for each country (every country had some local text into the image eg. 'nieuw' / 'new') I've to replace the image at the new created node. After uploading the new image (without deleting the other), the old file was deleted from the server. Even when the old image was linked from the other node language.

8. Steps to reproduce the problem.
Install localizer module ( http://drupal.org/project/localizer ), create 2 languages, create a copy of a node with an image and replace the image with a new one at the copy of the node.

#1

dopry - December 18, 2007 - 04:36
Project:ImageField» Localizer
Version:5.x-1.1» 5.x-1.x-dev

I don't know anything about localizer... As far as I know imagefield work fine, even with revisions. This is probably something that isn't supported by localizer.

#2

satish.c.ayappan - November 21, 2008 - 06:12

I am also having the same issue, trying to find out a solution

#3

satish.c.ayappan - November 21, 2008 - 11:09

Hi All,

Found a solution. patched the imagefield_file_insert function of imagefield.module

Add the following piece of code and tested on website

if(strstr($file['filepath'], file_create_path())) {
    $source= (object)$file;
    $dest=file_directory_temp() . '/' . $file['filename'];
    if(file_copy($source, $dest)) {
      $file['filepath']=$dest;
    }
  }

Here is the changed fucntion

function imagefield_file_insert($node, &$file, $field) {
  $fieldname = $field['field_name'];

  // allow tokenized paths.
  if (function_exists('token_replace')) {
    global $user;
    $widget_image_path = token_replace($field['widget']['image_path'],'user', $user);
  }
  else {
    $widget_image_path = $field['widget']['image_path'];
  }
 
  if(strstr($file['filepath'], file_create_path())) {
    $source= (object)$file;
    $dest=file_directory_temp() . '/' . $file['filename'];
    if(file_copy($source, $dest)) {
      $file['filepath']=$dest;
    }
  }
 
  $filepath = file_create_path($widget_image_path) . '/' . $file['filename'];

  if (imagefield_check_directory($widget_image_path) && $file = file_save_upload((object)$file, $filepath)) {
    $file = (array)$file;
    $file['fid'] = db_next_id('{files}_fid');
    db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)
             VALUES (%d, %d, '%s','%s','%s',%d)",
            $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
    module_invoke_all('imagefield_file', 'save', $file);
    return (array)$file;
  }
  else {
    // Include file name in upload error.
    form_set_error(NULL, t('Image upload was unsuccessful.'));
    return FALSE;
  }
}

Hope this will help everybody, who has this problem.

 
 

Drupal is a registered trademark of Dries Buytaert.