X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmedia_entity%2Fmedia_entity.drush.inc;fp=web%2Fmodules%2Fcontrib%2Fmedia_entity%2Fmedia_entity.drush.inc;h=15704470fbe25b3d93a25b25957fa19f3a250ee4;hp=0000000000000000000000000000000000000000;hb=9e65bae52407293a5182f19dc57b5628b09e92f4;hpb=af6d1fb995500ae68849458ee10d66abbdcfb252 diff --git a/web/modules/contrib/media_entity/media_entity.drush.inc b/web/modules/contrib/media_entity/media_entity.drush.inc new file mode 100644 index 000000000..15704470f --- /dev/null +++ b/web/modules/contrib/media_entity/media_entity.drush.inc @@ -0,0 +1,85 @@ +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; + } +} + +/** + * Implements hook_drush_command(). + */ +function media_entity_drush_command() { + + $items['media-entity-check-upgrade'] = [ + 'description' => 'Check upgrade requirements for Media Entity into Media in core.', + 'aliases' => ['mecu'], + 'core' => ['8+'], + 'examples' => [ + "drush mecu" => "Checks upgrade requirements for Media Entity while upgrading to Media in core.", + ], + ]; + + return $items; +} + +/** + * Callback for drush commmand "media-entity-check-upgrade" (mecu). + */ +function drush_media_entity_check_upgrade() { + // This command is useless if the DB updates have already been run. + if (drupal_get_installed_schema_version('media_entity') >= 8004) { + drush_log(dt('Your site has already run the media_entity DB updates. If you believe this is not correct, you should consider rolling back your database to a previous backup and try again.'), LogLevel::WARNING); + return; + } + + drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_FULL); + $checks = \Drupal::service('media_entity.cli')->validateDbUpdateRequirements(); + + if (empty($checks['errors'])) { + drush_log(sprintf("\033[1;32;40m\033[1m%s\033[0m", '✓') . ' ' . dt('SUCCESS: All upgrade requirements are met and you can proceed with the DB updates.'), LogLevel::OK); + } + else { + drush_log(sprintf("\033[31;40m\033[1m%s\033[0m", '✗') . ' ' . dt('ERROR: Your site did not pass all upgrade checks. You can find more information in the error messages below.'), LogLevel::ERROR); + } + foreach ($checks['passes'] as $pass_msg) { + drush_log($pass_msg, LogLevel::OK); + } + foreach ($checks['errors'] as $error_msg) { + drush_log($error_msg, LogLevel::ERROR); + } +}