Unverified Commit d23b4cc8 authored by alexpott's avatar alexpott

Issue #3112295 by mpdonadio, Hardik_Patel_12, daffie, JeroenT, Vlad Bo,...

Issue #3112295 by mpdonadio, Hardik_Patel_12, daffie, JeroenT, Vlad Bo, pifagor, voleger, alexpott: Replace REQUEST_TIME in OO code w/o access to the container
parent 42b761c3
......@@ -291,10 +291,10 @@ public static function weekDaysOrdered($weekdays) {
public static function years($min = 0, $max = 0, $required = FALSE) {
// Ensure $min and $max are valid values.
if (empty($min)) {
$min = intval(date('Y', REQUEST_TIME) - 3);
$min = intval(date('Y', \Drupal::time()->getRequestTime()) - 3);
}
if (empty($max)) {
$max = intval(date('Y', REQUEST_TIME) + 3);
$max = intval(date('Y', \Drupal::time()->getRequestTime()) + 3);
}
$none = ['' => ''];
$range = range($min, $max);
......
......@@ -106,7 +106,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
$date_formats = [];
foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $machine_name)]);
}
$date_formats['custom'] = $this->t('Custom');
......
......@@ -30,7 +30,7 @@ public function preSave() {
// Set the timestamp to request time if it is not set.
if (!$this->value) {
$this->value = REQUEST_TIME;
$this->value = \Drupal::time()->getRequestTime();
}
else {
// On an existing entity translation, the changed timestamp will only be
......@@ -47,7 +47,7 @@ public function preSave() {
if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) {
$original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value;
if ($this->value == $original_value && $entity->hasTranslationChanges()) {
$this->value = REQUEST_TIME;
$this->value = \Drupal::time()->getRequestTime();
}
}
}
......
......@@ -22,7 +22,7 @@ class CreatedItem extends TimestampItem {
public function applyDefaultValue($notify = TRUE) {
parent::applyDefaultValue($notify);
// Created fields default to the current timestamp.
$this->setValue(['value' => REQUEST_TIME], $notify);
$this->setValue(['value' => \Drupal::time()->getRequestTime()], $notify);
return $this;
}
......
......@@ -36,7 +36,7 @@ public function has($key) {
return (bool) $this->connection->query('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :key AND expire > :now', [
':collection' => $this->collection,
':key' => $key,
':now' => REQUEST_TIME,
':now' => \Drupal::time()->getRequestTime(),
])->fetchField();
}
......@@ -47,7 +47,7 @@ public function getMultiple(array $keys) {
$values = $this->connection->query(
'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE expire > :now AND name IN ( :keys[] ) AND collection = :collection',
[
':now' => REQUEST_TIME,
':now' => \Drupal::time()->getRequestTime(),
':keys[]' => $keys,
':collection' => $this->collection,
])->fetchAllKeyed();
......@@ -62,7 +62,7 @@ public function getAll() {
'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND expire > :now',
[
':collection' => $this->collection,
':now' => REQUEST_TIME,
':now' => \Drupal::time()->getRequestTime(),
])->fetchAllKeyed();
return array_map([$this->serializer, 'decode'], $values);
}
......@@ -78,7 +78,7 @@ public function setWithExpire($key, $value, $expire) {
])
->fields([
'value' => $this->serializer->encode($value),
'expire' => REQUEST_TIME + $expire,
'expire' => \Drupal::time()->getRequestTime() + $expire,
])
->execute();
}
......
......@@ -87,9 +87,10 @@ protected function doCreateItem($data) {
->fields([
'name' => $this->name,
'data' => serialize($data),
// We cannot rely on REQUEST_TIME because many items might be created
// by a single request which takes longer than 1 second.
'created' => time(),
// We cannot rely on \Drupal::time()->getRequestTime() because many
// items might be created by a single request which takes longer than 1
// second.
'created' => \Drupal::time()->getCurrentTime(),
]);
// Return the new serial ID, or FALSE on failure.
return $query->execute();
......@@ -214,7 +215,7 @@ public function garbageCollection() {
try {
// Clean up the queue for failed batches.
$this->connection->delete(static::TABLE_NAME)
->condition('created', REQUEST_TIME - 864000, '<')
->condition('created', \Drupal::time()->getRequestTime() - 864000, '<')
->condition('name', 'drupal_batch:%', 'LIKE')
->execute();
......@@ -225,7 +226,7 @@ public function garbageCollection() {
'expire' => 0,
])
->condition('expire', 0, '<>')
->condition('expire', REQUEST_TIME, '<')
->condition('expire', \Drupal::time()->getRequestTime(), '<')
->execute();
}
catch (\Exception $e) {
......
......@@ -112,7 +112,7 @@ public function write($key, $content) {
$this->storage()->save($key, $content);
// Save the last mtime.
$cid = 'twig:' . $key;
$this->cache->set($cid, REQUEST_TIME);
$this->cache->set($cid, \Drupal::time()->getRequestTime());
}
/**
......
......@@ -85,7 +85,7 @@ public function refreshItems() {
$success = \Drupal::service('aggregator.items.importer')->refresh($this);
// Regardless of successful or not, indicate that it has been checked.
$this->setLastCheckedTime(REQUEST_TIME);
$this->setLastCheckedTime(\Drupal::time()->getRequestTime());
$this->setQueuedTime(0);
$this->save();
......
......@@ -16,7 +16,7 @@ public function getTranslationElement(LanguageInterface $translation_language, $
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$description = $this->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.');
$format = $this->t('Displayed as %date_format', ['%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)]);
$format = $this->t('Displayed as %date_format', ['%date_format' => $date_formatter->format(\Drupal::time()->getRequestTime(), 'custom', $translation_config)]);
return [
'#type' => 'textfield',
......
......@@ -107,7 +107,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
// Just pick a date in the past year. No guidance is provided by this Field
// type.
$timestamp = REQUEST_TIME - mt_rand(0, 86400 * 365);
$timestamp = \Drupal::time()->getRequestTime() - mt_rand(0, 86400 * 365);
if ($type == DateTimeItem::DATETIME_TYPE_DATE) {
$values['value'] = gmdate(static::DATE_STORAGE_FORMAT, $timestamp);
}
......
......@@ -94,7 +94,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
// Just pick a date in the past year. No guidance is provided by this Field
// type.
$start = REQUEST_TIME - mt_rand(0, 86400 * 365) - 86400;
$start = \Drupal::time()->getRequestTime() - mt_rand(0, 86400 * 365) - 86400;
$end = $start + 86400;
if ($type == static::DATETIME_TYPE_DATETIME) {
$values['value'] = gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start);
......
......@@ -286,7 +286,7 @@ public static function finished($success, $results, $operations, $elapsed) {
*/
public static function onPostRowSave(MigratePostRowSaveEvent $event) {
// We want to interrupt this batch and start a fresh one.
if ((time() - REQUEST_TIME) > static::$maxExecTime) {
if ((\Drupal::time()->getCurrentTime() - \Drupal::time()->getRequestTime()) > static::$maxExecTime) {
$event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
}
}
......@@ -317,7 +317,7 @@ public static function onPostImport(MigrateImportEvent $event) {
*/
public static function onPostRowDelete(MigrateRowDeleteEvent $event) {
// We want to interrupt this batch and start a fresh one.
if ((time() - REQUEST_TIME) > static::$maxExecTime) {
if ((\Drupal::time()->getCurrentTime() - \Drupal::time()->getRequestTime()) > static::$maxExecTime) {
$event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
}
}
......
......@@ -1686,7 +1686,7 @@ public function preExecute($args = []) {
\Drupal::moduleHandler()->invokeAll('views_pre_view', [$this, $display_id, &$this->args]);
// Allow hook_views_pre_view() to set the dom_id, then ensure it is set.
$this->dom_id = !empty($this->dom_id) ? $this->dom_id : hash('sha256', $this->storage->id() . REQUEST_TIME . mt_rand());
$this->dom_id = !empty($this->dom_id) ? $this->dom_id : hash('sha256', $this->storage->id() . \Drupal::time()->getRequestTime() . mt_rand());
// Allow the display handler to set up for execution
$this->display_handler->preExecute();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment