We switched from 7.x-2.3 to 7.x-2.x to take advantage of some patches. Everything worked fine on my local install but when we deployed it to our dev server running Aegir, the install fails with the error below.

Seems like some change in xmlsitemap.drush.inc triggered it. Possibly one of these commits:

ERROR
exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'wd152devtestingw.semaphore' doesn't exist' in /var/aegir/platforms/NAMEREMOVED/includes/database/database.inc:2227

Stack trace: #0 /var/aegir/platforms/NAMEREMOVED/includes/database/database.inc(2227): PDOStatement->execute(Array)
#1 /var/aegir/platforms/NAMEREMOVED/includes/database/database.inc(697): DatabaseStatementBase->execute(Array, Array)
#2 /var/aegir/platforms/NAMEREMOVED/includes/database/database.inc(2406): DatabaseConnection->query('SELECT expire, ...', Array, Array)
#3 /var/aegir/platforms/NAMEREMOVED/includes/lock.inc(167): db_query('SELECT expire, ...', Array)
#4 /var/aegir/platforms/NAMEREMOVED/includes/lock.inc(146): lock_may_be_available('variable_init')
#5 /var/aegir/platforms/NAMEREMOVED/includes/bootstrap.inc(1181): lock_acquire('variable_init', 1)
#6 /var/aegir/platforms/NAMEREMOVED/includes/bootstrap.inc(2759): variable_initialize(Array)
#7 /var/aegir/platforms/NAMEREMOVED/includes/bootstrap.inc(2520): _drupal_bootstrap_variables()
#8 /var/aegir/platforms/NAMEREMOVED/includes/bootstrap.inc(2654): drupal_bootstrap(3, false)
#9 /var/aegir/platforms/NAMEREMOVED/includes/bootstrap.inc(2512): _drupal_bootstrap_page_cache()
#10 /var/aegir/platforms/NAMEREMOVED/sites/all/modules/contrib/xmlsitemap/xmlsitemap.drush.inc(14): drupal_bootstrap(3)
#11 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(1094): xmlsitemap_drush_command()
#12 phar:///usr/local/bin/drush-8.1.15.phar/commands/core/topic.drush.inc(38): drush_get_commands()
#13 [internal function]: topic_drush_help_alter(Array)
#14 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(1500): call_user_func_array('topic_drush_hel...', Array)
#15 phar:///usr/local/bin/drush-8.1.15.phar/includes/drush.inc(336): drush_command_invoke_all_ref('drush_help_alte...', Array)
#16 phar:///usr/local/bin/drush-8.1.15.phar/includes/backend.inc(866): drush_get_global_options(false)
#17 phar:///usr/local/bin/drush-8.1.15.phar/includes/backend.inc(746): _drush_backend_get_global_contexts(Array)
#18 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(135): drush_backend_invoke_concurrent(Array, Array, Array)
#19 /var/aegir/.drush/provision/provision.inc(431): drush_invoke_process('@wd152.dev-test...', 'provision-insta...', Array, Array, Array)
#20 /var/aegir/.drush/provision/platform/install.provision.inc(99): provision_backend_invoke('@wd152.dev-test...', 'provision-insta...', Array, Array)
#21 [internal function]: drush_provision_drupal_provision_install()
#22 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(422): call_user_func_array('drush_provision...', Array)
#23 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#24 [internal function]: drush_command()
#25 phar:///usr/local/bin/drush-8.1.15.phar/includes/command.inc(199): call_user_func_array('drush_command', Array)
#26 phar:///usr/local/bin/drush-8.1.15.phar/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#27 phar:///usr/local/bin/drush-8.1.15.phar/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#28 phar:///usr/local/bin/drush-8.1.15.phar/includes/startup.inc(458): drush_main()
#29 phar:///usr/local/bin/drush-8.1.15.phar/includes/startup.inc(365): drush_run_main(false, '/', 'Phar detected. ...')
#30 phar:///usr/local/bin/drush-8.1.15.phar/drush(114): drush_startup(Array)
#31 /usr/local/bin/drush-8.1.15.phar(10): require('phar:///usr/loc...') #32 {main}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bwaindwain created an issue. See original summary.

jacob.embree’s picture

Correct. This was caused by the patch in #2329991: XML sitemap needs to bootstrap to DRUPAL_BOOTSTRAP_CONFIGURATION before using variable_get in hook_drush_command(). XML Sitemap's Drush hook is being executed apparently before Drupal is installed enough to have a DRUPAL_BOOTSTRAP_VARIABLES bootstrap level.
Is there a way to check if the hook is being called without a full installation?

dagomar’s picture

I can confirm this issue. For us the issue even arises if we have the xmlsitemap module anywhere in our platform; installing the minimal or standard profiles in aegir still will fail because of this. I believe this might be because when drush runs it runs all hook_drush_command implementations from all modules present in the code base, not just those in the chosen installation profile.

I came up with a solution that works for us. I looked around to see if there are other modules which try to get a variable through variable_get in hook_drush_command, and found that the features module has something in place for this. I adapted their solution to xmlsitemap. Basically in the features module a check is done to see if a constant is defined in its .module file, and if so, it uses variable get, otherwise it hard codes the variable.

  // See if batch limit is defined.
  if (defined('XMLSITEMAP_BATCH_LIMIT')) {
    $batch_limit = variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT);
  }
  else {
    $batch_limit = 100;
  }
// [...] 'limit' => 'The limit of links of each type to process. Default value: ' . $batch_limit,

Note that I had to add the constant to the module file as none existed previously.

I believe this works because when drupal is bootstrapped, any constants coming from .module files will be available. In any case, this works for us, and I checked, the variable is indeed displaying the set batch limit in case you change it.

I have attached a patch.

dagomar’s picture

Status: Active » Needs review
jacob.embree’s picture

That looks good to me, but I haven't tested it yet.

pifagor’s picture

FileSize
2.16 KB

This is not a fully implemented patch. Here is an extended patch

jacob.embree’s picture

Status: Needs review » Reviewed & tested by the community
pifagor’s picture

  • pifagor committed 936c357 on 7.x-2.x
    Issue #2939318 by dagomar, pifagor, jacob.embree, bwaindwain: Updated...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

Fabianx’s picture

@pifagor:

You unfortunately missed this part in your re-worked patch.

As it is now this patch again breaks custom variable.inc implementations:

-  drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
+
+  // See if batch limit is defined.
+  if (defined('XMLSITEMAP_BATCH_LIMIT')) {
+    $batch_limit = variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT);
+  }
+  else {
+    $batch_limit = 100;
+  }

The variable_get() must only be called from hook_drush_command() when the constant is defined.

See #3

pifagor’s picture

Hello @Fabianx
I see See #3, and I see point

I believe this works because when drupal is bootstrapped, any constants coming from .module files will be available. In any case, this works for us, and I checked, the variable is indeed displaying the set batch limit in case you change it.

The constant should be available globally, so the code:

-  drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
+
+  // See if batch limit is defined.
+  if (defined('XMLSITEMAP_BATCH_LIMIT')) {
+    $batch_limit = variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT);
+  }
+  else {
+    $batch_limit = 100;
+  }

should not be