130 lines
4.9 KiB
Plaintext
130 lines
4.9 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Installation file for Scheduler module.
|
|
*/
|
|
|
|
use Drupal\Core\Url;
|
|
use Drupal\views\Entity\View;
|
|
|
|
/**
|
|
* Implements hook_requirements().
|
|
*/
|
|
function scheduler_requirements($phase) {
|
|
$requirements = [];
|
|
|
|
// Report server internal clock.
|
|
if ($phase === 'runtime') {
|
|
$user = \Drupal::currentUser();
|
|
|
|
$now = \Drupal::time()->getRequestTime();
|
|
$system_date = \Drupal::config('system.date');
|
|
$date_default_timezone = $system_date->get('timezone.default') ?: date_default_timezone_get();
|
|
$date_formatter = \Drupal::service('date.formatter');
|
|
|
|
$t_options = [
|
|
// For %utc specify 'GMT' as the timezone (4th parameter) so that no
|
|
// timezone offset is returned.
|
|
'%utc' => $date_formatter->format($now, 'custom', 'jS F Y, H:i:s P', 'GMT'),
|
|
// For %localtime do not specify any timezone parameter so that the user
|
|
// or site default setting is returned.
|
|
'%localtime' => $date_formatter->format($now, 'custom', 'jS F Y, H:i:s P T e'),
|
|
'%daylight_saving' => $date_formatter->format($now, 'custom', 'I') ? t('currently in daylight saving mode') : t('not in daylight saving mode'),
|
|
'%date_default_timezone' => $date_default_timezone,
|
|
'%date_default_offset' => $date_formatter->format($now, 'custom', 'P', $date_default_timezone),
|
|
'%date_default_code' => $date_formatter->format($now, 'custom', 'T', $date_default_timezone),
|
|
'@account_edit' => Url::fromRoute('entity.user.edit_form', ['user' => $user->id()])->toString(),
|
|
'@admin_regional_settings' => Url::fromRoute('system.regional_settings')->toString(),
|
|
];
|
|
|
|
$descriptions = [
|
|
t('In most cases the server time should match Coordinated Universal Time (UTC) / Greenwich Mean Time (GMT).', $t_options),
|
|
t('Default timezone: %date_default_timezone (%date_default_code), offset from UTC/GMT by %date_default_offset hours. This timezone can be <a href="@admin_regional_settings">changed by admin users</a> with the appropriate access.', $t_options),
|
|
];
|
|
if ($system_date->get('timezone.user.configurable')) {
|
|
$descriptions[] = t('Local time: %localtime (%daylight_saving). You can change this via your <a href="@account_edit">user account</a>.', $t_options);
|
|
if (!$user->getTimezone()) {
|
|
$descriptions[] = t('Note: The user timezone has not been stored, so defaulting to the website timezone.');
|
|
}
|
|
}
|
|
else {
|
|
$descriptions[] = t('Your local time is %localtime (%daylight_saving). This is not configurable by you.', $t_options);
|
|
}
|
|
|
|
$requirements['scheduler_timecheck'] = [
|
|
'title' => t('Scheduler Time Check'),
|
|
'value' => t('Server time: @utc', [
|
|
'@utc' => $date_formatter->format($now, 'custom', 'jS F Y, H:i:s P', 'GMT'),
|
|
]),
|
|
'description' => [
|
|
'#type' => 'inline_template',
|
|
'#template' => '{{ description|raw }}',
|
|
'#context' => ['description' => implode('<br />', $descriptions)],
|
|
],
|
|
];
|
|
}
|
|
|
|
return $requirements;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_install().
|
|
*/
|
|
function scheduler_install() {
|
|
// Set cron access key value, as this is now required in SchedulerCronForm.
|
|
$config = \Drupal::service('config.factory')->getEditable('scheduler.settings');
|
|
$config->set('lightweight_cron_access_key', substr(md5(rand()), 0, 20))
|
|
->save();
|
|
}
|
|
|
|
/**
|
|
* Implements hook_uninstall().
|
|
*/
|
|
function scheduler_uninstall() {
|
|
// Delete the scheduled content view.
|
|
\Drupal::configFactory()->getEditable('views.view.scheduler_scheduled_content')->delete();
|
|
}
|
|
|
|
/**
|
|
* Reset date and time formats to default.
|
|
*/
|
|
function scheduler_update_8001() {
|
|
// See https://www.drupal.org/project/scheduler/issues/2799869
|
|
$config = \Drupal::configFactory()->getEditable('scheduler.settings');
|
|
$config
|
|
->set('date_format', 'Y-m-d H:i:s')
|
|
->set('date_only_format', 'Y-m-d')
|
|
->set('time_only_format', 'H:i:s')
|
|
->save();
|
|
return t('The date and time format has been reset.');
|
|
}
|
|
|
|
/**
|
|
* Set default value for new config option.
|
|
*/
|
|
function scheduler_update_8101() {
|
|
// See https://www.drupal.org/project/scheduler/issues/3145169
|
|
$config = \Drupal::configFactory()->getEditable('scheduler.settings');
|
|
$config
|
|
->set('default_show_message_after_update', TRUE)
|
|
->save();
|
|
return t('Default set on for new option "Show a message after updating content"');
|
|
}
|
|
|
|
/**
|
|
* Update view - Move 'Scheduled' tab to be a local task under 'Content'.
|
|
*/
|
|
function scheduler_update_8102() {
|
|
// The text in the doc block above is shown on the update.php list.
|
|
// See https://www.drupal.org/project/scheduler/issues/3167193
|
|
$view = View::load('scheduler_scheduled_content');
|
|
if ($view) {
|
|
$display =& $view->getDisplay('overview');
|
|
$display['display_options']['menu']['description'] = 'Content scheduled for publishing and unpublishing';
|
|
$display['display_options']['menu']['type'] = 'normal';
|
|
$view->save();
|
|
return t('The "Scheduled" tab is now a "Scheduled content" sub-task under the "Content" tab');
|
|
}
|
|
}
|