1

I've a large amount of files to be migrated, stored in a folder under my Drupal root folder. My source schema is a Mysql table like this:

id (PK)
dmname
dmfilename
tid
dmdate_published

I want to store them like entities of type 'file' and bundle 'document' and they will be not attached to nodes. The bundle document has a taxonomy custom field.

I wrote this migration class in a Migrate custom module:

class TabellaDocmanMigration extends Migration {
    public function __construct(array $arguments = array())
    {
        parent::__construct($arguments);
        $this->description = t('Migrazione base dati componente Docman di Joomla.');
        $query = db_select('jos_docman', 'j')
            ->fields('j', array(
                'id',
                'dmname',
                'dmfilename',
            ));
        $query->addExpression("UNIX_TIMESTAMP(dmdate_published)", 'dmdate_published');
        $query->innerJoin('docman_pivot', 'd', 'd.id_docman = j.catid');
        $query->fields('d', array('tid'));
        $query->condition('published', 1, '=');
        $query->condition('approved', 1, '=');
        $query->orderBy('id', 'DESC');
        $query->range(0,2);
        $this->source = new MigrateSourceSQL($query);
        $this->destination = new MigrateDestinationFile('document');
        $this->map = new MigrateSQLMap($this->machineName,
            array(
                'id' => array(
                    'type' => 'int',
                    'not null' => true,
                    'description' => 'ID del file originale',
                ),
            ),
            MigrateDestinationFile::getKeySchema()
        );

        // My source directory
        $this->addFieldMapping('source_dir')
            ->defaultValue('sites/default/files/dmdocuments');

        // My source file.
        $this->addFieldMapping('value', 'dmfilename');

        // My destination.
        $this->addFieldMapping('destination_dir')
            ->defaultValue('public://media-root');
        $this->addFieldMapping('destination_file', 'dmfilename');

        // My fields
        $this->addFieldMapping('timestamp', 'dmdate_published');
        $this->addFieldMapping('field_folder', 'tid');
        $this->addFieldMapping('field_folder:source_type')
            ->defaultValue('tid');

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

        $this->addFieldMapping('preserve_files')->defaultValue(FALSE);
        $this->addFieldMapping('pathauto')->defaultValue(0);

    }
}

The class works well but I can't migrate file name (as title). Ex:

id (PK) -> 842
dmname -> My file name like a title
dmfilename -> my_file_uri.pdf
tid -> 18
dmdate_published -> 1486371655

How can I solve this?

Thanks

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.