Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / media_entity / src / CliService.php
1 <?php
2
3 namespace Drupal\media_entity;
4
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7
8 /**
9  * Class CliService.
10  *
11  * @internal
12  */
13 class CliService {
14
15   use StringTranslationTrait;
16
17   /**
18    * The module handler.
19    *
20    * @var \Drupal\Core\Extension\ModuleHandlerInterface
21    */
22   protected $moduleHandler;
23
24   /**
25    * CliService constructor.
26    *
27    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
28    *   The module handler.
29    */
30   public function __construct(ModuleHandlerInterface $module_handler) {
31     $this->moduleHandler = $module_handler;
32   }
33
34   /**
35    * Verify if the upgrade to Media in core is possible.
36    *
37    * @return array
38    *   An associative array with two keys:
39    *   - errors: An array of error messages, one per requirement that failed.
40    *     An empty array here means that the site can proceed with the upgrade
41    *     path.
42    *   - passes: An array of success messages, one per requirement verified.
43    */
44   public function validateDbUpdateRequirements() {
45     $checks = [
46       'errors' => [],
47       'passes' => [],
48     ];
49
50     module_load_install('media_entity');
51
52     // This update only makes sense with core >= 8.4.x.
53     $version = explode('.', \Drupal::VERSION);
54     if ($version[1] < 4) {
55       $checks['errors'][] = $this->t('The Media Entity 2.x upgrade path only works with Drupal core >= 8.4.x');
56     }
57     else {
58       $checks['passes'][] = $this->t('Drupal core is the correct version (>= 8.4.0). [@version detected]', ['@version' => \Drupal::VERSION]);
59     }
60
61     // This update can't proceed if there already is an enabled module called
62     // "media".
63     if ($this->moduleHandler->moduleExists('media')) {
64       $checks['errors'][] = $this->t('In order to run the Media Entity 2.x upgrade, please uninstall and remove from the codebase the contributed "Media" module.');
65     }
66     else {
67       $checks['passes'][] = $this->t('The contributed "Media" module is not installed.');
68     }
69
70     // Prevent the updates from running if there is a type-provider that is
71     // still on the 1.x branch.
72     $incompatible_modules = _media_entity_get_incompatible_modules();
73     if (!empty($incompatible_modules)) {
74       $provider_modules = !empty($incompatible_modules['providers']) ? implode(", ", $incompatible_modules['providers']) : '';
75       $additional_msg_providers = !empty($provider_modules) ? ' ' . $this->t('The following modules provide source plugins and need to be upgraded: @provider_modules.', [
76         '@provider_modules' => $provider_modules,
77       ]) : '';
78       $dependent_modules = !empty($incompatible_modules['modules']) ? implode(", ", $incompatible_modules['modules']) : '';
79       $additional_msg_dependent = !empty($dependent_modules) ? ' ' . $this->t('The following modules depend on media entity and need to be either upgraded or uninstalled: @dependent_modules.', [
80         '@dependent_modules' => $dependent_modules,
81       ]) : '';
82       $checks['errors'][] = $this->t('Before continuing, please make sure all modules that provide plugins for Media Entity (or depend on it) have their code updated to their respective 2.x branches. Note that you will probably need to revert to the 1.x branch of the Media Entity module if you want to uninstall existing plugin modules.') . $additional_msg_providers . $additional_msg_dependent;
83     }
84     else {
85       $checks['passes'][] = $this->t('All provider plugins and modules depending on media_entity are up-to-date.');
86     }
87
88     $module_data = system_rebuild_module_data();
89
90     // Generic media types should now live in the contrib Media Entity Generic
91     // module, which should be available at the codebase.
92     $generic_types = _media_entity_get_bundles_by_plugin('generic');
93     if ($generic_types) {
94       if (!isset($module_data['media_entity_generic'])) {
95         $checks['errors'][] = $this->t('One or more of your existing media types are using the Generic source, which has been moved into a separate "Media Entity Generic" module. You need to download this module to your codebase before continuing.');
96       }
97       else {
98         $checks['passes'][] = $this->t('The "Media Entity Generic" module is available.');
99       }
100     }
101
102     // Actions now live in the contributed media_entity_actions, until generic
103     // entity actions are part of Drupal core (2916740).
104     if (!isset($module_data['media_entity_actions']) && !file_exists(\Drupal::root() . '/core/modules/media/src/Plugin/Action/PublishMedia.php')) {
105       $checks['errors'][] = $this->t('Media Actions (for example, for bulk operations) have been moved into a separate "Media Entity Actions" module. You need to download this module to your codebase before continuing.');
106     }
107     else {
108       $checks['passes'][] = $this->t('The "Media Entity Actions" module is available.');
109     }
110
111     // EXIF image handling was dropped from the patch that moved ME + MEI into
112     // core. If a site was using it, we need to ensure the contrib module
113     // media_entity_image_exif is present, to fill in that gap.
114     if (!empty(_media_entity_get_bundles_using_exif()) && !isset($module_data['media_entity_image_exif'])) {
115       $checks['errors'][] = $this->t('Your site uses EXIF mapping on image types, and these were not initially incorporated in Media in core. In order not to lose that functionality, you need to download the module "Media Entity Image EXIF" into your codebase before continuing.');
116     }
117     else {
118       $checks['passes'][] = $this->t('Site uses EXIF handling and the "Media Entity Image EXIF" module is available.');
119     }
120
121     return $checks;
122   }
123
124 }