Is it possible to run the update of existing nodes automatically? For example I need it to be run on every cron run. Or maybe I can connect it to a rule (Rules module) and if the rule is satisfied, it can trigger.

Comments

czigor’s picture

May I ask why you want to do that? You need to run the update only once, when the module is installed. Afterwards the corresponding node references are created without running the update.

Sinan Erdem’s picture

I use some importers from Feeds module to import several different content types which are connected to each other with references. For some reason, after import, the nodereferences of one of the types gets cleared. So I needed to fix it by running the update after an import.

czigor’s picture

Status: Active » Fixed

OK, I see. This is not a very common use case... Anyway, putting this in any module worked for me:

<?php
function MYMODULENAME_cron(){

  $options = node_get_types('names');
  foreach ($options as $type => $name) {
    $options[$type] = $type;
  }

  $form_state = array();
  $form_state['values'] = array();
  $form_state['values']['types'] = $options;
  drupal_execute('corresponding_node_references_update_form',$form_state);

}

Just for the record, for D7 it looks like this:

<?php
function MYMODULENAME_cron(){
  $options = _node_types_build()->types;
  foreach ($options as $type => $class) {
    $options[$type] = $type;
  }

  $form_state = array();
  $form_state['values'] = array();
  $form_state['values']['types'] = $options;
  drupal_form_submit('corresponding_node_references_update_form',$form_state);

}


Hope it helps.

Sinan Erdem’s picture

Thank you, I appreciate your help. I will try to run this next time when the references get lost again...

czigor’s picture

I forgot to say (just in case it wasn't clear): this code updates corresponding node references every time cron runs. (Which might be quite resource consuming.)

Sinan Erdem’s picture

Ah yes, it is my greatest nightmare on this project :) I cannot spearate different cron jobs. I would really like to have a way to separate cron jobs and run the large ones rarely and small ones more often... I tried several cron related modules with no luck yet...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Sinan Erdem’s picture

Status: Closed (fixed) » Active

Instead of writing it in a module, can I run this script as a standalone script? I dont want it to run on every cron run, but I want to make a line for this script in my crontab file. So my cron will run once an hour but this script will only run once a day?

Is it posible somehow?

domidc’s picture

Status: Active » Closed (won't fix)

No new features will be added. New features can be posted on http://drupal.org/project/cer which is the next evolution of cnr.