Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates expect .module file to be available (Error when running updates for 1.x-1.0.26) #160

Open
manu-mei-singh opened this issue Apr 1, 2024 · 8 comments

Comments

@manu-mei-singh
Copy link

Hey ya'll,

I am updating Backup Migrate on a number of Backdrop instances.
When I try and the database updates on for backup_migrate-1.x-1.0.26 on Backdrop 1.27.1

I get the following error when I run bee -y updb on the command line :

Error: Call to undefined function backup_migrate_include() in backup_migrate_update_1009() (line 632 of /var/www/path/to/root/directory/modules/backup_migrate/backup_migrate.install).

If I run the web update I get the following error:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: https:///directory.fake/core/update.php?op=selection&token=va-qAhj8U0PAJASE3GxdtneHT_n5y0n6Ox_ULVF_zWM&id=59&op=do_nojs&op=do StatusText: Service unavailable (with message) ResponseText: Error: Call to undefined function backup_migrate_include() in backup_migrate_update_1009() (line 632 of var/www/path/to/root/directory/modules/backup_m

Note that I've changed the file paths to protect clients.

Any help would be greatly appreciated!

thanks!
Manu

@argiepiano
Copy link
Collaborator

argiepiano commented Apr 2, 2024

Thanks for reporting, @manu-mei-singh. Apparently there are certain instances when the update hook is run before Backdrop includes the main backup_migrate.module file. This is strange.

As a stopgap measure, you may want to change line 632 of backup_migrate.install manually from:
backup_migrate_include('profiles');

TO:
include_once (BACKDROP_ROOT . '/' . backdrop_get_path('module', 'backup_migrate') . '/includes/profiles.inc');

Then run update.php again.

Please report back here.

@argiepiano
Copy link
Collaborator

argiepiano commented Apr 2, 2024

Actually, that may not work, since line 7 of profiles.inc invokes that same function. This is a very strange situation - I'm wondering if another contrib module is actually making the update hooks run before the module files are loaded.

Anyway, you may want, instead, to try this (replace the function as follows):

/**
 * Add the exclude_filepaths configuration for the new "DB and active config" source to all profiles.
 */
function backup_migrate_update_1009() {
  include_once (BACKDROP_ROOT . '/' . backdrop_get_path('module', 'backup_migrate') . '/backup_migrate.module');
  backup_migrate_include('profiles');
  foreach (backup_migrate_get_profiles() as $profile) {
    if (!isset($profile->filters['sources']['db_config']['exclude_filepaths'])) {
      $profile->filters['sources']['db_config']['exclude_filepaths'] = '';
      $profile->save();
    }
  }
}

Then try running update.php again.

@argiepiano
Copy link
Collaborator

EDIT: I pasted the wrong function. Now fixed. This function is in backup_migrate.install

@manu-mei-singh
Copy link
Author

Hi @argiepiano , yup that worked.
It did create a bunch of warnings though. Anyway thanks for your help! Because there are few more Backdrop updates I need to do -- I created a git patch. It's also attached if anyone else needs it.
backup_migrate_1x1026.patch

@argiepiano
Copy link
Collaborator

Thansk, @manu-mei-singh. Would you post here some of the warnings?

Was this a D7 upgrade site, or "native" Backdrop? Also, it possible, it'd be helpful to know what contrib modules you have installed in the site. Given that BM is so widely used, I'd like to be sure other people don't run into this, so if there is a bug, I'd like to find it.

@manu-mei-singh
Copy link
Author

Hi @argiepiano ,

This was update was performed on a staging "native" backdrop site. I ran the update via the web (core/update.php).

Here are the warning messages from the logs:

Warning: Trying to access array offset on value of type bool in backup_migrate_item->decode_db_row() (line 549 of /backdrop_root/modules/backup_migrate/includes/crud.inc).

Warning: foreach() argument must be of type array|object, null given in backup_migrate_item->decode_db_row() (line 549 of /backdrop_root/modules/backup_migrate/includes/crud.inc).

And it looks like I got few of these warnings.

To confirm that the update did work, I ran bee -y updb, which gave me a confirmation that the database has been updated.

The other contrib modules are IMCE and CiviCRM.

hope that helps and thanks for the all your work on this!

@jenlampton
Copy link
Member

jenlampton commented Apr 3, 2024

Apparently there are certain instances when the update hook is run before Backdrop includes the main backup_migrate.module file. This is strange.

@argiepiano This is expected, no module files should ever be loaded at update time. You can't depend on module code working at the time modules are updated. Consider an upgrade from Drupal 7 - if the schema were in one state for D7 but the Backdrop .module code expected a different state for B (or for config to exist!) then loading the .module file could cause a fatal error. Updates should only call APIs directly, and interact with database/config directly.

As such, i would not recommend doing a module_load_include() to the .module file, but instead move any code that the update will need to run into a .inc file, and include that from both the install and .module file.

It's strange that you found an instance where those files were loaded at update time - opcode cache maybe?.

Is it possible this explains some of the other issues with updates, like #158?

@jenlampton jenlampton changed the title Error when running database updates for 1.x-1.0.26 Updates expect .module file to be available (Error when running updates for 1.x-1.0.26) Apr 3, 2024
@argiepiano
Copy link
Collaborator

@jenlampton, yes, I was leaning toward that explanation. I'll figure out a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants