[development] fixing broken nodes

Lluís Forns enboig at gmail.com
Tue Apr 20 12:01:59 UTC 2010


you are right, as long as uid=1 is logged everything should be ok.
I am using a module which allow users to create/load/edit nodes only
under certain circumstances (similar to OG, but more complex), using
hook_node_access_records() and hook_node_grants(). In this particular
case, just uid=1 will call the function, so I could avoid them; but
for some other admin tasks not performed by uid=1 I need these
functions.

2010/4/20 Mukesh Agarwal <mike4u4ever2001 at gmail.com>:
> this reminds me that there is a weird issue with drupal... the access all
> content permissions saves the configuration in node_access with nid = 0
> which should not be the case.. so its best if you never interact with
> node_access table and stay out of the problem... not that it is relevant
> with this problem, just wanted to share :)
> i'm not sure if i follow the use of the 2 functions.. did it work for you?
> the permission for the user to be able to save the node can be defined using
> drupal permissions.. no? even in case you are using any access control
> module, your node_save should work independently.. the access control module
> should handle the permissions of saving the node..
>
> On Tue, Apr 20, 2010 at 5:00 PM, Lluís Forns <enboig at gmail.com> wrote:
>>
>> I just discovered another problem, I am using an access control
>> module, so I had to add 2 functions so my user could load/save any
>> node:
>>
>> function mymodule_loadAnyNode($nid) {
>>  if ($nid==0) return FALSE;
>>  global $user;
>>  static $orig_user = array();
>>  array_push($orig_user, $user);
>>  $user = user_load(1);
>>  $node=node_load($nid);
>>  $user = array_pop($orig_user);
>>  return $node;
>> }
>>
>> function mymodule_saveAnyNode($node) {
>>  if ($nid==0) return FALSE;
>>  global $user;
>>  static $orig_user = array();
>>  array_push($orig_user, $user);
>>  $user = user_load(1);
>>  $return=node_save($node);
>>  $user = array_pop($orig_user);
>>  return $return;
>> }
>>
>>
>>
>> 2010/4/20 Mukesh Agarwal <mike4u4ever2001 at gmail.com>:
>> > Try changing $node->uid.. The timestamps will have to change when you
>> > update
>> > a node.. it is necessary for many modules to be identified of the change
>> > like search and xmlsitemap
>> >
>> > On Tue, Apr 20, 2010 at 3:43 PM, Lluís Forns <enboig at gmail.com> wrote:
>> >>
>> >> My problem right now is node_save itself: uid and timestamps are
>> >> changed by node_save. Is there a way to avoid that? Or should I reset
>> >> these fields with db_query("UPDATE ...")?
>> >>
>> >> 2010/4/20 Lluís Forns <enboig at gmail.com>:
>> >> > This is the way I am following now. I hope my code will fix all the
>> >> > "broken" nodes.
>> >> >
>> >> > 2010/4/20 Steven Jones <steven.jones at computerminds.co.uk>:
>> >> >> Hi Lluís,
>> >> >>
>> >> >> You can use Drupal's Batch API to process large sets of objects like
>> >> >> this. Documentation for the API is here:
>> >> >>
>> >> >> http://api.drupal.org/api/group/batch
>> >> >>
>> >> >> And it includes an example for iterating over all nodes.
>> >> >>
>> >> >> Hope that helps!
>> >> >>
>> >> >> Regards
>> >> >> Steven Jones
>> >> >> ComputerMinds ltd - Perfect Drupal Websites
>> >> >>
>> >> >> Phone : 024 7666 7277
>> >> >> Mobile : 07702 131 576
>> >> >> Twitter : darthsteven
>> >> >> http://www.computerminds.co.uk
>> >> >>
>> >> >>
>> >> >>
>> >> >> On 20 April 2010 08:38:19 UTC+1, Lluís Forns <enboig at gmail.com>
>> >> >> wrote:
>> >> >>> I have some modules creating nodes calling directly node_save() and
>> >> >>> now when trying to rebuild permissions table drupal fails at a
>> >> >>> random
>> >> >>> node.
>> >> >>>
>> >> >>> I think this is caused because of some bad created nodes, and I
>> >> >>> thing
>> >> >>> I have found a way to fix them; but it fail because of memory
>> >> >>> limit.
>> >> >>> Is there a way to make node_load() not store nodes in cache? (I
>> >> >>> have
>> >> >>> around 30k nodes)
>> >> >>>
>> >> >>> Thanks
>> >> >>>
>> >> >>> <?php
>> >> >>> function mymodule_update_6008() {
>> >> >>>  $ret=array();
>> >> >>>  $res=db_query("SELECT nid, type FROM {node}");
>> >> >>>  while ($row=db_fetch_array($res)){
>> >> >>>    $prenode['type']=$row['type'];
>> >> >>>    $prenode=(object)$prenode;
>> >> >>>    $node_new=node_object_prepare($prenode);
>> >> >>>    $node_old=node_load($row['nid']);
>> >> >>>    foreach($node_old AS $key => $value) {
>> >> >>>      $node_new->$key = $value;
>> >> >>>    }
>> >> >>>    node_save($node_new);
>> >> >>>  }
>> >> >>> }
>> >> >>> ?>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> *Les normes hi són perquè hi pensis abans de saltar-te-les
>> >> >>> *La vida és com una taronja, què esperes a exprimir-la?
>> >> >>> *Si creus que l'educació és cara, prova la ignorància.
>> >> >>> *La vida és com una moneda, la pots gastar en el que vulguis però
>> >> >>> només una vegada.
>> >> >>> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>> >> >>>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > *Les normes hi són perquè hi pensis abans de saltar-te-les
>> >> > *La vida és com una taronja, què esperes a exprimir-la?
>> >> > *Si creus que l'educació és cara, prova la ignorància.
>> >> > *La vida és com una moneda, la pots gastar en el que vulguis però
>> >> > només una vegada.
>> >> > *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> *Les normes hi són perquè hi pensis abans de saltar-te-les
>> >> *La vida és com una taronja, què esperes a exprimir-la?
>> >> *Si creus que l'educació és cara, prova la ignorància.
>> >> *La vida és com una moneda, la pots gastar en el que vulguis però
>> >> només una vegada.
>> >> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>> >
>> >
>> >
>> > --
>> > Cheers,
>> > Mukesh
>> >
>>
>>
>>
>> --
>> *Les normes hi són perquè hi pensis abans de saltar-te-les
>> *La vida és com una taronja, què esperes a exprimir-la?
>> *Si creus que l'educació és cara, prova la ignorància.
>> *La vida és com una moneda, la pots gastar en el que vulguis però
>> només una vegada.
>> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>
>
>
> --
> Cheers,
> Mukesh
>



-- 
*Les normes hi són perquè hi pensis abans de saltar-te-les
*La vida és com una taronja, què esperes a exprimir-la?
*Si creus que l'educació és cara, prova la ignorància.
*La vida és com una moneda, la pots gastar en el que vulguis però
només una vegada.
*Abans d'imprimir aquest missatge, pensa en el medi ambient.


More information about the development mailing list