0

I'm working on a project where I have 2 Drupal installations which occasionally need to interact with eachothers database.

So far, I've been able to set up all interactions using db_set_active and db_select/db_query/db_update statements (example below):

db_set_active(.....);
db_select(.....);
db_set_active;

Simple select queries don't pose any problem. And while update queries are being propagated correctly, they have an inherit issue: they don't call the save hooks in the target Drupal installation...

My use case: I'm database updating a boolean CCK field (in Drupal B) from 0 to 1 (through a module script at Drupal A) and Rules (at Drupal B) should trigger on this. Moreover, the field caches aren't cleared so probably going directly through the database isn't a very good way to update the field...

Any other ideas how to update fields from within external scripts? Or maybe how to execute Rules while keeping the database operations?

Thanks

4
  • Have you tried using Entity API? drupal.org/node/1842304
    – pgrujic
    Commented Sep 4, 2013 at 20:49
  • Interacting directly with another site's database sounds dangerous. What is it you're trying to do with the boolean value?
    – beth
    Commented Sep 4, 2013 at 22:58
  • Hi Beth, I'm updating a boolean CCK field of a content type (like: 'Contract Signed?'). It really isn't that dangerous as Drupal has built-in support for this. However as the question states: direct database updates (using sql UPDATE ... SET ...) omit all various Drupal hooks which I do need. Commented Sep 5, 2013 at 6:56
  • @pgrujic I can succesfully read values using Entity API, but updating fields in the database (through entity_metadata_wrapper or entity_save) still fails with an error (EntityMetadataWrapperException: Unknown data property field_*****) Commented Sep 5, 2013 at 7:37

1 Answer 1

0

I have achieved the similar functionality with following code. I worked on Drupal 6. But, hopefully it worked for you.

I have two same drupal installation and when creating new node in one installation, I need to create node into another Drupal installation also. So, I customize the node form and added a submit function to node form.

Custom Submit function

function custom_node_export_form_submit($form, $form_state) {

  //Creating node object
  $node = new stdClass;

  foreach ($form_state['values'] as $key => $value) {
    $node->$key = $value;    
  }

  db_set_active('domain');

  node_save($node);

  db_set_active('default');  

}

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.