Would be great to have native support for uploads added to nodes using the core D6 Upload module.
My current solution:
abstract class CustomNodeMigration extends DrupalNode6Migration {
public function __construct(array $arguments) {
$this->sourceFields += array(
'attachements_filename' => t('Attachments File Names from D6'),
'attachements_filepath' => t('Attachments File Paths from D6'),
'attachements_description' => t('Attachments Description'),
'attachements_display' => t('Attachments Display Option'),
);
parent::__construct($arguments);
$this->addFieldMapping('field_attachments', 'attachements_filepath');
$this->addFieldMapping('field_attachments:file_class')->defaultValue('MigrateFileUri');
$this->addFieldMapping('field_attachments:file_replace')->defaultValue('FILE_EXISTS_REUSE');
$this->addFieldMapping('field_attachments:preserve_files')->defaultValue(FALSE);
$this->addFieldMapping('field_attachments:source_dir')->defaultValue('files2migrate');
$this->addFieldMapping('field_attachments:description', 'attachements_description');
$this->addFieldMapping('field_attachments:display', 'attachements_display');
}
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
$row->attachements_fid = array();
$row->attachements_filename = array();
$row->attachements_filepath = array();
$row->attachements_description = array();
$row->attachements_display = array();
$connection = Database::getConnection('default', $this->sourceConnection);
$query = $connection->select('upload', 'up');
$query->condition('up.vid', $row->vid);
$query->fields('up', array('fid', 'description', 'list', 'weight'));
$query->leftJoin('files', 'f', 'up.fid = f.fid');
$query->fields('f', array('filename', 'filepath'));
$results = $query->execute();
foreach ($results as $result) {
$result->filepath = str_replace("sites/default/files/","",$result->filepath);
$row->attachements_fid[] = $result->fid;
$row->attachements_filename[] = $result->filename;
$row->attachements_filepath[] = $result->filepath;
$row->attachements_description[] = $result->description;
$row->attachements_display[] = $result->list;
}
}
}
Comments
Comment #1
Miro Goepel commentedThumbs up!
This needs to be included.
Comment #2
alforddm commentedWill this work for comment upload as well?
Comment #3
alforddm commentedTo answer my own question...Yes it does work for the comment upload module as well. I just had to change "field_attachments" to my comment attachment field, the database table from upload to comment_upload and changed vid to cid. It worked great! Thanks so much!
Comment #4
fredcy commentedThis is great! I've been trying to figure out how to do exactly this. This would be a useful addition to migrate_d2d.
Comment #5
rooby commentedThis is definitely needed.
Is there a reason why attachments is often misspelled as attachements?
Comment #6
mikeryanOK, I've added support for the upload module - if the upload table is present and the source node type has attachments enabled, source fields upload (corresponding to upload.fid), description, list, and weight are exposed as mappable fields.
Comment #8
dasginganinjaOh MikeRyan, I might have a case for you to look at!
Migration failed with source plugin exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd6_goodshep_sand.upload' doesn't exist
This is using the latest dev versions of migrate, migrate_extras, migrate_d2d. Below I have included my class used and the definition I send to Migrate::register().
Thanks in advance!