2

Im using the migrate module to import data from a json feed. Mostly work fine however, i require that each time the feed is imported , updated records in the source are updated in the destination if they exist.

Im struggling to find much information on this or more over explicitly how to implement this kind of functionality.

I have list my code to date and would really appreciate any input someone has on this. An example might be the same feed being imported but the aboutOurClient field updated in the source

cheers

Steve

class JSONMigration extends Migration {
  /**
   * A constructor 
   */
  public function __construct() {

    parent::__construct(MigrateGroup::getInstance('json_migration'));


    $http_options = array();

    // define source definitions.... wont work with out this so hey ho
    $this->map = new MigrateSQLMap(
      $this->machineName,
      array(
        'jobref' => array(
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
        ),
      ),
      MigrateDestinationNode::getKeySchema()
    );

    $fields = array(
      'jobref'                   => 'Job reference',
      'jobTitle'                 => 'Job title',
      'aboutOurClient'           => 'About the job',

    );


    $json_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'json_migration') . '/';
    $items_url = $json_folder . 'PEsamplejson.json';

    $this->source = new MigrateSourceList(new ExampleListJSON($items_url),
      new ExampleItemJSON($items_url, array()), $fields);

    $options = array();


    $options = array('track_changes' => 1);
    $this->destination = new MigrateDestinationNode('jsontest', $options);
    //$this->systemOfRecord = Migration::DESTINATION;


    $this->addFieldMapping('field_jobref', 'jobref');
    $this->addFieldMapping('title'       , 'jobTitle');
    $this->addFieldMapping('body'        , 'aboutOurClient');




  }


  public function prepareRow($row) {
     // i can remap/manipulate here if needs be ie date
  }

}

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • AHA Seems i can effect this through drush drush mi --update {class name} – Steve Mason Feb 12 '14 at 15:09
0

If you are using the Migrate UI, at the bottom of the page there is an Options slideout with the Update checkbox. If you are kicking off your migration programmatically then call prepareUpdate() before calling processImport().

migrate_static_registration(array($machine_name));
$migration = Migration::getInstance($machine_name);
$migration->prepareUpdate();
$result = $migration->processImport();

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.