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.
Problem/Motivation
Drupal 6 and Drupal 7 user entity source plugins exclude the anonymous account (uid = "0") in their database query. ContentEntity source plugin should should follow them.
Proposed resolution
If the entity type ID is "user", exclude entity type IDs lower than "1".
Remaining tasks
Patch
Review
Commit
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Issue fork drupal-3187318
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
huzookaComment #3
Wim LeersI was going to ask to add
@see
… but you already did 🤩Comment #4
alexpottLooks like something we should be testing.
Comment #5
Wim LeersI'm hopeful we can test that relatively easily in
\Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest
🤞Comment #6
quietone CreditAttribution: quietone as a volunteer commentedThis issue is not specific to Drupal 7 sources, removing tags. One could argue that this could have a migrate-d8+-d8+ tag, but there are only two source plugins for the current version of Drupal so I don't think it is necessary.
Comment #9
eddie_c CreditAttribution: eddie_c at Oxfam International commentedI've created a merge request with @huzooka's patch and I've fixed ContentEntityTest as suggested by @Wim Leers.
ContentEntityTest::testUserSource() already has an assertion to check that only one user is in the $user_source (line 258) so I just added a second user with uid 0 which should be excluded.
Comment #10
quietone CreditAttribution: quietone as a volunteer commentedJust a few changes and this will be ready.
Comment #11
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@quietone all the changes are done as suggested. Please review it.
Comment #12
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedComment #13
quietone CreditAttribution: quietone as a volunteer commented@sudiptadas19, Thanks for the updates. Since this issue is using a MR it would be easier if work continued on the MR and not reintroduce the patch system. When making a patch normally I expect an interdiff but this is so small I guess that can be skipped this time.
Why is this changed?
Comment #15
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedAdded changes as suggested in MR 358. Please review it.
Comment #16
quietone CreditAttribution: quietone as a volunteer commentedAh, wow now there are two merge requests. That is a new situation for me.
@sudiptadas19, there is a question in #13.
Comment #17
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@quietone
We are creating an anonymous user object here, that is the reason I made those changes to be more accurate.
'name' => 'anon' to 'name' => 'anonymous',
$this->anonUser to $this->anonymousUser
any problem with these changes? please suggest.
Comment #18
quietone CreditAttribution: quietone as a volunteer commentedThere are now two branches and two merge requests for this and it is not making it easy to work on this. And besides, this is a small change and doesn't need multiple branches, in my opinion. If another person works on this issue which MR do they use/review? It is clear as mud.
The first, MR320 has unresolved issues. All but one of those has been resolved in the second MR358. I can not find a way to mark the unresolved issues and resolved. I would like to close MR320 but I can't find a way to do that.
I say work here is now on MR358, which looks good. I just have one question.
I will repeat the question for the one unresolved question from MR320. It is minor but I would like to know ...
Comment #19
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@quietone in our case we are using $this->entityType->getKey('id'), this will return string|bool that is the reason we have used this condition. $query->condition($this->entityType->getKey('id'), '0', '<>')
Comment #20
quietone CreditAttribution: quietone as a volunteer commentedHmm. If it does return FALSE, then trying to set the condition will thrown a QueryException. Perhaps that could be handled better? Then again, just above is this,
So, at least using getKey this way is consistent. I've search core and do see that this pattern is common.
But my question, which admittedly could have been clearer, is why use '<>' and not '>'? Is it possible for a uid to be less than zero? Or is this just being defensive.
Comment #21
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@quietone we have put a condition for string '0'. To check uid is not equal to '0' we have used '<>'. If we go with int 0 then we can go for '>' instead of '<>'.
No, it is not possible that uid will be lesser than zero.
Can we go with condition($this->entityType->getKey('id'), 0, '>') instead of - condition($this->entityType->getKey('id'), '0', '<>') ?
Comment #22
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedAdded suggested changes, available in MR358. Please review.
Comment #23
quietone CreditAttribution: quietone as a volunteer commented@sudiptadas19, thanks. That makes more sense to me because uid is an integer.
I think all that is left is to make 358 mergeable, I am sure the problem is because #3184650: ContentEntity migration source adds revision ID as source key, incompatible with Drupal 8.8 and earlier was comitted.
Comment #25
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@anmolgoyal74 thanks for make MR 358 mergeable.
Please review the changes.
Comment #26
quietone CreditAttribution: quietone as a volunteer commentedWhile it is good that 358 is now mergeable it also means I can't apply it as a patch locally, which I like to do so I can read the code in my editor with my colors and fonts. Oh well, that boat has sailed on this one. Then I found a line was missing. I found it in the other MR but could not get a link to that one line, what a nuisance. So, I copy/pasted.
The good news is, we are one step closer.
Comment #27
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@quietone
is there, now it is wrapped in a condition
I have not added this condition. Please confirm whether need to do a modification.
Comment #28
quietone CreditAttribution: quietone as a volunteer commented@sudiptadas19, thanks! I clearly am having problem adjusting to gitlab interface and I forgot that #3184650: ContentEntity migration source adds revision ID as source key, incompatible with Drupal 8.8 and earlier was committed.
So, yes, MR 358 is RTBC. But I think that the unresolved issue needs to be closed first.
Comment #29
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedThanks, @quietone for the confirmation. Moving this to review state.
Comment #30
siddhant.bhosale CreditAttribution: siddhant.bhosale as a volunteer and at QED42 commentedComment #31
quietone CreditAttribution: quietone as a volunteer commentedLooks like the work here is to get MR 358 mergeable, it isn't showing up as mergeable.
Comment #32
quietone CreditAttribution: quietone as a volunteer commented@sudiptadas19, it looks like you haven't touched this for a while, remember to un-assign and set the status to Need Review. I would have noticed this much earlier otherwise.
After all the work MR358 is not mergeable. Let's go back to a patch please, there has been too much time wasted on fiddling with the MRs.
Marking this as a novice task for the creation of a patch from MR358.
Comment #33
quietone CreditAttribution: quietone as a volunteer commentedComment #35
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedCreated a patch from MR358, as suggested by @quietone.
Not adding an interdiff, as this is a small change.
Comment #36
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedAdded a new patch for the 9.3.x version.
Comment #37
quietone CreditAttribution: quietone as a volunteer commented@sudiptadas19, thank you!
I applied the patch and reviewed it. It took me a bit to remember why the assertion is not made when translations are involved. But it just takes a look at the ContentEntity::count to see why. Plus the same if block to avoid testing counts is used for other entities in the test so this is not doing anything new. And there is an issue to get counts when translations are involve. #2937166: Improve count() for ContentEntity source plugin, so there is no need for a followup.
Finally, back to RTBC.
Comment #40
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!