I want to migrate external database table (not of a drupal website) to node destination having the content type : 'company_profile'
the migration is done except the image field witch has the machine name 'field_company_image'.
this is the class :
class SwMigrateCompanyProfileMigration extends BaseMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Company Profiles (tx_exinitjobexchange_profiles).');
// Add remote database connection
Database::addConnectionInfo('sw_typo3', 'default', array(
'driver' => 'mysql',
'database' => TYPO3_DATABASE_NAME,
'username' => TYPO3_DATABASE_USERNAME,
'password' => TYPO3_DATABASE_PASS,
'host' => TYPO3_DATABASE_HOST,
'port' => '3306',
'prefix' => '',
));
// Active connection to the database
db_set_active('sw_typo3');
$this->map = new MigrateSQLMap($this->machineName,
array('uid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'tx_exinitjobexchange_profiles ID.'
)
),
MigrateDestinationNode::getKeySchema(),
'sw_typo3'
);
// Connect to the remote $databases
$query = Database::getConnection('default', 'sw_typo3')
->select(TYPO3_DATABASE_NAME.'.tx_exinitjobexchange_profiles', 'cp')
->fields('cp', $this->queryParams['company_profile']['fields'])
->orderBy($this->queryParams['company_profile']['order_field'], $this->queryParams['company_profile']['order_field_operator']);
$query->condition('cp.fe_user', 0, '<>');
// Define source and destination for migration
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationNode('company_profile');
/*** Make the mappings ***/
$this->addFieldMapping('title', 'company');
$this->addFieldMapping('is_new')->defaultValue(TRUE);
// uid field
$this->addFieldMapping('uid', 'fe_user')->sourceMigration('SwMigrateFeUser');
// field_company_image
$this->addFieldMapping('field_company_image', 'logo')
->sourceMigration('SwMigrateCompanyProfileLogo');
$this->addFieldMapping('field_company_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_company_image:language')
->defaultValue('de');
$this->addFieldMapping('created', 'crdate');
$this->addFieldMapping('changed', 'crdate');
$this->addFieldMapping('status')->defaultValue(1);
$this->addFieldMapping('promote')->defaultValue(0);
$this->addFieldMapping('sticky')->defaultValue(0);
$this->addFieldMapping('language')->defaultValue('de');
$this->addFieldMapping('path')->issueGroup(t('DNM'));
$this->addFieldMapping('comment')->issueGroup(t('DNM'));
// Back to local database again!
db_set_active('default');
}
}
The class that import images (logo) is called "SwMigrateCompanyProfileLogoMigration" that's why I added the source migration when mapping the image field :
$this->addFieldMapping('field_company_image', 'logo')->sourceMigration('SwMigrateCompanyProfileLogo');
And the migration of the image files are done succefully (I can see them inside default/files directory, also inside "file_managed" database table are succesfully inserted!)
But, when I edit the nodes I don't find the image field filled up (the table "field_data_field_company_image" is empty !)
How can I improve this class or what im missing to make this relationship working ?
Thanks in advance.