You are here

function drush_media_entity_updatedb_validate in Media entity 8.2

Implements drush_hook_COMMAND_validate().

File

./media_entity.drush.inc, line 13
Drush integration for media_entity.

Code

function drush_media_entity_updatedb_validate() {

  // This hook exists because when running DB updates using drush,
  // hook_requirements() is not enforced (see
  // https://github.com/drush-ops/drush/pull/2708 for more info on that).
  // Here we just re-evaluate all the checks from hook_requirements() and abort
  // the "updatedb/updb" command by returning FALSE to this hook if any of them
  // is not met.
  drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_FULL);

  // Normally users should remove Media Entity from the codebase after the
  // upgrade. However, if they don't do so, this function will be called on
  // subsequent DB upgrades, even if ME is not enabled. Don't proceed on those
  // circumstances.
  if (!\Drupal::moduleHandler()
    ->moduleExists('media_entity')) {
    return TRUE;
  }
  $checks = \Drupal::service('media_entity.cli')
    ->validateDbUpdateRequirements();
  if (empty($checks['errors'])) {
    return TRUE;
  }
  else {
    foreach ($checks['errors'] as $error_msg) {

      // We can't use drush_log() inside this hook.
      drush_print($error_msg);
    }
    return FALSE;
  }
}