Problem/Motivation
There is a db_transaction(); in MenuRouterRebuildSubscriber
The problem with that is that nothing ensures that the menu router is actually stored in the database.
Note that this does not break anything and the issue is just cleanup.
Proposed resolution
Change the definition ofplugin.manager.menu.linkincore.services.ymlto pass in@databaseand store it in aconnection. property ofMenuTreeStorage.- Move the code block in
MenuRouterRebuildSubscriber::menuLinksRebuild()starting with$transaction = db_transaction();intoMenuTreeStorage::rebuild. Keep the lock mechanism inMenuRouterRebuildSubscriber. - Change the
db_transactionyou just moved into$this->connection->startTransaction. - Optional and can be a followup: write a unit test for
MenuLinkManager::rebuild. AFAIK there is no unit test currently that could be easily extended to include this method and so this part is not a novice task (but, feel free to try. You'd need to mock the plugin discovery, the module handler, the link override and the tree storage, I would borrow ideas/code fromLocalTaskManagerTest).
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #62 | 2396619-62.patch | 1.83 KB | Yogesh Sahu |
| #54 | interdiff-51-54.txt | 509 bytes | hardik_patel_12 |
| #54 | 2396619-54.patch | 1.78 KB | hardik_patel_12 |
| #32 | 2396619-32.patch | 1.68 KB | mitrpaka |
| #27 | interdiff-21-27.txt | 2.17 KB | mitrpaka |
Issue fork drupal-2396619
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 #1
chx commentedComment #2
chx commentedComment #3
chx commentedComment #4
dawehnerIf you would call the rebuild for your own, you should not have to take care about setting up the lock, starting a transaction etc.
The
MenuRebuildSubscribercode should also be entirely independent from the way how the menu tree is stored, soalternative number 2 is the WINNER!
Comment #5
chx commentedComment #6
dawehnerWe agreed on things, let's skip the assignment
Comment #7
chx commentedComment #8
dawehner@chx
Are you still into it? Maybe we could mark the issue as novice, so someone else has some fun working on it.
Comment #9
dawehnerMaybe this is a bit better, more verbose.
Comment #10
chx commentedComment #11
chx commentedComment #12
vj commentedI have created a patch by following the steps in "Proposed resolution".
I have not created tests, please guide me how to create it. Also let me know if any changes required in the patch.
Comment #14
chx commentedThanks for getting this one done! I am sorry for omitting this step -- but you still need to call
$this->menuLinkManager->rebuild();fromMenuRouterRebuildSubscriber::menuLinksRebuild().As for the test, as I said, let's leave that to a followup, that's a slightly bit too complicated for a Novice task, I think.
Comment #15
dawehnerI think its fair to not require an additional test for just the moving, given that we have some dort of general integration for menus all over the place already.
Comment #16
rpayanmLet me try.
Comment #18
dawehner... I don't think the menu.link plugin manager needs the database.
Having the lock here, in the middle of nowhere, is kinda pointless. Better wrap the
->rebuild()of the menu link manager.Comment #19
acrosmanI'm at DrupalCon LA, and working on moving this forward.
Comment #20
acrosmanRerolled that patch from #16 to try to take into account the suggestions given in response. I wasn't clear if the second suggestion was to move the call to rebuild() into the locking logic, or move the logic into the method. My instinct is that it should be in the method, and so I moved it there.
Comment #21
acrosmanReplacing the file from 20 with a file with the proper file extension.
Comment #22
willzyx commentedComment #24
msgph commentedI'm in DrupalCon Barcelona and I will try to fix the failing patch
Contrib task: https://www.drupal.org/contributor-tasks/create-patch
Comment #25
duaelfrI'm mentoring at DrupalCon Barcelona on that issue.
@msgph you might have a look at the contributor task page about writing an automated test too.
Comment #26
msgph commentedJust updating the summary for now, the first proposed solution has been done in the first patch #12. Second proposed solution needs some work.
Comment #27
mitrpaka commentedPatch attached based on the first proposed solution and original proposed resolution. Lock mechanism kept in MenuRouterRebuildSubscriber as proposed originally (as MenuTreeStructure doesn't have lock backend defined at the moment). Not sure whether should be added or not?
Patch created in co-operation with @msgph in DrupalCon Barcelona sprint.
Comment #30
pwolanin commentedDo we really even need to call
db_ignore_replica()?It seems that affects the $_SESSION, so is only for the current user in any case.
Comment #31
mitrpaka commentedComment #32
mitrpaka commentedUpdated patch to pass all tests trial ...
Comment #35
mitrpaka commentedUpdated patch to pass all tests ...
Comment #40
ajitsPatch was outdated. Re-rolled against the latest head on 8.3.x
Did not look at failing tests yet.
Comment #42
dawehnerRegarding point 4 in the issue summary, we have some test failures, so understanding them might help to judge whether we need sort of unit test / more educated test.
Comment #46
vacho commentedComment #47
vacho commentedWhen I review an tried to reroll, I noticed that this problem is already solved in code.
At file /core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php:75
Because
$this->menuLinkManager->rebuild();
And
$this->replicaKillSwitch->trigger(); (equivalent to db_ignore_replica();)
Are the code that the patch add... and it is already place in 8.8.x branch.
Comment #48
ajitsChanging the status as per #47. Maybe this just needs to be closed if the fix is already in?
Comment #51
hardik_patel_12 commentedRerolling the patch against 8.9.x-dev branch.
Comment #53
rajandro commentedRemoving

Needs rerolltag as patch #51 (2396619-51.patch) is working fine with the current core version.Comment #54
hardik_patel_12 commentedSolving failed test cases.
Comment #55
hardik_patel_12 commentedComment #60
longwaveThis came up in #bugsmash triage. There is no functional bug here, reclassifying as a cleanup task.
Comment #62
Yogesh Sahu commentedAdding the patch for drupal 9.5.x.
no interdiff because #54 patch fail to apply.
Comment #64
davidmv97 commentedThe patch provided by Yogesh Sahu works on Drupal 9.5 with PHP 8.1 and MariaDB 10.4
Comment #65
sarathkmUpdating the version to 10.1.x dev for reach
Comment #69
xjmI'd say this isn't really currently in a novice state. Thanks!