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.
See #2848161: [meta] Replace calls to deprecated db_*() wrappers.
Replace all usages of db_update in core, except in code that is testing db_update.
Comment | File | Size | Author |
---|---|---|---|
#69 | 2848137-68.patch | 36.39 KB | andypost |
#69 | interdiff.txt | 878 bytes | andypost |
#66 | interdiff.txt | 6.31 KB | andypost |
Comments
Comment #2
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedAlternative way to update database method used now.
Comment #3
cilefen CreditAttribution: cilefen commentedI am not sure about the scope here. I will look into it.
Comment #4
cilefen CreditAttribution: cilefen commentedSee the new parent issue. Let's replace this in all of core.
Comment #5
cilefen CreditAttribution: cilefen commentedComment #6
xjmComment #7
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedReplaced all the calls to db_update with correct format , except in test cases.
Comment #8
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #9
cilefen CreditAttribution: cilefen commentedComment #10
vidhatanand CreditAttribution: vidhatanand at OpenSense Labs commentedComment #11
JayKandariHi,
Found some code style related issues in patch #7, Kindly correct these.
Also, 1 more instance of "db_update()" found in
core/modules/path/path.api.php:42:
not covered in #7. Include this as well.Use spaces instead of Tabs.
Use proper Indentation.
Check indentation.
unecessary space at end of line.
Thanks !!
Comment #12
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedI have done all the corrections and replaced all calls to db_update with correct syntax.
Comment #13
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #14
JayKandari#12 Looks good except for minor coding standards. I'd recomend to run your code thru coder module.
minor spaces and indentation issues. could you pls fix that.
Thanks !!
Comment #15
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #16
daffie CreditAttribution: daffie commentedThere are still coding standards violations.
No need for this empty line.
Not the same indentation and unnecessary empty lines added.
Comment #17
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #18
daffie CreditAttribution: daffie commentedLooks good to me.
Comment #19
cilefen CreditAttribution: cilefen commentedI am moving this to database system to be like this others, although this is about calls into the system.
Comment #20
cilefen CreditAttribution: cilefen commentedThere is documentation in database.inc telling people to use db_update().
The meta issue reads: "...replace all usages of the function (except tests for the function itself)...", which would mean to replace usages except for tests that are specifically for db_update itself, which in this case I think is Drupal\KernelTests\Core\Database\UpdateTest.
Comment #21
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedWe can have separate issue for documentation. Documentation is not exactly usage , that comment can be edited when definition of db_update will be removed.
Comment #22
cilefen CreditAttribution: cilefen commentedSee #2232391: Revert drupal 8 changes made to generate-d7-content.sh and generate-d6-content.sh. This file should not be changed.
Comment #23
cilefen CreditAttribution: cilefen commentedOK on #21 - open a single issue to fix all the documentation references to using db_* functions and relate it to the meta issue please.
(edited)
Comment #24
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedChecked this issue (https://www.drupal.org/node/2232391) and have restored file generate-d7-content.sh
Comment #25
daffie CreditAttribution: daffie commentedLooks good to me. Back to RTBC.
Comment #26
cilefen CreditAttribution: cilefen commentedDid you see comment #20?
Comment #27
daffie CreditAttribution: daffie commented@cilefen: Sorry, I missed that one.
Comment #28
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commented@cilefen are you suggesting that calls to db_update in Drupal\KernelTests\Core\Database\UpdateTest should also be replaced with new syntax.??
Comment #29
cilefen CreditAttribution: cilefen commentedNo. As far as I know (still discussing with others) those are the usages not to change. But things like AggregatorCronTest::testCron call it.
Comment #30
xjmComment #31
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedreplaced the usage of "db_update" in database.inc file.
Comment #32
daffie CreditAttribution: daffie commentedI have some remarks about this patch:
The changes in the documentation will be done in #2849745: Replace documentation recommending db_*() wrappers.
The only thing that should be changed is the first line:
db_update('example_entity')
to\Drupal::database()->update('example_entity')
. Watch out for the semicolon.db_update()
is still not changed in a lot of places.Comment #33
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commented@daffie, I have updated the patch.
db_update is used in various test files. Are they also needs to be replaced in this patch?
Comment #34
daffie CreditAttribution: daffie commented@shashikant_chauhan: Yes all usages of db_update must be changed, including all tests! The changes that you made in comment #33 are good to me.
Comment #35
cilefen CreditAttribution: cilefen commentedI think on the meta we had reasoned that we should not remove tests for the function itself.
Comment #36
daffie CreditAttribution: daffie commentedThe function db_update() is used in a lot of tests, mostly in testing for other functionality. I had the idea that we would change ALL usages of db_update(). Can you point me to that decision @cilefen?
Comment #37
daffie CreditAttribution: daffie commentedI thought about it some more and I agree that if we remove all usage in testing then we will have no more testing for the functions in database.inc. I would really like to remove all usage of the functions in testing. My suggesting would be to create a new test for the functions in database.inc. If we do not remove all usage in testing we cannot a the start of Drupal 9.0 just delete the functions in database.inc.
Comment #38
cilefen CreditAttribution: cilefen commentedI would not call it an official decision: #2848161-25: [meta] Replace calls to deprecated db_*() wrappers because I don't know the project standard for leaving in tests that are testing a deprecated function directly. In either case, that issue is the place for that discussion.
Comment #39
hgunicamp CreditAttribution: hgunicamp at CI&T commentedI have fixed the 'drupal-replace-calls-to-db_update-2848137-33.patch' patch because it was not applying any more because 'array()' notation has already been applied in the files affected by the patch.
After that, I searched in all code to realize the size of the work we still need to do.
cit008490cpsubuntu:drupal progestag* 8.4.x$ find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep db_update {} \+ | wc -l
86
cit008490cpsubuntu:drupal progestag* 8.4.x$ patch -p1 < /tmp/replace_all_calls_to-2848137-39.patch
patching file core/lib/Drupal/Core/Entity/entity.api.php
patching file core/modules/locale/locale.translation.inc
patching file core/modules/path/path.api.php
patching file core/modules/search/search.module
patching file core/modules/tracker/tracker.module
patching file core/modules/user/user.api.php
cit008490cpsubuntu:drupal progestag* 8.4.x$ find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep db_update {} \+ | wc -l
77
Comment #40
hgunicamp CreditAttribution: hgunicamp at CI&T commentedComment #41
cilefen CreditAttribution: cilefen commentedComment #42
brahmjeet789 CreditAttribution: brahmjeet789 as a volunteer and at gai Technologies Pvt Ltd commented@hgunicamp i have replaced db_update in remaining files,now after running this command find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep db_update {} \+ | wc -l
61 please review the patch and advise me
Comment #44
hgunicamp CreditAttribution: hgunicamp at CI&T commented@brahmjeet789 you can change a little bit the command to make it show which files still have the 'db_update'.
For example:
find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep db_update {} \+ | cut -f1 -d':' | uniq
Explaining each part of the command:
Using this command I got:
find . -type f \( -name '*.inc' -or -name '*.module' -or -name '*.php' \) -exec grep db_update {} \+ | cut -f1 -d':' | uniq
./core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php
./core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php
./core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php
./core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php
./core/modules/system/tests/fixtures/update/drupal-8.block-content-uninstall.php
./core/modules/system/tests/modules/entity_test/entity_test.module
./core/modules/system/tests/modules/update_script_test/src/Controller/UpdateScriptTestController.php
./core/modules/system/system.module
./core/modules/system/src/Tests/Update/UpdateScriptTest.php
./core/modules/system/src/Tests/Update/DbUpdatesTrait.php
./core/modules/system/src/Tests/Update/UpdateSchemaTest.php
./core/modules/system/src/Tests/Update/UpdatePathTestBase.php
./core/modules/system/src/Controller/DbUpdateController.php
./core/modules/system/src/Theme/DbUpdateNegotiator.php
./core/modules/update/update.authorize.inc
./core/modules/update/update.module
./core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php
./core/modules/user/src/Tests/UserPasswordResetTest.php
./core/modules/user/src/Tests/UserCancelTest.php
./core/modules/user/src/Tests/UserBlocksTest.php
./core/modules/user/src/Tests/UserPictureTest.php
./core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php
./core/modules/contact/tests/drupal-7.contact.database.php
./core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php
./core/includes/database.inc
./core/lib/Drupal/Core/Database/Driver/pgsql/Update.php
./core/lib/Drupal/Core/Database/database.api.php
./core/lib/Drupal/Core/Database/Query/Update.php
./core/lib/Drupal/Core/Update/UpdateKernel.php
I hope it may help.
Comment #45
hgunicamp CreditAttribution: hgunicamp at CI&T commentedI posted the 'replace_all_calls_to-2848137-45.patch' fixing a typo in 'replace_all_calls_to-2848137-40.patch' which causes the linter failure.
Comment #46
cilefen CreditAttribution: cilefen commentedComment #47
Sharique CreditAttribution: Sharique as a volunteer commentedThe patch looks good to me. Quick search inside core folder does not find any instance of db_update in code. Also did sanity testing, everything works fine for me.
+1 for RTBC.
Comment #48
brahmjeet789 CreditAttribution: brahmjeet789 as a volunteer and at gai Technologies Pvt Ltd commentedThanks @hgunicamp for guiding me on this issue i will check and acknowledge it.
Comment #49
pk188 CreditAttribution: pk188 at OpenSense Labs commentedUpdated all the occurences.
Comment #50
brahmjeet789 CreditAttribution: brahmjeet789 as a volunteer and at gai Technologies Pvt Ltd commentedI Have tested it on my local its working fine, Now all calls to db_update is changed to \Drupal::database()->update().
Comment #52
brahmjeet789 CreditAttribution: brahmjeet789 as a volunteer and at gai Technologies Pvt Ltd commentedHi I have replaced the db calls, please review the patch.
Comment #53
brahmjeet789 CreditAttribution: brahmjeet789 as a volunteer and at gai Technologies Pvt Ltd commentedHi I have replaced the db calls, please review the patch.
Comment #55
pk188 CreditAttribution: pk188 at OpenSense Labs commentedComment #58
volegerReroll
Comment #60
Mile23Patch doesn't apply.
Comment #61
volegerPostponed on #2991542: Introduce a DatabaseLegacyTest class for deprecation testing and #2991337: Document the recommended ways to obtain the database connection object
Comment #62
volegerRerolled.
Added the legacy test.
Reverted changes to D7 related script.
Comment #64
volegerRerolled
Comment #66
andypostReroll and following changes
- removed dot at the end of URL to deprecated message cos some editors suppose the dot as part of URL
- connection is final object that could live withing each testcase, so I made a cache for local variable
Comment #67
andypostAnd test must ensure that functions return proper object instead of what the object can do - so testing was changed
Comment #69
andypostMissed table name
Comment #70
volegerLooks good
Comment #73
catchCommitted/pushed to 8.7.x, thanks!