Commit fb28836d authored by thalles's avatar thalles Committed by moshe weitzman

Issue #2935280 by kala4ek, thalles: Deprecated constant REQUEST_TIME

parent ad091a19
......@@ -112,7 +112,7 @@ function devel_generate_add_comments(NodeInterface $node, FieldDefinitionInterfa
'field_name' => $field_name,
'name' => 'devel generate',
'mail' => 'devel_generate@example.com',
'timestamp' => mt_rand($node->getCreatedTime(), REQUEST_TIME),
'timestamp' => mt_rand($node->getCreatedTime(), \Drupal::time()->getRequestTime()),
'subject' => substr($random->sentences(mt_rand(2, $title_length), TRUE), 0, 63),
'uid' => $users[array_rand($users)],
'langcode' => $node->language()->getId(),
......@@ -138,7 +138,7 @@ function devel_generate_add_statistics(NodeInterface $node) {
$statistic = array(
'nid' => $node->id(),
'totalcount' => mt_rand(0, 500),
'timestamp' => REQUEST_TIME - mt_rand(0, $node->getCreatedTime()),
'timestamp' => \Drupal::time()->getRequestTime() - mt_rand(0, $node->getCreatedTime()),
);
$statistic['daycount'] = mt_rand(0, $statistic['totalcount']);
db_insert('node_counter')->fields($statistic)->execute();
......
......@@ -3,6 +3,7 @@
namespace Drupal\devel_generate\Plugin\DevelGenerate;
use Drupal\comment\CommentManagerInterface;
use Drupal\Component\Datetime\Time;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -93,11 +94,21 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
protected $drushBatch;
/**
* Provides system time.
*
* @var \Drupal\Core\Datetime\Time
*/
protected $time;
/**
* The construct.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $node_storage
* The node storage.
* @param \Drupal\Core\Entity\EntityStorageInterface $node_type_storage
......@@ -112,8 +123,10 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
* The url generator service.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Datetime\Time $time
* Provides system time.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $node_storage, EntityStorageInterface $node_type_storage, ModuleHandlerInterface $module_handler, CommentManagerInterface $comment_manager = NULL, LanguageManagerInterface $language_manager, UrlGeneratorInterface $url_generator, DateFormatterInterface $date_formatter) {
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $node_storage, EntityStorageInterface $node_type_storage, ModuleHandlerInterface $module_handler, CommentManagerInterface $comment_manager = NULL, LanguageManagerInterface $language_manager, UrlGeneratorInterface $url_generator, DateFormatterInterface $date_formatter, Time $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
......@@ -123,6 +136,7 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
$this->languageManager = $language_manager;
$this->urlGenerator = $url_generator;
$this->dateFormatter = $date_formatter;
$this->time = $time;
}
/**
......@@ -138,7 +152,8 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
$container->has('comment.manager') ? $container->get('comment.manager') : NULL,
$container->get('language_manager'),
$container->get('url_generator'),
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time')
);
}
......@@ -490,7 +505,7 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
'revision' => mt_rand(0, 1),
'status' => TRUE,
'promote' => mt_rand(0, 1),
'created' => REQUEST_TIME - mt_rand(0, $results['time_range']),
'created' => $this->time->getRequestTime() - mt_rand(0, $results['time_range']),
'langcode' => $this->getLangcode($results),
));
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\devel_generate\DevelGenerateBase;
use Drush\Utils\StringUtils;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Datetime\Time;
/**
* Provides a UserDevelGenerate plugin.
......@@ -42,6 +43,13 @@ class UserDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu
*/
protected $dateFormatter;
/**
* Provides system time.
*
* @var \Drupal\Core\Datetime\Time
*/
protected $time;
/**
* Constructs a new UserDevelGenerate object.
*
......@@ -55,12 +63,15 @@ class UserDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu
* The user storage.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Datetime\Time $time
* Provides system time.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, Time $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->userStorage = $entity_storage;
$this->dateFormatter = $date_formatter;
$this->time = $time;
}
/**
......@@ -70,7 +81,8 @@ class UserDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu
return new static(
$configuration, $plugin_id, $plugin_definition,
$container->get('entity.manager')->getStorage('user'),
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time')
);
}
......@@ -161,7 +173,7 @@ class UserDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu
'pass' => $pass,
'mail' => $name . '@example.com',
'status' => 1,
'created' => REQUEST_TIME - mt_rand(0, $age),
'created' => $this->time->getRequestTime() - mt_rand(0, $age),
'roles' => array_values($roles),
// A flag to let hook_user_* know that this is a generated user.
'devel_generate' => TRUE,
......
......@@ -59,7 +59,7 @@ class ExampleDevelGenerate extends DevelGenerateBase {
'pass' => '',
'mail' => 'example_devel_generate@example.com',
'status' => 1,
'created' => REQUEST_TIME,
'created' => \Drupal::time()->getRequestTime(),
'roles' => '',
'devel_generate' => TRUE // A flag to let hook_user_* know that this is a generated user.
);
......
......@@ -2,7 +2,9 @@
/**
* @file
* This file is only used by Drush8. Drush9 discovers its commands via tagged
* This file is only used by Drush8.
*
* Drush9 discovers its commands via tagged
* service(s) in devel.services.yml. Also see classes in src/Commands.
*/
......@@ -12,95 +14,95 @@ use Drupal\Component\Uuid\Php;
* Implements hook_drush_command().
*/
function devel_drush_command() {
$items['devel-reinstall'] = array(
$items['devel-reinstall'] = [
'description' => dt('Uninstall, and Install a list of projects.'),
'drush dependencies' => array('pm'),
'arguments' => array(
'drush dependencies' => ['pm'],
'arguments' => [
'projects' => dt('A space-separated list of project names.'),
),
'allow-additional-options' => array('pm-uninstall', 'pm-enable'),
],
'allow-additional-options' => ['pm-uninstall', 'pm-enable'],
'required-arguments' => 1,
'aliases' => array('dre'),
);
$items['fn-hook'] = array(
'aliases' => ['dre'],
];
$items['fn-hook'] = [
'description' => 'List implementations of a given hook and explore the source of the selected one.',
'arguments' => array(
'hook' => 'The name of the hook to explore (e.g. "menu" for hook_menu()).'
),
'examples' => array(
'arguments' => [
'hook' => 'The name of the hook to explore (e.g. "menu" for hook_menu()).',
],
'examples' => [
'fn-hook cron' => 'List implementations of hook_cron().',
),
'allow-additional-options' => array('fn-view'),
],
'allow-additional-options' => ['fn-view'],
'required-arguments' => 1,
'aliases' => array('fnh', 'hook'),
);
$items['fn-event'] = array(
'aliases' => ['fnh', 'hook'],
];
$items['fn-event'] = [
'description' => 'List implementations of a given event and explore source of specified one.',
'arguments' => array(
'event' => 'The name of the event to explore. If omitted, a list of events is shown.'
),
'examples' => array(
'arguments' => [
'event' => 'The name of the event to explore. If omitted, a list of events is shown.',
],
'examples' => [
'fn-event' => 'Pick a Kernel event, then pick an implementation, and then view its source code.',
'fn-event kernel.terminate' => 'Pick a terminate subscribers and view its source code.',
),
'allow-additional-options' => array('fn-view'),
'aliases' => array('fne', 'event'),
);
$items['fn-view'] = array(
],
'allow-additional-options' => ['fn-view'],
'aliases' => ['fne', 'event'],
];
$items['fn-view'] = [
'description' => 'Show the source of specified function or method.',
'arguments' => array(
'arguments' => [
'function' => 'The name of the function or method to view.',
),
'options' => array(
],
'options' => [
'pipe' => 'Output just the filename of the function or method',
'format' => 'Specify how the filename should be printed. Available placeholders are @startline, @endline and @file',
),
'examples' => array(
],
'examples' => [
'fn-view drupal_set_breadcrumb' => 'View the source code for function "drupal_set_breadcrumb"',
'vi `drush --pipe fn-view user_access --format=\'+@startline @file\'`' => 'Edit the file that contains the function "user_access"',
'fn-view NodeController::load' => 'View the source code for method load in the class NodeController'
),
'aliases' => array('fnv'),
'fn-view NodeController::load' => 'View the source code for method load in the class NodeController',
],
'aliases' => ['fnv'],
'required-arguments' => 1,
);
$items['devel-token'] = array(
];
$items['devel-token'] = [
'description' => dt('List available tokens'),
'aliases' => array('token'),
//@todo support --format option for json, csv, etc.
);
'aliases' => ['token'],
// @todo support --format option for json, csv, etc.
];
$items['devel-container-services'] = array(
$items['devel-container-services'] = [
'description' => 'Get a list of available container services.',
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
'core' => array('8+'),
'aliases' => array('dcs'),
'options' => array(
'core' => ['8+'],
'aliases' => ['dcs'],
'options' => [
'format' => 'Format to output. Allowed values are: json, export, html.',
),
'arguments' => array(
],
'arguments' => [
'prefix' => 'A prefix to filter the service list by.',
),
'examples' => array(
],
'examples' => [
'drush container-services' => 'Gets a list of all available container services',
'drush container-services plugin.manager' => 'Get all services containing "plugin.manager"',
),
'outputformat' => array(
],
'outputformat' => [
'default' => 'list',
'pipe-format' => 'export',
),
);
],
];
$items['devel-generate-uuid'] = array(
$items['devel-generate-uuid'] = [
'description' => 'Generate a UUID.',
'core' => array('8+'),
'examples' => array(
'core' => ['8+'],
'examples' => [
"drush devel-generate-uuid" => "Outputs a Universally Unique IDentifier.",
),
'aliases' => array('uuid'),
'outputformat' => array(
],
'aliases' => ['uuid'],
'outputformat' => [
'default' => 'string',
),
);
],
];
return $items;
}
......@@ -111,10 +113,10 @@ function devel_drush_command() {
function drush_devel_reinstall() {
$projects = func_get_args();
$args = array_merge(array('pm-uninstall'), $projects);
$args = array_merge(['pm-uninstall'], $projects);
call_user_func_array('drush_invoke', $args);
$args = array_merge(array('pm-enable'), $projects);
$args = array_merge(['pm-enable'], $projects);
call_user_func_array('drush_invoke', $args);
}
......@@ -142,7 +144,10 @@ function drush_devel_fn_hook($hook) {
function drush_devel_fn_event($event = NULL) {
$dispatcher = Drupal::service('event_dispatcher');
if (empty($event)) {
$events = array('kernel.controller', 'kernel.exception', 'kernel.request', 'kernel.response', 'kernel.terminate', 'kernel.view');
$events = [
'kernel.controller', 'kernel.exception', 'kernel.request',
'kernel.response', 'kernel.terminate', 'kernel.view',
];
$events = array_combine($events, $events);
if (!$event = drush_choice($events, 'Enter the event you wish to explore.')) {
return drush_user_abort();
......@@ -183,7 +188,11 @@ function drush_devel_fn_view($function_name) {
}
$reflect = new ReflectionMethod($class, $method);
}
$func_info = array('@file' => $reflect->getFileName(), '@startline' => $reflect->getStartLine(), '@endline' => $reflect->getEndLine());
$func_info = [
'@file' => $reflect->getFileName(),
'@startline' => $reflect->getStartLine(),
'@endline' => $reflect->getEndLine(),
];
$format = drush_get_option('format', '@file');
drush_print_pipe(dt($format, $func_info));
drush_print(dt("// file: @file, lines @startline-@endline", $func_info));
......@@ -195,11 +204,11 @@ function drush_devel_fn_view($function_name) {
* Command callback. List available tokens.
*/
function drush_devel_token() {
$rows[] = array(dt('Group'), dt('Token'), dt('Name'));
$rows[] = [dt('Group'), dt('Token'), dt('Name')];
$all = \Drupal::token()->getInfo();
foreach ($all['tokens'] as $group => $tokens) {
foreach ($tokens as $key => $token) {
$rows[] = array($group, $key, $token['name']);
$rows[] = [$group, $key, $token['name']];
}
}
drush_print_table($rows, TRUE);
......@@ -217,19 +226,21 @@ function drush_devel_generate_uuid() {
}
/**
* Print the specified function.
*
* Print the specified function, including any
* doxygen-style comments that come before it.
*/
function _drush_devel_print_function($file, $start_line, $end_line) {
$line_num = 0;
$doxygen = NULL;
$fp = fopen( $file, 'r' );
$fp = fopen($file, 'r');
while (!feof($fp) && ($line_num < ($start_line - 1))) {
$line = fgets($fp);
++$line_num;
if (substr($line,0,3) == '/**') {
if (substr($line, 0, 3) == '/**') {
$doxygen = $line;
}
elseif (isset($doxygen)) {
......
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