menu_link_maintain(), $op update critically broken.

Berdir - April 4, 2009 - 15:17
Project:Drupal
Version:7.x-dev
Component:menu system
Category:bug report
Priority:critical
Assigned:Berdir
Status:closed
Issue tags:Quick fix
Description

I'm writing tests for aggregator.module and noticed that menu_link_maintain() dies with a fatal error when called with $op update.

The reason is that $item is now an object, it was an array before and has not been converted in #320510: [DBTNG] revamp menu.inc with DBTNG syntax.

A test is not yet included, you can reproduce the issue by enabling the aggregator.module, create a category and then update it. it will die with an fatal error.

AttachmentSizeStatusTest resultOperations
drupal.menu_link_maintain_bug.patch594 bytesIdleFailed: Failed to apply patch.View details | Re-test

#1

mr.baileys - April 6, 2009 - 15:40
Status:needs review» reviewed & tested by the community

Confirmed bug, reviewed patch, applied patch, all good...

#2

pwolanin - April 6, 2009 - 16:28
Status:reviewed & tested by the community» needs work

No, I disagree - we made a choice to handle all menu links as associative arrays at all stages for consistency - hence the query should be altered to fetch associative arrays.

This is a bit ugly, but apparently is the way to do it for DBTNG:

$result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))

#3

pwolanin - April 6, 2009 - 16:43

Or Crell suggest we can use:

$result->setFetchMode(PDO::FETCH_ASSOC);

before the foreach.

#4

Berdir - April 6, 2009 - 16:53

Updated patch, it does now use fetchCol().

AttachmentSizeStatusTest resultOperations
drupal.menu_link_maintain_bug_2.patch747 bytesIdleFailed: Failed to apply patch.View details | Re-test

#5

Berdir - April 6, 2009 - 16:54
Status:needs work» needs review

Setting to needs review again.

#6

pwolanin - April 6, 2009 - 18:10

Hmm, looks ok - though not sure we've used that method much - I had to look at the doxygen to see what it does - I was confused with fetchField()

Can you double-check that this is correct if there are multiple rows in the result set?

#7

Berdir - April 8, 2009 - 13:04

Updated:

- Added some tests for menu_link_maintain(). Including adding, updating multiple links in different menus and delete
- Added a groupby to the query which loads the updated menus, we don't need to clear the cache of a menu multiple times.

AttachmentSizeStatusTest resultOperations
drupal.menu_link_maintain_bug_3.patch3.48 KBIdleFailed: 10706 passes, 6 fails, 0 exceptionsView details | Re-test

#8

System Message - April 8, 2009 - 13:20
Status:needs review» needs work

The last submitted patch failed testing.

#9

Berdir - April 8, 2009 - 13:41
Status:needs work» needs review

Forgot to add the change in menu_test.module...

AttachmentSizeStatusTest resultOperations
drupal.menu_link_maintain_bug_4.patch4.31 KBIdleFailed: Failed to apply patch.View details | Re-test

#10

pwolanin - April 8, 2009 - 13:58

sure - guess there is no reason not to group the results.

#11

pwolanin - April 8, 2009 - 14:18
Status:needs review» reviewed & tested by the community

new tests pass, looks good.

#12

Dries - April 13, 2009 - 12:18
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#13

System Message - April 27, 2009 - 12:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#14

agentrickard - July 3, 2009 - 19:33
Status:closed» needs work

This is actually still broken, IMO. Since the update $op doesn't use menu_link_save(), we can't get expected results for patches like #457450: Adds hooks to track changes to {menu_links}.

Shouldn't we just be calling menu_link_save()?

#15

agentrickard - July 4, 2009 - 16:35

OK. Here is a revised version of the patch which standardizes the 'update' op to use menu_link_save().

I think if we don't use menu_link_save() in both cases, then we have written an exception handler, not an API function.

AttachmentSizeStatusTest resultOperations
423690-menu-link-maintain.patch2.15 KBIdlePassed: 12398 passes, 0 fails, 0 exceptionsView details | Re-test

#16

agentrickard - July 4, 2009 - 16:37
Status:needs work» needs review

#17

pwolanin - July 10, 2009 - 01:12

I'm still not clear why we'd need to track the change if all that's changing is the title - are you going to update the node title based on this?

#18

agentrickard - July 10, 2009 - 15:53

Possibly. Who knows what someone might want to do with the information. And, technically, not just nodes might use this function.

#19

pwolanin - July 12, 2009 - 00:06

Probably premature optimization, but it would be nice to then tell menu_link_save that there are only title/options changes and that all the hierarchy info can be assumed to be correct as-is. Otherwise, we are doing a lot of work to make this change to one field. Still, I understand from a consistency standpoint why it's preferable.

#20

agentrickard - August 23, 2009 - 20:24
Status:needs review» fixed

I'm going to set this issue back to fixed and address this change over in #457450: Adds hooks to track changes to {menu_links}.

#21

System Message - September 6, 2009 - 20:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.