diff --git a/composer.lock b/composer.lock index e844832c232e51015af9adf7769c4d56ba7a0f73..d09064df1778726019ab0d2376257a64029b7b00 100644 --- a/composer.lock +++ b/composer.lock @@ -7489,26 +7489,26 @@ }, { "name": "drupal/ultimate_cron", - "version": "2.0.0-alpha5", + "version": "2.0.0-alpha6", "source": { "type": "git", "url": "https://git.drupalcode.org/project/ultimate_cron.git", - "reference": "8.x-2.0-alpha5" + "reference": "8.x-2.0-alpha6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/ultimate_cron-8.x-2.0-alpha5.zip", - "reference": "8.x-2.0-alpha5", - "shasum": "0f10464fff29eca89024e7afa5b6d8d07bd52f75" + "url": "https://ftp.drupal.org/files/projects/ultimate_cron-8.x-2.0-alpha6.zip", + "reference": "8.x-2.0-alpha6", + "shasum": "42ab6df8e94a9b3772876a378062534552a32826" }, "require": { - "drupal/core": "^8.7.7 || ^9" + "drupal/core": "^9 || ^10" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-2.0-alpha5", - "datestamp": "1600928948", + "version": "8.x-2.0-alpha6", + "datestamp": "1666471448", "security-coverage": { "status": "not-covered", "message": "Alpha releases are not covered by Drupal security advisories." @@ -7516,7 +7516,7 @@ }, "drush": { "services": { - "drush.services.yml": "^9 || ^10" + "drush.services.yml": "^9 || ^10 || ^11" } } }, diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 13899373c38b6de0ce35e536cc9d62d1cb124537..8b1b270136c1ebec852c0480c7d18c3d3ba149fe 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -7782,27 +7782,27 @@ }, { "name": "drupal/ultimate_cron", - "version": "2.0.0-alpha5", - "version_normalized": "2.0.0.0-alpha5", + "version": "2.0.0-alpha6", + "version_normalized": "2.0.0.0-alpha6", "source": { "type": "git", "url": "https://git.drupalcode.org/project/ultimate_cron.git", - "reference": "8.x-2.0-alpha5" + "reference": "8.x-2.0-alpha6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/ultimate_cron-8.x-2.0-alpha5.zip", - "reference": "8.x-2.0-alpha5", - "shasum": "0f10464fff29eca89024e7afa5b6d8d07bd52f75" + "url": "https://ftp.drupal.org/files/projects/ultimate_cron-8.x-2.0-alpha6.zip", + "reference": "8.x-2.0-alpha6", + "shasum": "42ab6df8e94a9b3772876a378062534552a32826" }, "require": { - "drupal/core": "^8.7.7 || ^9" + "drupal/core": "^9 || ^10" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-2.0-alpha5", - "datestamp": "1600928948", + "version": "8.x-2.0-alpha6", + "datestamp": "1666471448", "security-coverage": { "status": "not-covered", "message": "Alpha releases are not covered by Drupal security advisories." @@ -7810,7 +7810,7 @@ }, "drush": { "services": { - "drush.services.yml": "^9 || ^10" + "drush.services.yml": "^9 || ^10 || ^11" } } }, @@ -7820,6 +7820,10 @@ "GPL-2.0+" ], "authors": [ + { + "name": "arnested", + "homepage": "https://www.drupal.org/user/245635" + }, { "name": "Berdir", "homepage": "https://www.drupal.org/user/214652" @@ -7828,14 +7832,6 @@ "name": "Dane Powell", "homepage": "https://www.drupal.org/user/339326" }, - { - "name": "Primsi", - "homepage": "https://www.drupal.org/user/282629" - }, - { - "name": "arnested", - "homepage": "https://www.drupal.org/user/245635" - }, { "name": "gielfeldt", "homepage": "https://www.drupal.org/user/366993" @@ -7843,6 +7839,10 @@ { "name": "miro_dietiker", "homepage": "https://www.drupal.org/user/227761" + }, + { + "name": "Primsi", + "homepage": "https://www.drupal.org/user/282629" } ], "description": "Ultimate cron", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 5758fa5e83717db58c0a7d17add84151d3dd8dd7..36776195a7a71eea966b1cb33e7601f63797fa03 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1262,9 +1262,9 @@ 'dev_requirement' => false, ), 'drupal/ultimate_cron' => array( - 'pretty_version' => '2.0.0-alpha5', - 'version' => '2.0.0.0-alpha5', - 'reference' => '8.x-2.0-alpha5', + 'pretty_version' => '2.0.0-alpha6', + 'version' => '2.0.0.0-alpha6', + 'reference' => '8.x-2.0-alpha6', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/ultimate_cron', 'aliases' => array(), diff --git a/web/modules/ultimate_cron/composer.json b/web/modules/ultimate_cron/composer.json index 7fc89ffd922116154e4e22e94b56b568f4e173b7..4e4804a9479f05aec322fd2daf930e99750d94ef 100644 --- a/web/modules/ultimate_cron/composer.json +++ b/web/modules/ultimate_cron/composer.json @@ -4,12 +4,12 @@ "license": "GPL-2.0+", "description": "Ultimate cron", "require": { - "drupal/core": "^8.7.7 || ^9" + "drupal/core": "^9 || ^10" }, "extra": { "drush": { "services": { - "drush.services.yml": "^9 || ^10" + "drush.services.yml": "^9 || ^10 || ^11" } } } diff --git a/web/modules/ultimate_cron/src/Commands/UltimateCronCommands.php b/web/modules/ultimate_cron/src/Commands/UltimateCronCommands.php index 243c5c21e4f0dd535f38ee11d507625f6dc2d90d..c7b17d85e026ac13d4dca28239084ac21a61f446 100644 --- a/web/modules/ultimate_cron/src/Commands/UltimateCronCommands.php +++ b/web/modules/ultimate_cron/src/Commands/UltimateCronCommands.php @@ -15,13 +15,6 @@ */ class UltimateCronCommands extends DrushCommands { - /** - * Logger object. - * - * @var \Drupal\Core\Logger\LoggerChannelInterface - */ - protected $logger; - /** * Constructs an UltimateCronCommands object. * diff --git a/web/modules/ultimate_cron/src/CronJobDiscovery.php b/web/modules/ultimate_cron/src/CronJobDiscovery.php index 0f8a0d6a312acbdf4f3b0a27d270338bdfe2cf7c..22e6fc7c5ee1b65322896190cb52c862dcf0343a 100644 --- a/web/modules/ultimate_cron/src/CronJobDiscovery.php +++ b/web/modules/ultimate_cron/src/CronJobDiscovery.php @@ -180,7 +180,13 @@ protected function getModuleHooks($module) { $items = array(); // Add hook_cron() if applicable. - if ($this->moduleHandler->implementsHook($module, 'cron')) { + if (method_exists($this->moduleHandler, 'hasImplementations')) { + $has_implementations = $this->moduleHandler->hasImplementations('cron', $module); + } + else { + $has_implementations = $this->moduleHandler->implementsHook($module, 'cron'); + } + if ($has_implementations) { $info = $this->moduleExtensionList->getExtensionInfo($module); $callback = "{$module}_cron"; $items[$callback] = array( diff --git a/web/modules/ultimate_cron/src/CronJobListBuilder.php b/web/modules/ultimate_cron/src/CronJobListBuilder.php index e6e9c72854423fd03b93dc07607e4397a21f285f..95e040f8fd3e63114ba6278629a86809d2bed2e7 100644 --- a/web/modules/ultimate_cron/src/CronJobListBuilder.php +++ b/web/modules/ultimate_cron/src/CronJobListBuilder.php @@ -37,8 +37,8 @@ public function buildHeader() { */ public function buildRow(EntityInterface $entity) { /* @var \Drupal\ultimate_cron\CronJobInterface $entity */ - $icon = drupal_get_path('module', 'ultimate_cron') . '/icons/hourglass.png'; - $behind_icon = ['#prefix' => ' ', '#theme' => 'image', '#uri' => file_create_url($icon), '#title' => t('Job is behind schedule!')]; + $icon = \Drupal::service('extension.list.module')->getPath('ultimate_cron') . '/icons/hourglass.png'; + $behind_icon = ['#prefix' => ' ', '#theme' => 'image', '#uri' => \Drupal::service('file_url_generator')->generateAbsoluteString($icon), '#title' => t('Job is behind schedule!')]; $log_entry = $entity->loadLatestLogEntry(); $row['label'] = $entity->label(); @@ -49,7 +49,7 @@ public function buildRow(EntityInterface $entity) { $row['scheduled']['behind'] = $behind_icon; } // If the start time is 0, the jobs have never been run. - $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')->format($log_entry->start_time, "short") : $this->t('Never'); + $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')->format((int) $log_entry->start_time, "short") : $this->t('Never'); // Display duration $progress = $entity->isLocked() ? $entity->formatProgress() : ''; diff --git a/web/modules/ultimate_cron/src/CronPluginMultiple.php b/web/modules/ultimate_cron/src/CronPluginMultiple.php index ca8f9d5955c0a162e1b51231d388508fb6f4c057..c94a8f89c2838f595d4647d9c601fa88fb37ef6a 100644 --- a/web/modules/ultimate_cron/src/CronPluginMultiple.php +++ b/web/modules/ultimate_cron/src/CronPluginMultiple.php @@ -2,7 +2,7 @@ namespace Drupal\ultimate_cron; -class CronPluginMultiple extends \Drupal\ultimate_cron\CronPlugin { +class CronPluginMultiple extends CronPlugin { static public $multiple = TRUE; /** diff --git a/web/modules/ultimate_cron/src/Entity/CronJob.php b/web/modules/ultimate_cron/src/Entity/CronJob.php index 837e8775d3d872f20a66d210ed0acb0805c083d6..735f1167e0bc041f797f3a1803b0bb032cc7fabb 100644 --- a/web/modules/ultimate_cron/src/Entity/CronJob.php +++ b/web/modules/ultimate_cron/src/Entity/CronJob.php @@ -477,13 +477,17 @@ public function run($init_message = NULL) { // explicitly here instead. The advantage is that this will not // interrupt the process. $variables = Error::decodeException($e); - unset($variables['backtrace']); + $variables = array_filter($variables, function ($key) { + return $key[0] == '@' || $key[0] == '%'; + }, ARRAY_FILTER_USE_KEY); $log_entry->log('%type: @message in %function (line %line of %file).', $variables, RfcLogLevel::ERROR); return FALSE; } catch (\Exception $e) { $variables = Error::decodeException($e); - unset($variables['backtrace']); + $variables = array_filter($variables, function ($key) { + return $key[0] == '@' || $key[0] == '%'; + }, ARRAY_FILTER_USE_KEY); $log_entry->log('%type: @message in %function (line %line of %file).', $variables, RfcLogLevel::ERROR); return FALSE; } diff --git a/web/modules/ultimate_cron/src/Form/SchedulerSettingsForm.php b/web/modules/ultimate_cron/src/Form/SchedulerSettingsForm.php index c9bdc716b7c4cfb5f73dfc49b75304ff4d993791..e4e5053aadae650cab9b8bdc518330e4c1af8213 100644 --- a/web/modules/ultimate_cron/src/Form/SchedulerSettingsForm.php +++ b/web/modules/ultimate_cron/src/Form/SchedulerSettingsForm.php @@ -69,7 +69,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#collapsed' => TRUE, ); $form['crontab']['rules_help']['info'] = array( - '#markup' => file_get_contents(drupal_get_path('module', 'ultimate_cron') . '/help/rules.html'), + '#markup' => file_get_contents(\Drupal::service('extension.list.module')->getPath('ultimate_cron') . '/help/rules.html'), ); // Settings for Simple scheduler. diff --git a/web/modules/ultimate_cron/src/Launcher/LauncherBase.php b/web/modules/ultimate_cron/src/Launcher/LauncherBase.php index f83f695f060a50fe1a9ed37128edc791157550b3..743570ed9e99dbbafa8e3a76d4cf18a2c2a23e48 100644 --- a/web/modules/ultimate_cron/src/Launcher/LauncherBase.php +++ b/web/modules/ultimate_cron/src/Launcher/LauncherBase.php @@ -67,7 +67,7 @@ public function launchJobs(array $jobs) { * {@inheritdoc} */ public function formatRunning(CronJobInterface $job) { - $file = drupal_get_path('module', 'ultimate_cron') . '/icons/hourglass.png'; + $file = \Drupal::service('extension.list.module')->getPath('ultimate_cron') . '/icons/hourglass.png'; $status = ['#theme' => 'image', '#uri' => $file]; $title = t('running'); return array($status, $title); @@ -77,7 +77,7 @@ public function formatRunning(CronJobInterface $job) { * {@inheritdoc} */ public function formatUnfinished(CronJobInterface $job) { - $file = drupal_get_path('module', 'ultimate_cron') . '/icons/lock_open.png'; + $file = \Drupal::service('extension.list.module')->getPath('ultimate_cron') . '/icons/lock_open.png'; $status = ['#theme' => 'image', '#uri' => $file]; $title = t('unfinished but not locked?'); return array($status, $title); diff --git a/web/modules/ultimate_cron/src/Logger/WatchdogLogger.php b/web/modules/ultimate_cron/src/Logger/WatchdogLogger.php index 56d69ec37eedcd49878ae776c1436562f06bd513..381c551dcb82707df72673012c34b870ee6a8b87 100644 --- a/web/modules/ultimate_cron/src/Logger/WatchdogLogger.php +++ b/web/modules/ultimate_cron/src/Logger/WatchdogLogger.php @@ -49,7 +49,7 @@ public function __construct(LogMessageParserInterface $parser) { /** * {@inheritdoc} */ - public function log($level, $message, array $context = array()) { + public function log($level, $message, array $context = array()): void { if ($this->logEntries) { diff --git a/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Logger/CacheLogger.php b/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Logger/CacheLogger.php index a97070c223682337927b8c907c1f6cb41f734c69..4a7b304cca6df87688f4d80e2fe0c4d90a70acba 100644 --- a/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Logger/CacheLogger.php +++ b/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Logger/CacheLogger.php @@ -116,7 +116,7 @@ public function save(LogEntry $log_entry) { $settings = $this->getConfiguration(); - $expire = $settings['timeout'] != Cache::PERMANENT ? REQUEST_TIME + $settings['timeout'] : $settings['timeout']; + $expire = $settings['timeout'] != Cache::PERMANENT ? \Drupal::time()->getRequestTime() + $settings['timeout'] : $settings['timeout']; $this->cache->set('uc-name:' . $log_entry->name, $log_entry->lid, $expire); $this->cache->set('uc-lid:' . $log_entry->lid, $log_entry->getData(), $expire); diff --git a/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Scheduler/Crontab.php b/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Scheduler/Crontab.php index 1795ad55a873ffaf26be5e55dad58c55724c70c1..7592b1b45a9750b41279e44d9650bbe17b5f3280 100644 --- a/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Scheduler/Crontab.php +++ b/web/modules/ultimate_cron/src/Plugin/ultimate_cron/Scheduler/Crontab.php @@ -41,7 +41,7 @@ public function formatLabel(CronJob $job) { public function formatLabelVerbose(CronJob $job) { $parsed = ''; $next_schedule = NULL; - $time = REQUEST_TIME; + $time = \Drupal::time()->getRequestTime(); $skew = $this->getSkew($job); foreach ($this->configuration['rules'] as $rule) { $cron = CronRule::factory($rule, $time, $skew); @@ -83,7 +83,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ); $form['rules_help']['info'] = array( - '#markup' => file_get_contents(drupal_get_path('module', 'ultimate_cron') . '/help/rules.html'), + '#markup' => file_get_contents(\Drupal::service('extension.list.module')->getPath('ultimate_cron') . '/help/rules.html'), ); $form['catch_up'] = array( @@ -179,7 +179,7 @@ public function isBehind(CronJob $job) { $time = $cron->getNextSchedule(); $next_schedule = is_null($next_schedule) || $time < $next_schedule ? $time : $next_schedule; } - $behind = REQUEST_TIME - $next_schedule; + $behind = \Drupal::time()->getRequestTime() - $next_schedule; return $behind > $this->configuration['catch_up'] ? $behind : FALSE; } diff --git a/web/modules/ultimate_cron/src/QueueWorker.php b/web/modules/ultimate_cron/src/QueueWorker.php index d5a819e53097b9e221a27ca9a0085225a3a1e490..a89957bfe464566ca51bdd067b10a2ef3862d460 100644 --- a/web/modules/ultimate_cron/src/QueueWorker.php +++ b/web/modules/ultimate_cron/src/QueueWorker.php @@ -7,6 +7,8 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Queue\RequeueException; use Drupal\Core\Queue\SuspendQueueException; +use Drupal\Core\Queue\DelayableQueueInterface; +use Drupal\Core\Queue\DelayedRequeueException; /** * Defines the queue worker. @@ -114,6 +116,13 @@ public function queueCallback(CronJobInterface $job) { // The worker requested the task be immediately requeued. $queue->releaseItem($item); } + catch (DelayedRequeueException $e) { + if ($queue instanceof DelayableQueueInterface) { + // This queue can handle a custom delay; use the duration provided + // by the exception. + $queue->delayItem($item, $e->getDelay()); + } + } catch (SuspendQueueException $e) { // If the worker indicates there is a problem with the whole queue, // release the item and skip to the next queue. @@ -121,6 +130,10 @@ public function queueCallback(CronJobInterface $job) { watchdog_exception('cron', $e); + // Rethrow the SuspendQueueException, so that the queue is correctly + // suspended for the current cron run to avoid infinite loops. + throw $e; + } catch (\Exception $e) { // In case of any other kind of exception, log it and leave the item diff --git a/web/modules/ultimate_cron/src/TaggedSettings.php b/web/modules/ultimate_cron/src/TaggedSettings.php index 4cae649a736a126d553fee5c81092cdd7a23c11d..db9028357506424f59f6351032eb19de3c2bdf49 100644 --- a/web/modules/ultimate_cron/src/TaggedSettings.php +++ b/web/modules/ultimate_cron/src/TaggedSettings.php @@ -15,6 +15,6 @@ class TaggedSettings extends Settings { * Only valid for jobs tagged with the proper tag. */ public function isValid($job = NULL) { - return $job ? in_array($this->name, $job->hook['tags']) : \Drupal\ultimate_cron\parent::isValid(); + return $job ? in_array($this->name, $job->hook['tags']) : parent::isValid(); } } diff --git a/web/modules/ultimate_cron/tests/src/Functional/CronJobFormTest.php b/web/modules/ultimate_cron/tests/src/Functional/CronJobFormTest.php index 5c0d13109ea30abd886f71e6fbedcd9e127f38a6..1af58f91012a2bbf6229bbdc5dea347f3ab44519 100644 --- a/web/modules/ultimate_cron/tests/src/Functional/CronJobFormTest.php +++ b/web/modules/ultimate_cron/tests/src/Functional/CronJobFormTest.php @@ -61,16 +61,16 @@ public function testManageJob() { // Cron Jobs overview. $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertResponse('200'); + $this->assertSession()->statusCodeEquals('200'); // Check for the default schedule message in Job list. - $this->assertText('Every 15 min'); + $this->assertSession()->pageTextContains('Every 15 min'); // Check for the Last Run default value. - $this->assertText('Never'); + $this->assertSession()->pageTextContains('Never'); // Start editing added job. $this->drupalGet('admin/config/system/cron/jobs/manage/' . $this->jobId); - $this->assertResponse('200'); + $this->assertSession()->statusCodeEquals('200'); // Set new cron job configuration and save the old job name. $job = CronJob::load($this->jobId); @@ -79,72 +79,74 @@ public function testManageJob() { $edit = array('title' => $this->jobName); // Save the new job. - $this->drupalPostForm(NULL, $edit, t('Save')); + $this->submitForm($edit, t('Save')); // Assert the edited Job hasn't run yet. - $this->assertText('Never'); + $this->assertSession()->pageTextContains('Never'); // Assert messenger service message for successful updated job. - $this->assertText(t('job @name has been updated.', array('@name' => $this->jobName))); + $this->assertSession()->pageTextContains(t('job @name has been updated.', array('@name' => $this->jobName))); // Run the Jobs. $this->cronRun(); // Assert the cron jobs have been run by checking the time. $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertText(\Drupal::service('date.formatter')->format(\Drupal::state()->get('system.cron_last'), 'short'), 'Created Cron jobs have been run.'); + $this->assertSession()->pageTextContains(\Drupal::service('date.formatter')->format(\Drupal::state()->get('system.cron_last'), 'short')); // Check that all jobs have been run. - $this->assertNoText("Never"); + $this->assertSession()->pageTextNotContains("Never"); // Assert cron job overview for recently updated job. $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertNoText($old_job_name); - $this->assertText($this->jobName); + $this->assertSession()->pageTextNotContains($old_job_name); + $this->assertSession()->pageTextContains($this->jobName); // Change time when cron runs, check the 'Scheduled' label is updated. $this->clickLink(t('Edit')); - $this->drupalPostForm(NULL, ['scheduler[configuration][rules][0]' => '0+@ */6 * * *'], t('Save')); - $this->assertText('Every 6 hours'); + $this->submitForm(['scheduler[configuration][rules][0]' => '0+@ */6 * * *'], t('Save')); + $this->assertSession()->pageTextContains('Every 6 hours'); // Test disabling a job. $this->clickLink(t('Disable'), 0); - $this->assertText('This cron job will no longer be executed.'); - $this->drupalPostForm(NULL, NULL, t('Disable')); + $this->assertSession()->pageTextContains('This cron job will no longer be executed.'); + $this->submitForm([], t('Disable')); // Assert messenger service message for successful disabled job. - $this->assertText(t('Disabled cron job @name.', array('@name' => $this->jobName))); + $this->assertSession()->pageTextContains(t('Disabled cron job @name.', array('@name' => $this->jobName))); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[6]', 'Disabled'); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Enable'); - $this->assertNoFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); + $this->assertSession()->elementExists('xpath', '//table/tbody/tr[1]/td[6]'); + $this->assertSession()->elementContains('xpath','//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Enable'); + $this->assertSession()->elementNotContains('xpath', '//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); // Test enabling a job. $this->clickLink(t('Enable'), 0); - $this->assertText('This cron job will be executed again.'); - $this->drupalPostForm(NULL, NULL, t('Enable')); + $this->assertSession()->pageTextContains('This cron job will be executed again.'); + $this->submitForm([], t('Enable')); // Assert messenger service message for successful enabled job. - $this->assertText(t('Enabled cron job @name.', array('@name' => $this->jobName))); + $this->assertSession()->pageTextContains(t('Enabled cron job @name.', array('@name' => $this->jobName))); $this->drupalGet('admin/config/system/cron/jobs'); - $expected_checkmark_image_url = file_url_transform_relative(file_create_url('core/misc/icons/73b355/check.svg')); + $expected_checkmark_image_url = \Drupal::service('file_url_generator')->generateString('core/misc/icons/73b355/check.svg'); $this->assertEquals($expected_checkmark_image_url, $this->xpath('//table/tbody/tr[1]/td[6]/img')[0]->getAttribute('src')); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); + $this->assertSession()->elementExists('xpath','//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a'); // Test disabling a job with the checkbox on the edit page. $edit = array( 'status' => FALSE, ); - $this->drupalPostForm('admin/config/system/cron/jobs/manage/' . $this->jobId, $edit, t('Save')); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[6]', 'Disabled'); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Enable'); - $this->assertNoFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); + $this->drupalGet('admin/config/system/cron/jobs/manage/' . $this->jobId); + $this->submitForm($edit, t('Save')); + $this->assertSession()->elementExists('xpath','//table/tbody/tr[1]/td[6]'); + $this->assertSession()->elementContains('xpath','//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Enable'); + $this->assertSession()->elementNotContains('xpath', '//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); // Test enabling a job with the checkbox on the edit page. $edit = array( 'status' => TRUE, ); - $this->drupalPostForm('admin/config/system/cron/jobs/manage/' . $this->jobId, $edit, t('Save')); + $this->drupalGet('admin/config/system/cron/jobs/manage/' . $this->jobId); + $this->submitForm($edit, t('Save')); $this->assertEquals($expected_checkmark_image_url, $this->xpath('//table/tbody/tr[1]/td[6]/img')[0]->getAttribute('src')); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a', 'Run'); + $this->assertSession()->elementExists('xpath','//table/tbody/tr[1]/td[8]/div/div/ul/li[1]/a'); $this->drupalGet('admin/config/system/cron/jobs'); @@ -153,18 +155,19 @@ public function testManageJob() { $job_configuration = array( 'scheduler[id]' => 'crontab', ); - $this->drupalPostForm(NULL, $job_configuration, t('Save')); - $this->drupalPostForm('admin/config/system/cron/jobs/manage/' . $this->jobId, ['scheduler[configuration][rules][0]' => '0+@ * * * *'], t('Save')); - $this->assertText('0+@ * * * *'); + $this->submitForm($job_configuration, t('Save')); + $this->drupalGet('admin/config/system/cron/jobs/manage/' . $this->jobId); + $this->submitForm(['scheduler[configuration][rules][0]' => '0+@ * * * *'], t('Save')); + $this->assertSession()->pageTextContains('0+@ * * * *'); // Try editing the rule to an invalid one. $this->clickLink('Edit'); - $this->drupalPostForm(NULL, ['scheduler[configuration][rules][0]' => '*//15+@ *-2 * * *'], t('Save')); - $this->assertText('Rule is invalid'); - $this->assertTitle('Edit job | Drupal'); + $this->submitForm(['scheduler[configuration][rules][0]' => '*//15+@ *-2 * * *'], t('Save')); + $this->assertSession()->pageTextContains('Rule is invalid'); + $this->assertSession()->titleEquals('Edit job | Drupal'); // Assert that there is no Delete link on the details page. - $this->assertNoLink('Delete'); + $this->assertSession()->linkNotExists('Delete'); // Force a job to be invalid by changing the callback. $job = CronJob::load($this->jobId); @@ -173,15 +176,15 @@ public function testManageJob() { $this->drupalGet('admin/config/system/cron/jobs'); // Assert that the invalid cron job is displayed properly. - $this->assertFieldByXPath('//table/tbody/tr[1]/td[6]', 'Missing'); - $this->assertFieldByXPath('//table/tbody/tr[1]/td[8]/div/div/ul/li/a', 'Delete'); + $this->assertSession()->elementExists('xpath','//table/tbody/tr[1]/td[6]'); + $this->assertSession()->elementExists('xpath','//table/tbody/tr[1]/td[8]/div/div/ul/li/a'); // Test deleting a job (only possible if invalid cron job). $this->clickLink(t('Delete'), 0); - $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertText(t('The cron job @name has been deleted.', array('@name' => $job->label()))); + $this->submitForm([], t('Delete')); + $this->assertSession()->pageTextContains(t('The cron job @name has been deleted.', array('@name' => $job->label()))); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertNoText($job->label()); + $this->assertSession()->pageTextNotContains($job->label()); $job = CronJob::load('ultimate_cron_cron'); @@ -192,13 +195,13 @@ public function testManageJob() { $this->drupalGet('admin/config/system/cron/jobs'); $this->clickLink('Logs'); $xpath = $this->xpath('//tbody/tr[@class="odd"]/td'); - $start_time = \Drupal::service('date.formatter')->format($log_entry->start_time, 'custom', 'Y-m-d H:i:s'); - $end_time = \Drupal::service('date.formatter')->format($log_entry->end_time, 'custom', 'Y-m-d H:i:s'); - $this->assertEqual($xpath[1]->getText(), $start_time); - $this->assertEqual($xpath[2]->getText(), $end_time); + $start_time = \Drupal::service('date.formatter')->format((int) $log_entry->start_time, 'custom', 'Y-m-d H:i:s'); + $end_time = \Drupal::service('date.formatter')->format((int) $log_entry->end_time, 'custom', 'Y-m-d H:i:s'); + $this->assertEquals($xpath[1]->getText(), $start_time); + $this->assertEquals($xpath[2]->getText(), $end_time); // The message logged depends on timing, do not hardcode that. - $this->assertEqual($xpath[3]->getText(), $log_entry->message ?: $log_entry->formatInitMessage()); - $this->assertEqual($xpath[4]->getText(), '00:00'); + $this->assertEquals($xpath[3]->getText(), $log_entry->message ?: $log_entry->formatInitMessage()); + $this->assertEquals($xpath[4]->getText(), '00:00'); // Assert queue cron jobs. $this->config('ultimate_cron.settings') @@ -207,12 +210,12 @@ public function testManageJob() { \Drupal::service('ultimate_cron.discovery')->discoverCronJobs(); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertText('Queue: Broken queue test'); + $this->assertSession()->pageTextContains('Queue: Broken queue test'); $this->drupalGet('admin/config/system/cron/jobs/manage/ultimate_cron_queue_cron_queue_test_broken_queue'); - $this->assertFieldByName('title', 'Queue: Broken queue test'); - $this->drupalPostForm(NULL, [], 'Save'); - $this->assertText('job Queue: Broken queue test has been updated.'); + $this->assertSession()->fieldValueEquals('title', 'Queue: Broken queue test'); + $this->submitForm([], 'Save'); + $this->assertSession()->pageTextContains('job Queue: Broken queue test has been updated.'); } } diff --git a/web/modules/ultimate_cron/tests/src/Functional/CronJobInstallTest.php b/web/modules/ultimate_cron/tests/src/Functional/CronJobInstallTest.php index f89dd34c12b9c1cf9b73b9d7f858573b8777d3fe..76fc6de662f42a3cd3fc4d58301e3edb92a129d4 100644 --- a/web/modules/ultimate_cron/tests/src/Functional/CronJobInstallTest.php +++ b/web/modules/ultimate_cron/tests/src/Functional/CronJobInstallTest.php @@ -44,19 +44,19 @@ public function testManageJob() { // Check default modules \Drupal::service('module_installer')->install(array('field')); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertText('Purges deleted Field API data'); - $this->assertText('Cleanup (caches, batch, flood, temp-files, etc.)'); - $this->assertNoText('Deletes temporary files'); + $this->assertSession()->pageTextContains('Purges deleted Field API data'); + $this->assertSession()->pageTextContains('Cleanup (caches, batch, flood, temp-files, etc.)'); + $this->assertSession()->pageTextNotContains('Deletes temporary files'); // Install new module. \Drupal::service('module_installer')->install(array('file')); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertText('Deletes temporary files'); + $this->assertSession()->pageTextContains('Deletes temporary files'); // Uninstall new module. \Drupal::service('module_installer')->uninstall(array('file')); $this->drupalGet('admin/config/system/cron/jobs'); - $this->assertNoText('Deletes temporary files'); + $this->assertSession()->pageTextNotContains('Deletes temporary files'); } /** @@ -64,8 +64,8 @@ public function testManageJob() { */ public function testRequirements() { $element = ultimate_cron_requirements('runtime')['cron_jobs']; - $this->assertEqual($element['value'], t("Cron is running properly.")); - $this->assertEqual($element['severity'], REQUIREMENT_OK); + $this->assertEquals($element['value'], t("Cron is running properly.")); + $this->assertEquals($element['severity'], REQUIREMENT_OK); $values = array( @@ -75,7 +75,7 @@ public function testRequirements() { 'callback' => 'ultimate_cron_fake_cron', ); - $job = new CronJob($values, 'ultimate_cron_job'); + $job = CronJob::create($values); $job->save(); \Drupal::service('cron')->run(); @@ -93,15 +93,15 @@ public function testRequirements() { ->execute(); // Check run counter, at this point there should be 0 run. - $this->assertEqual(1, \Drupal::state()->get('ultimate_cron.cron_run_counter'), 'Job has run once.'); + $this->assertEquals(1, \Drupal::state()->get('ultimate_cron.cron_run_counter'), 'Job has run once.'); $this->assertNotEmpty($job->isBehindSchedule(), 'Job is behind schedule.'); $element = ultimate_cron_requirements('runtime')['cron_jobs']; - $this->assertEqual($element['value'], '1 job is behind schedule', '"1 job is behind schedule." is displayed'); - $this->assertEqual($element['description']['#markup'], 'Some jobs are behind their schedule. Please check if <a href="' . + $this->assertEquals($element['value'], '1 job is behind schedule', '"1 job is behind schedule." is displayed'); + $this->assertEquals($element['description']['#markup'], 'Some jobs are behind their schedule. Please check if <a href="' . Url::fromRoute('system.cron', ['key' => \Drupal::state()->get('system.cron_key')])->toString() . '">Cron</a> is running properly.', 'Description is correct.'); - $this->assertEqual($element['severity'], REQUIREMENT_WARNING, 'Severity is of level "Error"'); + $this->assertEquals($element['severity'], REQUIREMENT_WARNING, 'Severity is of level "Error"'); } } diff --git a/web/modules/ultimate_cron/tests/src/Functional/LoggerWebTest.php b/web/modules/ultimate_cron/tests/src/Functional/LoggerWebTest.php index 1b274551ec19dcb9e5659a347fb624a5cc439228..6e1066a4a47b1eeedef076feb75e6af5c2fbbfff 100644 --- a/web/modules/ultimate_cron/tests/src/Functional/LoggerWebTest.php +++ b/web/modules/ultimate_cron/tests/src/Functional/LoggerWebTest.php @@ -44,7 +44,7 @@ class LoggerWebTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->user = $this->createUser([ 'administer ultimate cron', @@ -66,8 +66,8 @@ public function testLoggerException() { // Check that the error message is displayed in its log page. $this->drupalGet('admin/config/system/cron/jobs/logs/ultimate_cron_logger_test_cron'); - $this->assertRaw('/core/misc/icons/e32700/error.svg'); - $this->assertRaw('<em class="placeholder">Exception</em>: Test cron exception in <em class="placeholder">ultimate_cron_logger_test_cron()</em> (line'); + $this->assertSession()->responseContains('/core/misc/icons/e32700/error.svg'); + $this->assertSession()->responseContains('<em class="placeholder">Exception</em>: Test cron exception in <em class="placeholder">ultimate_cron_logger_test_cron()</em> (line'); } /** @@ -84,8 +84,8 @@ public function testLoggerFatal() { // Check that the error message is displayed in its log page. $this->drupalGet('admin/config/system/cron/jobs/logs/ultimate_cron_logger_test_cron'); - $this->assertRaw('/core/misc/icons/e32700/error.svg'); - $this->assertRaw('Call to undefined function call_to_undefined_function'); + $this->assertSession()->responseContains('/core/misc/icons/e32700/error.svg'); + $this->assertSession()->responseContains('Call to undefined function call_to_undefined_function'); // Empty the logfile, our fatal errors are expected. $filename = DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'; @@ -107,7 +107,7 @@ public function testLoggerLongMessage() { $xpath = $this->xpath('//table/tbody/tr/td[4]'); // The last 2 chars from xpath are not related to the message. $this->assertTrue(strlen(substr($xpath[0]->getText(), 0, -2)) == 5000); - $this->assertRaw('This is a v…'); + $this->assertSession()->responseContains('This is a v…'); } /** @@ -122,8 +122,8 @@ public function testLoggerLogWarning() { // Check that the error message is displayed in its log page. $this->drupalGet('admin/config/system/cron/jobs/logs/ultimate_cron_logger_test_cron'); - $this->assertRaw('/core/misc/icons/e29700/warning.svg'); - $this->assertRaw('This is a warning message'); + $this->assertSession()->responseContains('/core/misc/icons/e29700/warning.svg'); + $this->assertSession()->responseContains('This is a warning message'); } @@ -136,8 +136,8 @@ public function testLoggerNormal() { // Check that the error message is displayed in its log page. $this->drupalGet('admin/config/system/cron/jobs/logs/ultimate_cron_logger_test_cron'); - $this->assertRaw('/core/misc/icons/73b355/check.svg'); - $this->assertText('Launched in thread 1'); + $this->assertSession()->responseContains('/core/misc/icons/73b355/check.svg'); + $this->assertSession()->pageTextContains('Launched in thread 1'); } /** diff --git a/web/modules/ultimate_cron/tests/src/Kernel/CronJobKernelTest.php b/web/modules/ultimate_cron/tests/src/Kernel/CronJobKernelTest.php index 2124810dccbc393c3676024da998150d08a9e59f..49fec4aae87b020a831628fbe8967943ef9f108c 100644 --- a/web/modules/ultimate_cron/tests/src/Kernel/CronJobKernelTest.php +++ b/web/modules/ultimate_cron/tests/src/Kernel/CronJobKernelTest.php @@ -19,7 +19,7 @@ class CronJobKernelTest extends KernelTestBase { */ public static $modules = array('system', 'ultimate_cron'); - protected function setup() { + protected function setup(): void { parent::setUp(); $this->installSchema('ultimate_cron', [ diff --git a/web/modules/ultimate_cron/tests/src/Kernel/CronJobTest.php b/web/modules/ultimate_cron/tests/src/Kernel/CronJobTest.php index fdea092712160af725745cd4f6e286ae269225b9..2602a190d9636c4962165fa3192c3e6e8bede00c 100644 --- a/web/modules/ultimate_cron/tests/src/Kernel/CronJobTest.php +++ b/web/modules/ultimate_cron/tests/src/Kernel/CronJobTest.php @@ -15,7 +15,7 @@ class CronJobTest extends KernelTestBase { public static $modules = array('ultimate_cron'); - public function setup() { + public function setup(): void { parent::setUp(); $this->installSchema('ultimate_cron', array( diff --git a/web/modules/ultimate_cron/tests/src/Kernel/UltimateCronQueueTest.php b/web/modules/ultimate_cron/tests/src/Kernel/UltimateCronQueueTest.php index 39cbfb8fd542af397d8a967f7440a7b036445443..6a35c76eb1ef73abfed7f820260a76a58f1365f0 100644 --- a/web/modules/ultimate_cron/tests/src/Kernel/UltimateCronQueueTest.php +++ b/web/modules/ultimate_cron/tests/src/Kernel/UltimateCronQueueTest.php @@ -23,9 +23,9 @@ class UltimateCronQueueTest extends CronQueueTest { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); - module_load_install('ultimate_cron'); + \Drupal::moduleHandler()->loadInclude('ultimate_cron', 'install'); ultimate_cron_install(); $this->installSchema('ultimate_cron', [ 'ultimate_cron_log', @@ -58,7 +58,7 @@ public function testExceptions() { // @see \Drupal\Core\Cron::processQueues() $this->connection->update('queue') ->condition('name', 'cron_queue_test_exception') - ->fields(['expire' => REQUEST_TIME - 1]) + ->fields(['expire' => \Drupal::time()->getRequestTime() - 1]) ->execute(); // Has to be manually called for Ultimate Cron. @@ -154,4 +154,11 @@ public function testOverriddenProcessing() { // worker. } + /** + * {@inheritdoc} + */ + public function testLeaseTime() { + $this->markTestSkipped('Test does not support ultimate cron schedule logic'); + } + } diff --git a/web/modules/ultimate_cron/tests/ultimate_cron_logger_test/ultimate_cron_logger_test.info.yml b/web/modules/ultimate_cron/tests/ultimate_cron_logger_test/ultimate_cron_logger_test.info.yml index 9081ead804845be08bb5a49d7ccc6fd384ef0639..7d4f173c2c19a7a1085141bc431153767431f4f7 100644 --- a/web/modules/ultimate_cron/tests/ultimate_cron_logger_test/ultimate_cron_logger_test.info.yml +++ b/web/modules/ultimate_cron/tests/ultimate_cron_logger_test/ultimate_cron_logger_test.info.yml @@ -1,12 +1,11 @@ name: Ultimate Cron Logger Test type: module description: Ultimate Cron Logger Test -core_version_requirement: ^8.7.7 || ^9 -package: Tests +package: Testing dependencies: - ultimate_cron -# Information added by Drupal.org packaging script on 2020-09-24 -version: '8.x-2.0-alpha5' +# Information added by Drupal.org packaging script on 2022-10-22 +version: '8.x-2.0-alpha6' project: 'ultimate_cron' -datestamp: 1600928951 +datestamp: 1666471451 diff --git a/web/modules/ultimate_cron/ultimate_cron.api.php b/web/modules/ultimate_cron/ultimate_cron.api.php index 8f3e7d7a643437dca99a7b22930a9e94135f8eb0..62c00502d3e183aad0876d69cee56f0ea8d64743 100644 --- a/web/modules/ultimate_cron/ultimate_cron.api.php +++ b/web/modules/ultimate_cron/ultimate_cron.api.php @@ -73,7 +73,7 @@ function hook_cronapi() { $items['example_my_cron_job_1'] = array( 'title' => t('This is my cron job #1'), 'file' => 'example.jobs.inc', - 'file path' => drupal_get_path('module', 'example') . '/cron', + 'file path' => \Drupal::service('extension.list.module')->getPath('example') . '/cron', 'callback' => 'example_my_cron_job_callback', 'callback arguments' => array('cronjob1'), 'enabled' => FALSE, diff --git a/web/modules/ultimate_cron/ultimate_cron.info.yml b/web/modules/ultimate_cron/ultimate_cron.info.yml index ef825f2a5a67a7fa1637ea409f352628df6aa752..a9cdf8b06b379893688053a0509dd468e7952f58 100644 --- a/web/modules/ultimate_cron/ultimate_cron.info.yml +++ b/web/modules/ultimate_cron/ultimate_cron.info.yml @@ -1,10 +1,10 @@ type: module name: "Ultimate Cron" description: "Cron" -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^9.3 || ^10 configure: entity.ultimate_cron_job.collection -# Information added by Drupal.org packaging script on 2020-09-24 -version: '8.x-2.0-alpha5' +# Information added by Drupal.org packaging script on 2022-10-22 +version: '8.x-2.0-alpha6' project: 'ultimate_cron' -datestamp: 1600928951 +datestamp: 1666471451 diff --git a/web/modules/ultimate_cron/ultimate_cron.module b/web/modules/ultimate_cron/ultimate_cron.module index 15035785d26094d267d9b95b5b83ca5aa98a4e56..9516262f1736cf29dc4f074f9313d4e3f56d02e7 100755 --- a/web/modules/ultimate_cron/ultimate_cron.module +++ b/web/modules/ultimate_cron/ultimate_cron.module @@ -1,4 +1,8 @@ <?php + +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Database\Database; + /** * @file * Ultimate Cron. Extend cron functionality in Drupal. @@ -159,7 +163,7 @@ function ultimate_cron_hook_info() { * Implements hook_help(). * */ -function ultimate_cron_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) { +function ultimate_cron_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.ultimate_cron': // Return a line-break version of the module README. @@ -256,5 +260,5 @@ function _ultimate_cron_multi_column_sort($a, $b) { * Connection target. */ function _ultimate_cron_get_transactional_safe_connection() { - return !\Drupal::config('ultimate_cron.settings')->get('bypass_transactional_safe_connection') && \Drupal\Core\Database\Database::getConnection()->inTransaction() ? 'ultimate_cron' : 'default'; + return !\Drupal::config('ultimate_cron.settings')->get('bypass_transactional_safe_connection') && Database::getConnection()->inTransaction() ? 'ultimate_cron' : 'default'; }