3 namespace Drupal\media_entity\Commands;
5 use Drush\Commands\DrushCommands as DrushCommandsBase;
6 use Drupal\media_entity\CliService;
9 * Add commands for Drush 9.
11 class DrushCommands extends DrushCommandsBase {
16 * @var \Drupal\media_entity\CliService
18 protected $cliService;
21 * MediaEntityCommands constructor.
23 * @param \Drupal\media_entity\CliService $cli_service
24 * The CLI service which allows interoperability.
26 public function __construct(CliService $cli_service) {
27 $this->cliService = $cli_service;
31 * Check upgrade requirements for Media Entity into Media in core.
33 * @command media_entity:check-upgrade
35 * Checks upgrade requirements for Media Entity while upgrading to Media in
37 * @aliases mecu,media-entity-check-upgrade
39 public function mediaEntityCheckUpgrade() {
40 drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_FULL);
41 $logger = $this->logger();
42 // This command is useless if the DB updates have already been run.
43 if (drupal_get_installed_schema_version('media_entity') >= 8201) {
44 $logger(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.'));
48 $checks = $this->cliService->validateDbUpdateRequirements();
50 if (empty($checks['errors'])) {
51 $logger->success(sprintf("\033[1;32;40m\033[1m%s\033[0m", '✓') . ' ' . dt('All upgrade requirements are met and you can proceed with the DB updates.'));
54 $logger->error(sprintf("\033[31;40m\033[1m%s\033[0m", '✗') . ' ' . dt('Your site did not pass all upgrade checks. You can find more information in the error messages below.'));
56 foreach ($checks['passes'] as $pass_msg) {
57 $logger->success($pass_msg);
59 foreach ($checks['errors'] as $error_msg) {
60 $logger->error($error_msg);