Score:0

Update field without node save

ve flag

I am a beginner in Drupal, I would like to insert a value into a node field. But instead of a node->save() I want to avoid any presave hook and insert it directly using sql query. I have the entity_id to insert also in the field_NAME_value column, is this the node id? Or how do I get this? Or is there a way to do a node save without calling presave ? Thanks

cn flag
With utmost respect, if you need to ask (i.e. aren't able to work out/intuit) what the columns in these tables are, you're probably going to end up breaking something by manipulating the database manually. It may help to turn your problem on its head and explain what's wrong with the presave hook(s) running in the first place. You might be able to stop that behaviour instead, in a more elegant and future-proof manner.
Jaypan avatar
de flag
I have to agree with Clive. This is dangerous, a bad practice, and skips API checks. Why do you not want to save the node?
jacksparrow avatar
ve flag
@Clive Thanks guys. Actually I have a batch operation (more than 20k nodes) which times out, there are some hook presaves that gets called and the whole process is slow , so to speed this up I wanted to try and update directly the db which would make things faster.
cn flag
I'd be tempted to accept that the batch is going to be slow, and look at chunking it up into smaller pieces instead - you shouldn't get a timeout running a batch op, that's kind of why they exist in the first place. If you make the number of nodes per op smaller, you might even find that the whole process runs quicker as a whole anyway, as you won't be using as many resources per request
jacksparrow avatar
ve flag
@Clive thanks for your thoughts, they are helpful. When running the batch during a hook_deploy , there is a timeout after 14400s coming from Drush (it is set in drush.php) and also a database timeout, I don't know how to override this, which is why I was trying to reduce the time for the whole process. I think I will create a cron that will run 4 times the batch and divide the total number of nodes in 4
cn flag
Oh I see, this may also be helpful then: https://drupal.stackexchange.com/questions/280846/how-to-change-the-drush-default-timeout-of-14400
jacksparrow avatar
ve flag
@Clive thanks for your help!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.