Problem/Motivation

The upgrade process is generating an error because it can't locate some function called db_or. If the module is in the wrong place for the upgrade to find it, please let me know.

Thanks for any help.

Steps to reproduce

  1. Start with a clean version of Drupal 9.0.8 built with composer. Running php7.4.
  2. Install DMU: composer require 'drupal/drupalmoduleupgrader:^1.5'
  3. Install drush composer require drush/drush
  4. Place module in question in web/modules/contrib/. In this case, this means the Annotation module from here:
    https://www.drupal.org/project/annotation
  5. Run dmu-analyze. Get an empty report:
     vendor/drush/drush/drush dmu-analyze annotation
    Indexing...
    done.
    
  6. And then run dmu-upgrade and get the error:
     vendor/drush/drush/drush dmu-upgrade annotation
    Indexing...
    done.
     [warning] annotation does not implement hook_hook_entity_info.
     [error]  Error: Call to undefined function Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\db_or() in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\HookFormAlter->convert() (line 25 of /var/www/html/ann3/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFormAlter.php) #0 /var/www/html/ann3/web/modules/contrib/drupalmoduleupgrader/src/Commands/DrupalmoduleupgraderCommands.php(188): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\HookFormAlter->convert()
    #1 [internal function]: Drupal\drupalmoduleupgrader\Commands\DrupalmoduleupgraderCommands->upgrade()
    #2 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
    #3 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #4 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #5 /var/www/html/ann3/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #6 /var/www/html/ann3/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #7 /var/www/html/ann3/vendor/symfony/console/Application.php(1018): Symfony\Component\Console\Command\Command->run()
    #8 /var/www/html/ann3/vendor/symfony/console/Application.php(271): Symfony\Component\Console\Application->doRunCommand()
    #9 /var/www/html/ann3/vendor/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun()
    #10 /var/www/html/ann3/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
    #11 /var/www/html/ann3/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun()
    #12 /var/www/html/ann3/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
    #13 /var/www/html/ann3/vendor/drush/drush/drush(4): require('/var/www/html/a...')
    #14 {main}. 
    Error: Call to undefined function Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\db_or() in /var/www/html/ann3/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFormAlter.php on line 25 #0 /var/www/html/ann3/web/modules/contrib/drupalmoduleupgrader/src/Commands/DrupalmoduleupgraderCommands.php(188): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\HookFormAlter->convert()
    #1 [internal function]: Drupal\drupalmoduleupgrader\Commands\DrupalmoduleupgraderCommands->upgrade()
    #2 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
    #3 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #4 /var/www/html/ann3/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #5 /var/www/html/ann3/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #6 /var/www/html/ann3/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #7 /var/www/html/ann3/vendor/symfony/console/Application.php(1018): Symfony\Component\Console\Command\Command->run()
    #8 /var/www/html/ann3/vendor/symfony/console/Application.php(271): Symfony\Component\Console\Application->doRunCommand()
    #9 /var/www/html/ann3/vendor/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun()
    #10 /var/www/html/ann3/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
    #11 /var/www/html/ann3/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun()
    #12 /var/www/html/ann3/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
    #13 /var/www/html/ann3/vendor/drush/drush/drush(4): require('/var/www/html/a...')
    #14 {main}
    Error: Call to undefined function Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\db_or() in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\HookFormAlter->convert() (line 25 of /var/www/html/ann3/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookFormAlter.php).
     [warning] Drush command terminated abnormally.
    
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bogdog400 created an issue. See original summary.

bogdog400’s picture

I downgraded from the dev version to 1.5 and got the same error.

solideogloria’s picture

If you look at the code:

    // @FIXME This is not working (returns empty result set)...don't know why.
    $alter_hooks = $indexer
      ->getQuery()
      ->condition(db_or()
        ->condition('id', $target->id() . '_form_alter')
        ->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE')
      )
      ->execute();

So maybe this is why.

db_or() and db_like() are both deprecated in 8.0.0 and removed in 9.0.0.

solideogloria’s picture

Status: Active » Needs review
StatusFileSize
new2.07 KB

Though this was a bit tricky to find the right way to do the OR-ing, I figured it out.

The patch replaces the instances of db_or and db_like. I tested it on the module you mentioned, and it works now.

ALSO, I noticed that the LIKE's weren't escaped properly, because underscores are wildcards in SQL, so I fixed that, too.

solideogloria’s picture

Title: Upgrade fails on missing function "db_or" » Drupal 9 cannot use "db_or", "db_like"
solideogloria’s picture

Parent issue: » #3184120: Drupal 9 readiness

tyler36 made their first commit to this issue’s fork.

tyler36’s picture

@solideogloria , almost there.

Patch changes error to
Error: Class 'Drupal\corefake\Driver\Database\corefakeWithAllCustomClasses\Condition' not found in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\HookFormAlter->convert()

I think you forgot to import the class
use Drupal\Core\Database\Query\Condition;

(sorry ... not sure how to create patches yet)

solideogloria’s picture

@tyler36 You should read this page: Making a patch | Using Git to Contribute to Drupal.

solideogloria’s picture

I added the import. Please review again. Thanks.

Also, for reference, change the issue status to "Needs Work" if you find something like that in the future.

jcnventura’s picture

And interdiffs :)

Would be good to have either @bogdog400 or @tyler36 test and review this. Once you do, please set the status to 'Reviewed and tested by community' if @solideogloria's patch fixed the issue.

solideogloria’s picture

StatusFileSize
new420 bytes
tyler36’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed.

- Reproduced error on Drupal 9.0.3.
- Applied #10 patch
- Run `drush dmu-upgrade annotation`
- Recieved new message

Indexing...
done.
 [warning] annotation does not implement hook_hook_entity_info.

- Code appears to have been updated as expected

PS. @solideogloria, thanks for your patience and guidance

jcnventura’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the work and review, @solideogloria and @tyler36

Status: Fixed » Closed (fixed)

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