Hello,

I have 5,000 nodes with address information that I am now able to geocode by editing and saving each node.

To accelerate this process I enlisted views bulk operations to be able to save batches of nodes at one time. Unfortunately performing a batch save on any nodes causes the node's geodata to be erased.

Any thoughts on what might cause this?

Or another process for batch saving each node to more quickly geocode already existing data?

Thanks for your time.

:) Andy

Comments

aprice42’s picture

I am working to create a views_bulk_operations replacement script to properly save the nodes with the geocoded data. As the default VBO save function is obviously not working, and producing the result above...

To create the script I need to find the function that is being called to "save" the geocoded data.

It is my understanding that to save the node hook_nodeapi is usually called. I looked through the geocode module code, and I am not able to find a geocode_nodeapi anywhere.

Can someone please let me know what function is called to save the geocoded data?

Thanks,
Andy

aprice42’s picture

with the help of Justin Miller of code sorcery, arrived at this conclusion...

using vbo to execute the following php script:


$test = node_load(&$object->nid);

module_load_include('inc', 'node', 'node.pages');

$test_state['values']['op'] = t('Save');

drupal_execute('your_node_type_node_form', $test_state, $test);

replace your_node_type with the name of your content type.

basvredeling’s picture

Thanks a L p, that snippet saved me a lot of time.

avr’s picture

D7 Snippet

I ran into this same issue. The "drupal_execute" function changed for D7. It works exactly the same but uses $entity instead of $object and drupal_form_submit instead of drupal_execute

$test = node_load($entity->nid);
module_load_include('inc', 'node', 'node.pages');
$test_state['values']['op'] = t('Save');
drupal_form_submit('church_node_form', $test_state, $test);
sano’s picture

Hi, where do I place the script? I checked the "Execute arbitrary PHP script (views_bulk_operations_script_action)" in the "Style options" pane of my VBO view and saved the view. Then - on the view-rendered page - I chose the "Execute arbitrary PHP script" action and submitted the form (page). On the next page I entered the script - modified it first as instructed with the name of the content type being updated. I got an error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'nabezky_trasy' was given in /home4/stringsn/public_html/nabezky/includes/form.inc on line 377.

What am I doing wrong?

sano’s picture

I noticed that I have not understand what to replace in the script and missed the fact that only the bold section in the drupal_execute('your_node_type_node_form', $test_state, $test); snippet needs to be replaced with the content type name. After modifying the script the operation completes, but a new error is shown:

warning: date_format() expects parameter 1 to be DateTime, null given in sites/all/modules/date/date/date_elements.inc on line 514.

I have a CCK date field in that content type. Maybe somebody knows what is causing this new error?

jerdavis’s picture

Status: Active » Postponed (maintainer needs more info)

It's not entirely clear to me what, if anything, is required from the module at this point - or even if this is still an active need.

jprstoney’s picture

Issue summary: View changes

I have a similar issue with around 7,000 imported business that need re-geocoding for their map to re-appear. Editing a node without touching anything then re-saving works and so I ran #4 with high hopes. It ran ok, but didn't re-geocode the nodes.

Many thanks for the advice but it's back to the drawing board.

askibinski’s picture

Snippet at #4 still works if added as an arbitrary PHP snippet. Tested with addressfield 1.2, geocoder 1.2 and VBO 3.3.

Just don't forget to replace "MACHINE_NAME_CONTENT_TYPE" with your own content type machine name.

$test = node_load($entity->nid);
module_load_include('inc', 'node', 'node.pages');
$test_state['values']['op'] = t('Save');
drupal_form_submit('MACHINE_NAME_CONTENT_TYPE_node_form', $test_state, $test);

I'm just curious why the standard "Save" action which is available in VBO doesn't trigger this geocode.

eloivaque’s picture

Hi

The code of #9 comment is work fine.

I reajusted code if you changes of all content of content types.

$test = node_load($entity->nid);
module_load_include('inc', 'node', 'node.pages');
$test_state['values']['op'] = t('Save');
drupal_form_submit($test->type.'_node_form', $test_state, $test);
andrewmriv’s picture

#4 worked for me 7 years later.
VBO, node_save(), and many other strategies do not work. I have had to manually go to the Node Edit form to click "Save" in order for the geolocation to work in 7.x-1.4.

Looping through NIDs and running
drupal_form_submit('FORM_ID', $test_state, $test);
worked for me.