Drush updb failed on hook updates 9003 and 9004

Created on 13 December 2022, almost 2 years ago
Updated 1 February 2024, 10 months ago

Problem/Motivation

During execution of update hooks, Drush fails with the following error:

>  [notice] Update started: opigno_messaging_update_9003
>  [error]  The module module does not exist.
>  [error]  Update failed: opigno_messaging_update_9003

and
>  [notice] Update started: opigno_messaging_update_9004
>  [error]  The module opigno_lms does not exist.
>  [error]  Update failed: opigno_messaging_update_9004

Steps to reproduce

Apply module update from a previous version, in my case I was applying update to "opigno/opigno_lms", via composer 1.x, from version 2.29. Now using "opigno/opigno_lms" version 3.1.1

Proposed resolution

Resolution to the hook_update_9003, hook_update_9004 is required, since it called incorrect set of function arguments:

  function opigno_messaging_update_9003() {
    module_load_include('install', 'opigno_module');
    _opigno_module_apply_update('module', 'opigno_messaging', 'config/optional', [
	  'views.view.private_message'
	]);
  }
  function opigno_messaging_update_9004() {
    module_load_include('install', 'opigno_module');
    if (!\Drupal::moduleHandler()->moduleExists('honeypot')) {
      \Drupal::service('module_installer')->install(['honeypot']);
    }
    _opigno_module_apply_update('profile', 'opigno_lms', 'config/optional', ['honeypot.settings']);
  }
// Note that the "_opigno_module_apply_update" requires first argument to be a module name (it appears that a module type(theme, profile or theme) was passed instead). please check opigno_module.install file.

 

The expected function call is:

  function opigno_messaging_update_9003() {
    module_load_include('install', 'opigno_module');
    _opigno_module_apply_update('opigno_messaging', 'config/optional', [
	  'views.view.private_message',
	]);
  }
  Calling the config files from profile is a work around, created new menthod _opigno_messaging_apply_update (adapted from opigno_lms.install)
  /**
   * Import honeypot configs.
   */
  function opigno_messaging_update_9004() {
    if (!\Drupal::moduleHandler()->moduleExists('honeypot')) {
      \Drupal::service('module_installer')->install(['honeypot']);
    }
    _opigno_messaging_apply_update('profile', 'opigno_lms', 'config/optional', [
	  'honeypot.settings',
	]);
  }
  /**
   * Configs update helper function.
   */
  function _opigno_messaging_apply_update($type, $name, $path, $ymls) {
    $theme_path = sprintf("%s/%s/", \Drupal::service('extension.list.' . $type)->getPath($name), $path);
    $config_factory = \Drupal::configFactory();
    $config_storage = \Drupal::service('config.storage');
    $configs = [];
    foreach ($ymls as $yml) {
      $configs[$yml] = $theme_path;
    }
    foreach ($configs as $config => $config_path) {
      $source = new FileStorage($config_path);
      $data = $source->read($config);
      if (is_array($data)) {
        $config_factory->getEditable($config)->setData($data)->save(TRUE);
        $config_storage->write($config, $data);
      }
      else {
        \Drupal::messenger()->addWarning(t('Incorrect data of @config', ['@config' => $config]));
      }
    }
  }

Remaining tasks

  1. Validate the patch provided by a broader community
  2. commit to the module codebase

User interface changes

N/A (no)

API changes

N/A (no)

Data model changes

N/A (no)

🐛 Bug report
Status

RTBC

Version

3.0

Component

Code

Created by

🇮🇳India kuhikar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024