Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi all,
I have to migrate a folder of images in media images in my new site.
The problem is that I don't have a sql, or json or xml source, simply I have an array containing all images filenames.
Please can you suggest me what kind of migrate source class I have to use?
Here's what I did:
class myImagesMigration extends myMigration {
public function __construct() {
parent::__construct();
$this->description = t('Embedded images in articles body');
$this->map = new MigrateSQLMap($this->machineName,
array(
'filename' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Image filename',
)
),
MigrateDestinationMedia::getKeySchema()
);
// Source fields:.
$fields = array(
'filename' => t('Image filename, relative to the source directory'),
);
// All source images were previous copied in a defined folder:
$dir_path = '/var/www/mysite/sites/default/files/old_server/source_files';
// source folder contains only .jpg files: grab all image names with scandir:
$images = array_diff(scandir($dir_path), array('..', '.'));
$this->source = new Migrate...... ($images); <= WHAT MIGRATE SOURCE?!?!?!**********************
$this->destination = new MigrateDestinationMedia('image');
$this->addFieldMapping('source_dir')
->defaultValue($dir_path);
$this->addFieldMapping('value', 'filename');
$this->addFieldMapping('uid')
->defaultValue(1);
$this->addUnmigratedDestinations(array('field_image_description:format',
'field_image_description:language', 'destination_dir', 'destination_file',
'file_replace', 'preserve_files', 'timestamp'));
}
}
Thank you very much for helping me
Comments
Comment #1
dropfen CreditAttribution: dropfen commentedWhy are you trying to use Migrate for this case. As I understood, you want create just file objects managed by media, right? Maybe it's better to use something like this...
http://drupal.org/project/bulk_media_upload
Comment #2
MXTThank you for your suggestion dropfen, but
Because:
Does someone have any idea to resolve what I'm asking ?
Thank you very much
Comment #3
mikeryanIf you really want to literally use a memory array as a source, then that would require implementing a source class that would accept the array and iterate over it (which would actually be about just about the simplest source class possible, but no one's done that yet).
However, what you're really trying to do is to process files in a directory, you can use MigrateListFiles and MigrateItemFile (see plugins/sources/files.inc). I haven't used them myself (they were a community contribution), but I think you should be able to encapsulate the directory listing in MigrateListFiles and reference the individual file names in MigrateItemFile.
Comment #4
mikeryanNo further response.