lightning_scheduler.install in Lightning Workflow 8.2
File
modules/lightning_scheduler/lightning_scheduler.install
View source
<?php
use Drupal\Core\Url;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
function lightning_scheduler_update_8001() {
Drupal::moduleHandler()
->resetImplementations();
$definition_manager = Drupal::entityDefinitionUpdateManager();
$installed = Drupal::service('entity.last_installed_schema.repository');
$migrations = [];
foreach (Drupal::entityTypeManager()
->getDefinitions() as $entity_type) {
$base_fields = lightning_scheduler_entity_base_field_info($entity_type);
if (empty($base_fields)) {
continue;
}
foreach ($base_fields as $field_name => $field_definition) {
$definition_manager
->installFieldStorageDefinition($field_name, $entity_type
->id(), 'lightning_scheduler', $field_definition);
}
$installed_fields = $installed
->getLastInstalledFieldStorageDefinitions($entity_type
->id());
if (isset($installed_fields['scheduled_publication'], $installed_fields['scheduled_moderation_state'])) {
array_push($migrations, $entity_type
->id());
}
}
Drupal::service('lightning_scheduler.migrator')
->setMigrations($migrations);
$url = Url::fromRoute('lightning_scheduler.migrate');
try {
$url
->getInternalPath();
} catch (RouteNotFoundException $e) {
Drupal::service('router.builder')
->rebuild();
}
$variables = [
':url' => $url
->getInternalPath(),
];
if (PHP_SAPI === 'cli') {
$link = t('You may want to visit /:url to migrate your existing content now', $variables);
}
else {
$variables += [
':base_url' => Drupal::service('router.request_context')
->getCompleteBaseUrl(),
];
$link = t('You may want to <a href=":base_url/:url">migrate your existing content</a> now', $variables);
}
return t('Lightning Scheduler\'s new fields have been created. @link. Note that you must be logged in as the superuser (user 1) to do this.', [
'@link' => $link,
]);
}
function lightning_scheduler_update_8002() {
Drupal::service('plugin.manager.field.widget')
->clearCachedDefinitions();
}
function lightning_scheduler_update_dependencies() {
return [
'block_content' => [
8400 => [
'lightning_scheduler' => 8001,
],
],
'lightning_scheduler' => [
8001 => [
'system' => 8501,
],
],
];
}
function lightning_scheduler_requirements($phase) {
$requirements = [];
if ($phase === 'runtime') {
$migrations = Drupal::service('lightning_scheduler.migrator')
->getMigrations();
if ($migrations) {
$requirements['lightning_scheduler_migrations'] = [
'severity' => REQUIREMENT_INFO,
'title' => t('Lightning Scheduler data migration'),
'description' => t('Some content has not yet been migrated into the new base fields installed by Lightning Scheduler. Visit <a href=":url">this page</a> to migrate the data.', [
':url' => Url::fromRoute('lightning_scheduler.migrate')
->toString(),
]),
];
}
}
return $requirements;
}