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 CompanyProfileMigration extends BaseMigration {
  public function __construct($arguments) {
    $this->description = t('Company Profiles.');      

    $this->map = new MigrateSQLMap($this->machineName,
        array('uid' => array(
                'type' => 'int',
                'not null' => TRUE,
                'description' => 'ID.'

    // Connect to the remote $databases
    $query = db_select(TYPO3_DATABASE_NAME.TABLENAME, '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('uid', 'fe_user')->sourceMigration('SwMigrateFeUser');

    // field_company_image
    $this->addFieldMapping('field_company_image', 'image')

    $this->addFieldMapping('created', 'crdate');
    $this->addFieldMapping('changed', 'crdate');


    // Back to local database again!


The class that import images is called "CompanyProfileLogoMigration" that's why I added the source migration when mapping the image field :

$this->addFieldMapping('field_company_image', 'image')->sourceMigration('CompanyProfileImage');

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.

  • what value is logo, is it a file_id? – sam2de Aug 25 '15 at 16:28
  • no it's the 'filename' exp: my_image_name.png – Boussetta moez Aug 26 '15 at 7:18
  • I think this is the problem, it should expect the id that you used in the images migration, look into the images migration mapping table and see what you use there. – sam2de Aug 26 '15 at 13:37
  • the image mapping table is the same as the company profile table "tx_exinitjobexchange_profiles" , I get the name of the logo from this table, then search on it inside the 'source_dir' then it import them... So the ID of each image entry is the same ID of the companyProfile (they are in the same table) – Boussetta moez Aug 26 '15 at 14:04
  • 1
    try to use the id in your mapping and see how it goes: $this->addFieldMapping('field_company_image', 'companyProfile_ID') ->sourceMigration('SwMigrateCompanyProfileLogo');. Migration with look the companyProfile ID in the mapping table and return the Drupal file id. Give it a shot – sam2de Aug 26 '15 at 14:17

Your Answer

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

Browse other questions tagged or ask your own question.