Drupal save_node function removes taxomomy values from node when you create unpublish or publish node.
I have modified current function publishcontent_toggle_status($node)
like this:
/**
* @param $node a node object
*/
function publishcontent_toggle_status($node) {
if (($node->status) == '0') {
$node->status = 1;
db_query('UPDATE {node} SET status=1, changed=%d WHERE nid=%d', time(), $node->nid);
drupal_set_message(_publishcontent_get_message($node->nid, $node->title, $node->status));
drupal_goto('node/'. $node->nid);
}
if (($node->status) == '1') {
$node->status = 0;
db_query('UPDATE {node} SET status=0, changed=%d WHERE nid=%d', time(), $node->nid);
drupal_set_message(_publishcontent_get_message($node->nid, $node->title, $node->status));
drupal_goto('node/'. $node->nid);
}
}
In this case taxonomy and all other values from node are preserved.
I know this is not the best way how to replace node_save function. If there is any other (more drupal elegant) solution please let me know ...
Comments
Comment #1
malaussene commentedHi Matejap,
I tried to reproduce your issue with a free tagging taxomony but was not able find any problem.
Could you describe me a minimal setup on (user, user access, type of taxonomy...) on which
your issue occurs?
thanks
Comment #2
Matejap commentedHi,
I'm sorry for not adding this before.
user: admin, authenticated user
User access: custom role (authenticated user) with permissions for full control over own nodes and adding new one for specific content type (form creates node in this specific content type)
taxonomy:
- five vocabularies with single hierarchy and multiple select
- two vocabularies with single hierarchy and no multiple select
all taxonomies are mandatory.
currently installed modules (drupal 5.15):
- core modules +
- publish content
- cck
- content taxonomy
- scheduler
- workflow ng
- date/time modules
- javascript tools
- nodeprofile
- ubercart
- jquery update
- views
Steps to reproduce:
Create taxonomy and add few terms -> Create cck content taxonomy filed from this taxonomy (I have also try without content taxonomy module -> same results) -> submit form to create node -> publish node with -> unpublish node with publish content modul -> After unpublishing check taxonomy values in node.
I belive it is better to update the "node" table directly instead of using node_save(). When node_save() is used, other nodeapi, (category / taxonomy for example) will also be called (http://api.drupal.org/api/HEAD/function/node_save). Since category / taxonomy does have any values under this circumstances, original value will be deleted from the term_node table.
thanks...
Comment #3
malaussene commentedHi Matejap,
thank you for your detailed explanation.
After a little research, it seems that your issue is an known problem for the content_taxonomy module,
see #443340: node_save removes content_taxonomy values
Based on a quick look at the code of content_taxonomy, the problem might lie in the hook_field i.e. content_taxonomy_field.
Concerning updating the node table directly, it might be a quick fix for you now, but it cannot be used in publishcontent module as it would not play nicely with other modules.
An example of such an integration would be to have a workflow and some actions/triggers attached to the
publishing and/or unpublishing of the nodes.
good luck and have a great day
kmalaussene
Comment #4
seo2win.com commentedSolution: http://drupal.org/node/182947