0

I'm using the Rules module to execute custom PHP script whenever a new node is saved after importing via Feeds module.

<?php

$lid = db_insert('location')->fields(array(
    'additional' => $node->field-address, //saves as '0'
    'city' => $node->field-locality, // saves '0'
    'province' => $prov, // //saves correctly
    'country' => 'xx', //saves 'xx' correctly
    'latitude' => $node->field-latitude-temp, //saves as 0.00000
    'longitude' => $node->field-longitude-temp, //same
    'source' => 1,
    'is_primary' => 0
))->execute();

This is the location table (from the Location module) and I'm importing data from a csv file.

All the other constant values are saved properly except for when it is coming from the $node object. Lat and Lon goes 0.00000 while all the other string values such as city and address also goes 0.

Been dealing with this for hours.

EDIT: I'm using Feeds module. But I need to import also location data. While a row is getting committed to db, the values are all 0!

node:field-latitude-temp shows the actual imported value correctly when viewing the node. But it is not getting absorbed in within the PHP Execute custom code page in Rules.

enter image description here

enter image description here

6
  • 1
    Any reason you're not using the Feeds module? Also which hook are you suing? Are you sure its called after node save? Aug 2, 2014 at 2:32
  • @Queenvictoria I have edited my post above.
    – jan
    Aug 2, 2014 at 5:45
  • From where you are getting the $node object? are you doing any node_load or the node object is supplied via any hook? Aug 2, 2014 at 6:01
  • It is supplied by the 'Execute Custom PHP Code' page via the Rules module. I have edited to include an image.
    – jan
    Aug 2, 2014 at 6:13
  • @Queenvictoria Also, the Feeds module can't import data to Location, not sure why though, so what I did was to temporarily save it to another field and then let drupal copy that value directly to the database using the execute code.
    – jan
    Aug 2, 2014 at 6:17

1 Answer 1

1

I am not sure this can help you, but I don't think $node->field-address or $node->field-longitude-temp are valid syntax by $node object, you should use $node->field_address['und'][0]['value'] or with entity_metadata_wrapper function, eg:

$nodeWrapper = entity_metadata_wrapper('node', $node);
$nodeWrapper->field_address->value()
3
  • 1
    Yes, this appears to be the issue, though I'd suggest trying $nodeWrapper->field_address->raw() to get a value more suitable for db_insert Aug 2, 2014 at 11:05
  • @DavidThomas yes, you're right, raw() will be the right method for insert operations..
    – xurshid29
    Aug 2, 2014 at 11:10
  • Thanks @xurshid29 for taking the time. Right now I just figured out I can use 'Location Feeds' to import location data using Feeds module. I have been looking for this. Though will keep your solution in mind.
    – jan
    Aug 2, 2014 at 11:33

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.