View source
<?php
namespace Drupal\media_entity;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class CliService {
use StringTranslationTrait;
protected $moduleHandler;
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
public function validateDbUpdateRequirements() {
$checks = [
'errors' => [],
'passes' => [],
];
module_load_install('media_entity');
$version = explode('.', \Drupal::VERSION);
if ($version[1] < 6) {
$checks['errors'][] = $this
->t('The Media Entity 2.x upgrade path only works with Drupal core >= 8.6.x');
}
else {
$checks['passes'][] = $this
->t('Drupal core is the correct version (>= 8.6.0). [@version detected]', [
'@version' => \Drupal::VERSION,
]);
}
if ($this->moduleHandler
->moduleExists('media')) {
$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.');
}
else {
$checks['passes'][] = $this
->t('The contributed "Media" module is not installed.');
}
$incompatible_modules = _media_entity_get_incompatible_modules();
if (!empty($incompatible_modules)) {
$provider_modules = !empty($incompatible_modules['providers']) ? implode(", ", $incompatible_modules['providers']) : '';
$additional_msg_providers = !empty($provider_modules) ? ' ' . $this
->t('The following modules provide source plugins and need to be upgraded: @provider_modules.', [
'@provider_modules' => $provider_modules,
]) : '';
$dependent_modules = !empty($incompatible_modules['modules']) ? implode(", ", $incompatible_modules['modules']) : '';
$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.', [
'@dependent_modules' => $dependent_modules,
]) : '';
$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;
}
else {
$checks['passes'][] = $this
->t('All provider plugins and modules depending on media_entity are up-to-date.');
}
$module_data = system_rebuild_module_data();
$generic_types = _media_entity_get_bundles_by_plugin('generic');
if ($generic_types) {
if (!isset($module_data['media_entity_generic'])) {
$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.');
}
else {
$checks['passes'][] = $this
->t('The "Media Entity Generic" module is available.');
}
}
if (!empty(_media_entity_get_bundles_using_exif()) && !isset($module_data['media_entity_image_exif'])) {
$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.');
}
else {
$checks['passes'][] = $this
->t('Site uses EXIF handling and the "Media Entity Image EXIF" module is available.');
}
return $checks;
}
}