1

When trying to set up a migration, I can't seem to register new Migrations. When running drush migrate-status, I only see my User migration, even after a drush migrate-register.

My migrate.inc looks like this:

function module_migrate_api() {
    $api = array(
        'api' => 2,
        'migrations' => array(
            'User' => array(
                'class_name' => 'UserMigration'
            ),
            'News' => array(
                'class_name' => 'NewsMigration'
            ),
            'Activity' => array(
                'class_name' => 'ActivityMigration'
            )
        )
    );

    return $api;
}

And my module.inc file contains classes for each of these Migrations, based off of the UserMigration I wrote first (example given is UserMigration, which works, and NewsMigration, which does not work):

class UserMigration extends TestMigration {
    public function __construct($arguments) {
        parent::__construct($arguments);

        $this->description = t('Migrates users');

        $query = Database::getConnection('default', 'original')
            ->select('users')
            ->fields('users', array(
                'user_id',
                'username',
                'firstname',
                'lastname'
            ));
        $this->source = new MigrateSourceSQL($query);

        $options = array();
        $this->destination = new MigrateDestinationUser($options);

        $this->map = new MigrateSQLMap($this->machineName, array(
            'user_id' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'description' => t('Source ID')
            )
        ), MigrateDestinationNode::getKeySchema());
    }

class NewsMigration extends TestMigration {
    public function __construct($arguments) {
        parent::__construct($arguments);

        $this->description = t('Migrates news');

        $query = Database::getConnection('default', 'original')
            ->select('news')
            ->fields('news', array(
                'news_id',
                'user_id',
                'title',
                'text'
            ));
        $this->source = new MigrateSourceSQL($query);

        $options = array();
        $this->destination = new MigrateDestinationNode('news');

        $this->map = new MigrateSQLMap($this->machineName, array(
            'news_id' => array(
                'type' => 'int',
                'unsigned' => TRUE,
                'not null' => TRUE,
                'description' => t('Source ID')
            )
        ), MigrateDestinationNode::getKeySchema());

        /* $this->addFieldMapping('target', 'source'); */
    }
}

So far, I haven't added fieldmappings, since I want to set up everything that should be migrated first, to get a complete view of the work that's left.

When running drush migrate-register, I'm getting the following output:

All statically defined migrations have been (re)registered.                                                                                                                                         [success]

And a drush migrate-status gives me the following:

 Group: Test  Total  Imported  Unprocessed  Status  Last imported
 User         55     0         55           Idle    2015-12-03 13:40:30

So as you can see, no errors, not even when running with -v. But only User is recognized. Both classes are in the same file. Am I missing something simple?

3
  • Are you sure the first class is properly closed, I believe there an accolade '}' missing. Dec 3 '15 at 15:26
  • That error is on the other side of the keyboard, I forgot to copy it when cleaning up the code I pasted here.
    – Erik S
    Dec 3 '15 at 18:51
  • I assume you got this worked out?
    – UltraBob
    Aug 4 '16 at 2:50
0

Make sure you clear your cache (drush cc all) after (re)registering your classes. Not doing so will often result in the migrate page showing error ClassName no longer exists.

0

Sometimes it helps to specify the exact name, e.g.

drush migrate-register NewsMigration

If won't work, clear cache and restart your memcached if in use.

Also when sometimes re-registering the class, but you should try unregister and register it again, e.g.

drush migrate-reset-status User
drush migrate-deregister User
drush migrate-register User

Using deregister will remove the old migrate_map_% table and register should recreate it. See also this post for further suggestions.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.