Community

Is there a way to save all nodes without node_save? [SOLVED]

I have a hard error on a lot of my pages. (Long story short there is a third party module that causes the error because a taxonomy term has been deleted)

To fix the error all I do is edit the node and hit save and the problem is fixed.

I want to go through all my nodes and re-save all of them to fix the issue. I tried to do a node_save($node) but it did not work. I also tried VBO Save Content and Publish Content. Does anyone know of a way of reproducing the Save just like I would be doing it manually?

Comments

Why doesn't node_save() work?

Why doesn't node_save() work? (It is used one you do it manually)

I think

http://www.screencast.com/t/6d5g4oYgZ

If you see this screenshot it shows that there are drop downs with blanks. Those are the child terms that got deleted. I'm guessing because I'm actually on the node edit form it blanks it out and if I do a node_save it still keeps the missing terms.

If you do a node_load() and

If you do a node_load() and then node_save() it should work. So what does your code look like that calls node_save().

This is my code:

<?php
$node
= node_load(5724);
node_save($node);
?>

Ok, how does I'm guessing

Ok, how does

I'm guessing because I'm actually on the node edit form it blanks it out and if I do a node_save it still keeps the missing terms.

relate to what you are doing?

Where are you placing that code?

I'm just trying to show that

I'm just trying to show that if I go in the edit screen manually I notice that the deleted terms are shown up as blanks in the drop down. And when I Save the error goes away. I'm not sure how it fixes it but when I hit Save the problem goes away.

I placed the php code in a different node on my site.

When you say the error goes

When you say the error goes away, do you mean the blank drop downs or something else?

The blank drop downs are gone

The blank drop downs are gone and the error goes away. (The error only is displayed when viewing the node and when editing it does not appear)

By the way this is the error: EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7633 of /includes/common.inc).

Solved

I found the reason why there was a difference when I did a Save manually and did a node_save. It turns out in the custom module who someone else wrote was calling $_POST in hook_node_update().

<?php

if (isset($_POST[$fieldname][$langcode])) {
 
$items = _reltw_form_to_storage($field, $langcode);
 
_reltw_cleanup_submitted_items($items);
}
?>

Also I figured out why I was getting the error. The module was calling entity_uri on a taxonomy term that was null.

<?php
$term
= taxonomy_term_load($item['tid']);
$uri = entity_uri('taxonomy_term', $term);
$markup .= ' &raquo; ' . l($term->name, $uri['path'], $uri['options']);
?>

I fixed this to:

<?php
$term
= taxonomy_term_load($item['tid']);
if(
$term) {
 
$uri = entity_uri('taxonomy_term', $term);
 
$markup .= ' &raquo; ' . l($term->name, $uri['path'], $uri['options']);
}
?>