Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / media_entity / media_entity.drush.inc
1 <?php
2
3 /**
4  * @file
5  * Drush integration for media_entity.
6  */
7
8 use Drush\Log\LogLevel;
9
10 /**
11  * Implements drush_hook_COMMAND_validate().
12  */
13 function drush_media_entity_updatedb_validate() {
14   // This hook exists because when running DB updates using drush,
15   // hook_requirements() is not enforced (see
16   // https://github.com/drush-ops/drush/pull/2708 for more info on that).
17   // Here we just re-evaluate all the checks from hook_requirements() and abort
18   // the "updatedb/updb" command by returning FALSE to this hook if any of them
19   // is not met.
20   drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_FULL);
21
22   // Normally users should remove Media Entity from the codebase after the
23   // upgrade. However, if they don't do so, this function will be called on
24   // subsequent DB upgrades, even if ME is not enabled. Don't proceed on those
25   // circumstances.
26   if (!\Drupal::moduleHandler()->moduleExists('media_entity')) {
27     return TRUE;
28   }
29
30   $checks = \Drupal::service('media_entity.cli')->validateDbUpdateRequirements();
31   if (empty($checks['errors'])) {
32     return TRUE;
33   }
34   else {
35     foreach ($checks['errors'] as $error_msg) {
36       // We can't use drush_log() inside this hook.
37       drush_print($error_msg);
38     }
39     return FALSE;
40   }
41 }
42
43 /**
44  * Implements hook_drush_command().
45  */
46 function media_entity_drush_command() {
47
48   $items['media-entity-check-upgrade'] = [
49     'description' => 'Check upgrade requirements for Media Entity into Media in core.',
50     'aliases' => ['mecu'],
51     'core' => ['8+'],
52     'examples' => [
53       "drush mecu" => "Checks upgrade requirements for Media Entity while upgrading to Media in core.",
54     ],
55   ];
56
57   return $items;
58 }
59
60 /**
61  * Callback for drush commmand "media-entity-check-upgrade" (mecu).
62  */
63 function drush_media_entity_check_upgrade() {
64   // This command is useless if the DB updates have already been run.
65   if (drupal_get_installed_schema_version('media_entity') >= 8004) {
66     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);
67     return;
68   }
69
70   drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_FULL);
71   $checks = \Drupal::service('media_entity.cli')->validateDbUpdateRequirements();
72
73   if (empty($checks['errors'])) {
74     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);
75   }
76   else {
77     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);
78   }
79   foreach ($checks['passes'] as $pass_msg) {
80     drush_log($pass_msg, LogLevel::OK);
81   }
82   foreach ($checks['errors'] as $error_msg) {
83     drush_log($error_msg, LogLevel::ERROR);
84   }
85 }