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.
If the update module is disabled there is fatal error when trying to get update_cache
Fatal error: Call to undefined function _update_cache_get() in (...)/modules/update/update.compare.inc on line 801
Comment | File | Size | Author |
---|---|---|---|
#21 | drupal-7-schema-check-for-update-module-2416475-21.patch | 13.96 KB | greg.harvey |
#4 | nagios-update_dependency-2416475-4-D7.patch | 4.75 KB | galooph |
Comments
Comment #1
Pene CreditAttribution: Pene commentedThe exact error message this (on nginx): PHP message: PHP Fatal error: Call to undefined function update_get_projects() in sites/all/modules/contrib/nagios/nagios.module on line 421
So if the update module is disabled, every page that calls update_get_projects() will broke (eg. admin/modules), and the module is also useless.
I think, the correct way of solve this problem is to put a dependency into the .info file. Patch attached.
Comment #2
Pene CreditAttribution: Pene commentedCorrected the name of the patch, and now includes an update hook to enable the update module.
Comment #3
greg.harveyI'm not sure a dependency is desired here. It might be better to wrap these function calls in
module_exists('update')
checks? Opinions welcome...Comment #4
galooph CreditAttribution: galooph at Code Enigma commentedHere's an alternative patch/idea.
From what I can see, we directly call three functions provided by the update module:
I've attached a patch that adds a wrapper function for each of these three. Each new wrapper function first checks to see if the update module is enabled. If it is, then the update function is called straight away and the output returned. If the update module is disabled, then the required update files are included before the functions are called.
So update_get_projects() becomes _nagios_update_get_projects(), and so on.
Might be a better approach rather than requiring the update module to be enabled.
Not the most elegant solution, but I've tested the modules page, /nagios, drush nagios-updates and drush nagios-check requirements with the update module both enabled and disabled, and got no errors.
Comment #5
galooph CreditAttribution: galooph at Code Enigma commentedActually, wrapping those update functions might also allow us to do some automated testing. By passing an extra parameter into the functions, we could return dummy update data simulating specific states.
Comment #6
C-LogemannI can confirm the bug and think the solution by @galooph is the better way to solve.
The patch of #4 is working and solving the bug: RTBC +1.
@galooph #5:
I agree that this is also a good idea.
Comment #7
C-LogemannComment #8
C-LogemannComment #9
helmo CreditAttribution: helmo at Initfour websolutions commentedWorks as expected.
Comment #11
greg.harveyThanks all for the work and the feedback. Committed to the 7.x-1.x branch.
Comment #12
greg.harveyI haven't looked at how the Drupal 8 version of the module currently handles this, but given this patch wasn't applied to the Drupal 7 branch when the Drupal 8 port was done, I'd imagine the bug persists there...?
Comment #13
chrinor2002 CreditAttribution: chrinor2002 as a volunteer commentedCan anyone verify what happens when a minimal install profile is used and nagios is enabled? I am getting:
using drupal 7.42
nagios 7.x-1.x-dev
My guess is that because the update module is never enabled in the first place, the schema for the update module is never installed, therefor some of these calls are failing,
Comment #14
greg.harveyHmmm, interesting. I think we need to go back to the
module_exists()
idea then. We'll look into it asap!Comment #15
greg.harveyOK, so I see the problem with the Drupal 7 code. Dan's code tries to load the update module even if it's not enabled, but doesn't account for the fact the schema might be absent:
http://cgit.drupalcode.org/nagios/commit/?id=e5cf290
So I guess we can't do that. The nicest thing to do would be to check for the schema and error out with a watchdog message if there's no schema. I guess db_table_exists() ought to do it. I'll have a go... :-)
Comment #16
greg.harveyAttached is a patch that wraps most of the code relating to Drupal update checking in a db_table_exists() call checking for the 'cache_update' table.
One thing that makes me wonder is I looked at nagios_check_requirements() function and it also makes a number of update related calls. On closer inspection, it seems to *rely* on the core update module to build a list of enabled modules to invoke hook_requirements() against. This feels wrong to me because while we may not want to update a module, that doesn't mean we don't want to check it's requirements.
The bigger problem is the commenting in the code states:
And the way this currently works is by calling an update module function:
This will always fail if update module was never initially installed. So unless there's another way to do this, without using the update module, we basically have a hard dependency on update.module in the Nagios module and all this code to try and work around the fact it might not be enabled is null and void. We should just declare a dependency and assume it is enabled!
Would love some thoughts on this...
Comment #17
greg.harveyActually, what am I talking about? We can implement a slightly altered version of update_get_projects() - it's a simple enough function - and we still won't need an actual dependency (which I really don't want):
https://api.drupal.org/api/drupal/modules!update!update.compare.inc/func...
Comment #18
greg.harveyReplacement patch attached.
Comment #19
greg.harveySo there's a call to _nagios_update_get_available() as well, which tries to interact with update.module's cache. Working on a way around that too.
Comment #20
greg.harveyThis code here ultimately calls update_get_available() which is heavily tied to the update module's caching in a way that means unpicking it will be ugly:
I think there's not much choice but to just accept this will break without the update module and write some warnings into watchdog.
Comment #21
greg.harveyNew patch, this one includes an extra requirements check to actively warn people if the Update module is disabled and also should at least stop *errors* if it's never been installed. (Last patch still had some circumstances where the Nagios status page threw a db error because of the missing update module cache table.)
Comment #22
greg.harveyComment #23
greg.harveyI could still use another opinion, but this works for me now on simplytest.me - I can uninstall the Update module completely and Nagios still works and doesn't error. Plus it warns on the status report page that you should enable the Update module for the best performance of the module.
Comment #24
Pene CreditAttribution: Pene commentedYep, RTBC. Thanks Greg!
Comment #26
greg.harveyAlright, Drupal 7 fix in, Drupal 8 will still need comparing and checking.
Comment #27
Gogowitsch CreditAttribution: Gogowitsch at QuoData GmbH Quality & Statistics for ÖQUASTA commentedI have just fixed this in Drupal 8; will push shortly.
Comment #30
solideogloria CreditAttribution: solideogloria commentedCould we get a new release for 7.x that includes this fix?
Comment #31
Gogowitsch CreditAttribution: Gogowitsch at QuoData GmbH Quality & Statistics for ÖQUASTA commentedThanks for the nudge. This fix is now part of the Drupal 7 release Nagios 7.x-1.4.