I'm just documenting this here, as it took me several hours to trace. But (I hope) it's an edge case that doesn't actually need work. Though there is a place it can be improved.

Symptom:
at the far end of a migration, after doing as much of the content conversions (entityreference fields etc) on my huge site, and eventually finally doing the node_gallery update.php, things were working.
Until I cleared the cache.
At which point, 2/3 of my admin menu items went away.

After a few DB restores and all sorts of random poking around, I found that
* clearing the cache - rebuilding the menu router - crashed part-way through, which is why most of my site didn't work.

Further tracing and debug narrowed it down to an error (seen through drush cc menu) that started like:

WD menu: PDOException: SQLSTATE[23000]: Integrity constraint         ESC[31;40mESC[1m[error]ESC[0m
violation: 1048 Column 'title' cannot be null: INSERT INTO
{menu_router} ......

Additional debug narrowed the offending insert to one generated by node_gallery_api_menu()

WD menu: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'link_title'      [error]
cannot be null: INSERT INTO {menu_links} (menu_name, plid, link_path, hidden, external, has_children,
expanded, weight, module, link_title, options, customized, updated) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3,
:db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9,
:db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array
(
    [:db_insert_placeholder_0] => navigation
    [:db_insert_placeholder_1] => 66971
    [:db_insert_placeholder_2] => node/%/upload/node_gallery_image
    [:db_insert_placeholder_3] => -1
    [:db_insert_placeholder_4] => 0
    [:db_insert_placeholder_5] => 0
    [:db_insert_placeholder_6] => 0
    [:db_insert_placeholder_7] => -2
    [:db_insert_placeholder_8] => system
    [:db_insert_placeholder_9] => 
    [:db_insert_placeholder_10] => a:0:{}
    [:db_insert_placeholder_11] => 0
    [:db_insert_placeholder_12] => 0
)
 in menu_link_save() (line 3126 of .../includes/menu.inc).

To skip to the end ...

* Our site (for reasons lost in time) once had TWO node_gallery relationships, as seen at /admin/config/content/node-gallery.
* One of those relationships, now unused, referred to a content type (node_gallery_image) that had since been deleted from the system (we'd replaced it with a generic 'image' content type that was used more widely)
* When the content type was deleted, the nodegallery relationship was invalidated, but not removed
And now, years later, the code found in D7 hook_menu :
- lists the relationships, including the broken one
- tries to load a link to that content type and get its name
- does not validate it's OK
- then tries to make a menu item named after it
- core menu does not validate it either
= and the database dies.

Now I've found it, I just want to cry, but OTOH, I think this problem is so far out there nobody else should ever hit it.
But to get my site online again, I went in to node_gallery_api.module:163~
and put in a check and an early exit.

      foreach ($relationship->item_types as $item_type) {
        $type_info = node_type_load($item_type);
        if (! $type_info) {
          watchdog(__FUNCTION__, "Invalid type referred to - can't init %item_type. You probably need to review the content types mentioned in the  node_gallery relationships.", array('%item_type' => $item_type), WATCHDOG_ERROR);
          continue;
        }
        $items['node/%node_gallery_api_gallery/upload/' . $item_type] = array(

(╯︵╰,)

Comments

thomasmurphy’s picture

You poor b@stard

thomasmurphy’s picture

Issue summary: View changes

fixed code tags

peter caritas’s picture

Thank you thank you thank you! I've been pulling my hair out over this for the last 6 hours. The content type we deleted was created on the D7 install, but the site itself was upgraded from D6 and I think node gallery was installed in D6 at one point. Crazy.