1

Happy New Year everyone,

I am fairly new to the Migrate Module and have come to a halt concerning image migration. To begin with, my problem currently is that when I run my migration, drush outputs: "New object was not saved, no error provided".

Now all I want is to get the images relating to a specific content type (educational_activity) and copy them over to my destination folder.

CODE:

class EduActFile extends EduMigration {

public function __construct() {

parent::__construct();

#Define variable for the default user id (user="grammateia") wherever it is used (uid, revision_uid, etc.). 
$user=36;

// Describe the class for the Migrate UI

$this->description = t('Migrate files');



$query = Database::getConnection('default', 'migrationDB')
           ->select('node', 'n');
//$query->leftJoin('content_field_filename', 'fi', 'n.nid = fi.nid');
$query->leftJoin('content_field_images', 'fim', 'n.nid = fim.nid');
//$query->leftJoin('files', 'fil', 'fil.fid = fi.field_filename_fid');
$query->leftJoin('files', 'file', 'file.fid = fim.field_images_fid');
$query->fields('n')
      //->fields('fil', array('fid', 'filename', 'filepath', 'filemime', 'filesize', 'timestamp'))
      ->fields('file', array('fid', 'filename', 'filepath', 'filemime', 'filesize', 'timestamp'))
      ->condition('type', "educational_activity",'=')
      ->groupBy('n.nid');


$this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE));

// Specify that we want to create files from the source data

$this->destination = new MigrateDestinationFile('');

// Remember what source record created each destination object and track migration status and allow rollback with MigrateSQLMap class

$this->map = new MigrateSQLMap($this->machineName,
    array(
      'nid' => array('type' => 'int',
                       'not null' => TRUE,
                       'description' => 'Node ID',
                       'alias' => 'n'
                      )
    ),
  MigrateDestinationFile::getKeySchema()
);

$this->addUnmigratedSources(array ('fid','filepath', 'filemime', 'filesize', 'timestamp'), t('Source fields that we will not be migrating'));

$this->addUnmigratedDestinations (array('timestamp', 'destination_file'));

$this->addFieldMapping('uid')
  ->defaultValue($user);

// For each source row to be processed define data mappings to the destination field from source field

$this->addFieldMapping('value', 'filename');


// Specify the location of the source folder to find the files

$this->addFieldMapping('source_dir')
     ->defaultValue('C:/xampp/htdocs/protovoulia.org/sites/default/files');

// Specify the location of the destination folder to place the files

$this->addFieldMapping('destination_dir')
     ->defaultValue('C:/xampp/htdocs/testpaideia/sites/default/files/educational_activity');


// Use existing files

$this->addFieldMapping('file_replace')->defaultValue('FILE_EXISTS_REUSE');

// Ensure files are not deleted during rollback

$this->addFieldMapping('preserve_files')->defaultValue(TRUE);

}//construct ends

}

Do I need to use a different class to migrate files? Is my query wrong? Thanks in advance, your help will be greatly appreciated.

  • Is there anything helpful in watchdog? – Mike Crittenden Jan 4 '13 at 6:34
  • Unfortunately not, the watchdog logs regarding this migration only contain the generic error "New object was not saved, no error provided". I figured though that the image files that are assigned to the node instances I am checking have an fid value of "NULL" in the "content_field_images" table. I am guessing that is the culprit. – Jim Bidis Jan 4 '13 at 11:34
  • How about going to admin/content/migrate and seeing if the "messages" column has a link for that migration? I had the exact same problem yesterday and the messages page for that migration had more details about what was wrong (permissions issue in my case). – Mike Crittenden Jan 4 '13 at 15:21
  • I will investigate the permissions issue as soon as I have time thank you for the tip. – Jim Bidis Jan 7 '13 at 9:23
0

This has been answered by me in another question I made. It can be found here: Migrating Multiple Files in a Node

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.