1

I have a drupal 7 commerce site, each day our client uploads a .csv with updates to approx. 4000 products, including published status.

2 imports have been configured, 1 to update the product information and the other to update the product references (node/display) - both read the same .csv.

The importers must run 3 times a day, in order to avoid errors, the product importer must execute before the reference importer. If we use Drupal cron, both will start at the same scheduled time, which leads to errors.

What we really want is to run the product importer until it is completed (multiple times if necessary), and only then to run the reference importer. All of the above 3 times a day.

I imagine there is a hook allowing execution of a specific importer, so I can run it via bash cron, but I don't know where to begin looking, any pointers would be appreciated.

3

2 Answers 2

2

There are multiple solutions to this problem:

  1. Cron manager

    One is indeed to use a cron manager module. I think you would need Feeds Ultimate Cron for this. This solution would require you though to guess when the first import is completed.

  2. Rules

    Using the Rules action 'Execute feeds importer' (requires latest dev of Feeds 7.x-2.x or the patch from https://www.drupal.org/node/2446307). In this case you would create a Rules component of type 'Action set' and then add two times the action for executing a feeds importer (one for each importer). Perhaps it possible with Rules Scheduler to run this action set on a regular basis? Note that you should configure the importers to not run in background, else both imports may still run simultaneously. Also note that Feeds would try in this case to perform the whole import in one go, so it could perhaps cause max runtime issues.

  3. Drush

    Feeds has a drush command called feeds-import with which you can perform an import in one go. So you could create a shell script that runs both imports after eachother and then run that script on a regular basis. For details about this command, see https://drushcommands.com/drush-7x/feeds/feeds-import/

  4. Implement hook_feeds_after_import()

    Feeds has a hook called hook_feeds_after_import() that you could use to initiate an other import programmatically:

/**
 * Implements hook_feeds_after_import().
 */
function mymodule_feeds_after_import(FeedsSource $source) {
  // Run product display importer after product importer.
  if ($source->importer->id == 'product_importer') {
    $product_display_source = feeds_source('product_display_importer');
    $product_display_source->existing()->startImport();

    // Execute batch, if there is any. Set 'progressive' to false to prevent
    // batch from triggering a drupal_goto().
    // (note: this code is not needed when using the 'process in background' option.)
    $batch =& batch_get();
    if (!empty($batch)) {
      $batch['progressive'] = FALSE;
      batch_process();
    }
  }
}
0

Use this module and it will do the work for you: https://www.drupal.org/project/feeds_dependency

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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