Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Remove those functions.
Replace all node_save($node) calls with $node->save(), the same for node_delete().
Remove node_delete_multiple($ids) with entity_delete_multiple('node', $ids).
Replace comment references with \Drupal\Core\Entity::save() and so on.
Comments
Comment #1
elvis2 CreditAttribution: elvis2 commentedComment #2
elvis2 CreditAttribution: elvis2 commentedThis patch takes care of the node_save uses in all files except:
/drupal/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php
lines 91, 93, 101, 103
Looking purely at the code, it seems those lines would break since node_save is expecting the $node object, so I hesitated to touch this for the time being. I will come back to it this week.
At this point, should function node_save($node) in node.module be removed or should this be left in place for contrib modules to have a fallback on upgrading from d7 to d8?
I am doing the node_delete fixes separately.
Comment #3
elvis2 CreditAttribution: elvis2 commentedComment #4
elvis2 CreditAttribution: elvis2 commentedLet's try that again...
Comment #5
BerdirThanks for working on this.
Yes, the functions should be removed.
You should be able to convert those in that test as well. If you can call node_save($whatever['thing']), then $whatever['think'] is a node object, however it might be named, so you can call ->save() on that and it should work.
Comment #6
elvis2 CreditAttribution: elvis2 commented@Berdir node_save is referenced from a page callback in:
/drupal/core/modules/system/tests/modules/menu_test/menu_test.module
within menu_test_menu.
How should that be handled?
Comment #8
BerdirWeird. I can't find a request that actually uses that in the tests, only one that loads it. Try to change it to menu_test_callback and then let's see if anything breaks.
Comment #9
elvis2 CreditAttribution: elvis2 commentedOk, all node_save() have been converted and documentation in node.api.php updated.
@Berdir I changed the menu callback as you suggested.
Comment #11
elvis2 CreditAttribution: elvis2 commented#9: 1999322-9-converted-node-save-functions.patch queued for re-testing.
Comment #13
BerdirLooks like you accidently added your .gitignore file to the patch. I suggest you add .gitignore to .gitignore, then it will ignore itself or add these rules to .git/info/exclude
You don't need to assign it to $node, you can simply call $this->node->save().
Same here. Everything that's passed to node_save() must be a node object, even if it's not named like that, so $revision->save() should work fine.
This looks quite readable but I'm not sure if this is valid, will have to check with someone that knows these documentation rules better.
This is actually not really true anymore. It should simply say something like "from the storage controller after the node was saved". If you're not sure, leave this part for now and I'll try to re-work it later.
Same for the other hook documentations in node.api.php
Looks good otherwise, I guess you still need to convert the node_save()'s in that search comment test. If you click on view details and then expand the detail log at the end, you can see that it dies with a fatal error trying to call that function somewhere.
Comment #14
elvis2 CreditAttribution: elvis2 commentedThanks for your tips Berdir. I will make those changes later this evening.
I am glad you brought up the doc stuff, as I have been questioning myself if that is the right way. Especially now that I am doing the same thing, pretty much, for node_delete documentation. I will add that patch this evening too.
Thanks for your help.
Comment #15
BerdirThanks for working on this, appreciated!
Note that you can upload the node_delete() changes as part of the same patch. Except we want to define that we should open a separate issue for it. Which might not be the dumbest idea (the only problem is that it could result in unnecessary conflicts between the two patches).
So if you want to, feel free to edit the original issue title and description, remove delete and create a separate issue for it. Your decision :)
Comment #16
elvis2 CreditAttribution: elvis2 commentedHere is the patch for the conversion of node_delete_multiple to entity_delete_multiple
Comment #18
elvis2 CreditAttribution: elvis2 commentedOk, let's try that again.
Comment #19
elvis2 CreditAttribution: elvis2 commentedBerdir, okay, the next patch I will combine both sets of changes.
Comment #20
BerdirYou can remove this as well and call $node->delete() instead. As this does just receive the node id, you might have to add some node_load()'s but only where you don't have a node object already.
Comment #21
elvis2 CreditAttribution: elvis2 commented@Berdir, so to be clear, where ever node_delete is called convert those to be $node->delete() ?
Comment #22
BerdirExactly, $node->delete() instead of node_delete($node->nid).
Comment #24
elvis2 CreditAttribution: elvis2 commentedThis patch has both conversions, node_save (to $node->save()) and node_delete (to $node->delete()).
I wanted to ask, do the test bots fail sometimes due to false positives? The last patch failed from the testbot but on my local box (after "cleaning environment" in simpletest) I had no errors, just two warnings.
The documentation needs attention. I am not familiar with the d8 documentation standards. For example, in d7 node_save($node) was mentioned in node.api.php. I think there is a more proper way to document the save() method and references. Can I get some help on that or point me to some examples?
Thanks berdir and timplunkett for your help.
Comment #25
elvis2 CreditAttribution: elvis2 commentedComment #26
elvis2 CreditAttribution: elvis2 commentedTrying again. I missed a few node_save()'s...
Comment #27
BerdirLooks good, a few (like 3 I think) cases that can be simplified, see #13.
Will try to find someone tomorrow for the documentation thing, I'm not sure myself. The problem with $node->save(), although it makes kinda sense is that it's not referencable to anything. But maybe that's fine, or maybe we just want to make some proper english out of it, e.g. "while saving a node". But there are some references that are supposed to reference where this actually happens, but they stopped making sense a long time ago anyway (node_save() isn't where the fun stuff happens, that's in the storag controller but that's hard to reference).
Comment #28
elvis2 CreditAttribution: elvis2 commentedThanks Berdir, I have simplified those 3.
Assuming this attached patch passes, afterwards, should I change the title of this issue? What is the proper protocol?
Comment #30
Berdir#28: 1999322-28-node_save-and-node_delete-conversions.patch queued for re-testing.
Comment #32
Berdir#28: 1999322-28-node_save-and-node_delete-conversions.patch queued for re-testing.
Comment #33
BerdirOk, this looks good. Discussed this with a few people and this is good to go.
Improving the hook documentation there to something that makes sense should happen in #1824184: Remove and replace entity type specific API hook documentation with generic entity API hook documentation
Comment #34
elvis2 CreditAttribution: elvis2 commentedGood to hear Berdir. This was my first time patching for core. Thanks for all your help...
Comment #35
catch#28: 1999322-28-node_save-and-node_delete-conversions.patch queued for re-testing.
Comment #37
elvis2 CreditAttribution: elvis2 commented@catch I need to reroll this, core has changed enough that this patch fails... I will do this Wednesday evening PST.
Comment #38
alexander.ilivanov CreditAttribution: alexander.ilivanov commentedWill be done today during Code Sprint UA.
Comment #39
alexander.ilivanov CreditAttribution: alexander.ilivanov commentedReplaced node_save(), node_delete(), node_delete_multiple()
Patch attached.
Comment #40
elvis2 CreditAttribution: elvis2 commented@alexander.ilivanov, nice work!
Comment #41
catchCommitted/pushed to 8.x, thanks!
Comment #42
podarokback to tag
Thanks for Your work @alexander.ilivanov
Comment #44
Gábor HojtsyNo change notice was created for this issue.
Comment #45
BerdirWe already have https://drupal.org/node/1400186, added a list of related removed functions there.
Adding every issue that's related to that is going to be too much...
Comment #46
BerdirRemoving tag.
Comment #47
BerdirComment #48
Gábor HojtsyI think thats a great solution. However wiring up that change notice to this issue seems important for posterity, so (a) its evident this issue is covered (b) people find the change explained in context from the issue summary. Added this issue to the list of related issues there.