See error message image (attached)

With some trial and error I was able to fix this by adding some code to check to see if the uri already existed in the filed_managed table, and if so copy & rename the file and then add the access to the image

So from line 207.... I added the $test query and if statement (with the else surrounding the original insert portion of the file.

      // We will convert filepaths to uri using the default scheme
      // and stripping off the existing file directory path.
      $file->uri = $scheme . str_replace($basename, '', $file->filepath);
      $file->uri = file_stream_wrapper_uri_normalize($file->uri);
      unset($file->filepath);
      
      //test to see if uri already exists - if so rename and insert a new record
      $test = db_query('SELECT n.fid
      			FROM {file_managed} n WHERE n.uri = :uri', array(':uri' => $file->uri));
      
      if($test->rowCount()>0){
      	$file = file_copy($file, $destination = 'public://images/', $replace = FILE_EXISTS_RENAME);
      }
      
      //otherwise save this file 
	  else{
      // Insert into the file_managed table.
      // Each fid should only be stored once in file_managed.
      db_merge('file_managed')
        ->key(array(
          'fid' => $file->fid,
        ))
        ->fields(array(
          'uid' => $file->uid,
          'filename' => $file->filename,
          'uri' => $file->uri,
          'filemime' => $file->filemime,
          'filesize' => $file->filesize,
          'status' => $file->status,
          'timestamp' => $file->timestamp,
        ))
        ->execute();
	}
      // Add the usage entry for the file.
      file_usage_add($file, 'file', 'node', $nid);
      break;

it fixed the issue for me without losing any of the files and also the content migration was able to complete without error messages

Comments

akalam’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new2.76 KB

Patch attached

damienmckenna’s picture

Status: Needs review » Needs work
Parent issue: » #1277262: Plan for CCK 7.x-3.0 release

Needs updating per the Drupal coding standards.