diff --git a/devel.module b/devel.module index e733079..4eb143e 100644 --- a/devel.module +++ b/devel.module @@ -564,7 +564,7 @@ function ddebug_backtrace($return = FALSE, $pop = 0, $options = DEBUG_BACKTRACE_ */ function devel_rebuild_node_comment_statistics() { // Empty table. - db_truncate('node_comment_statistics')->execute(); + \Drupal::database()->truncate('node_comment_statistics')->execute(); // TODO: DBTNG. Ignore keyword is Mysql only? Is only used in the rare case // when two comments on the same node share same timestamp. @@ -575,10 +575,10 @@ function devel_rebuild_node_comment_statistics() { SELECT c.nid, MAX(c.created) AS created, COUNT(*) AS comment_count FROM {comment} c WHERE status = 1 GROUP BY c.nid ) AS c2 ON c.nid = c2.nid AND c.created = c2.created )"; - db_query($sql, array(':published' => CommentInterface::PUBLISHED)); + \Drupal::database()->query($sql, array(':published' => CommentInterface::PUBLISHED)); // Insert records into the node_comment_statistics for nodes that are missing. - $query = db_select('node', 'n'); + $query = \Drupal::database()->select('node', 'n'); $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid'); $query->addField('n', 'changed', 'last_comment_timestamp'); $query->addField('n', 'uid', 'last_comment_uid'); @@ -587,7 +587,7 @@ function devel_rebuild_node_comment_statistics() { $query->addExpression('NULL', 'last_comment_name'); $query->isNull('ncs.comment_count'); - db_insert('node_comment_statistics', array('return' => Database::RETURN_NULL)) + Database::getConnection()->insert('node_comment_statistics', array('return' => Database::RETURN_NULL)) ->from($query) ->execute(); } diff --git a/devel_generate/devel_generate.module b/devel_generate/devel_generate.module index 530a4fb..69a36c3 100644 --- a/devel_generate/devel_generate.module +++ b/devel_generate/devel_generate.module @@ -141,5 +141,5 @@ function devel_generate_add_statistics(NodeInterface $node) { 'timestamp' => REQUEST_TIME - mt_rand(0, $node->getCreatedTime()), ); $statistic['daycount'] = mt_rand(0, $statistic['totalcount']); - db_insert('node_counter')->fields($statistic)->execute(); + Database::getConnection()->insert('node_counter')->fields($statistic)->execute(); } diff --git a/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php b/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php index 6070e02..9ceef03 100644 --- a/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php +++ b/devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php @@ -5,6 +5,7 @@ namespace Drupal\devel_generate\Plugin\DevelGenerate; use Drupal\comment\CommentManagerInterface; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; @@ -36,6 +37,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactoryPluginInterface { /** + * Database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * The node storage. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -104,8 +112,22 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory * The url generator service. * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter service. + * @param \Drupal\Core\Database\Connection $database + * Database connection. */ - 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, + Connection $database) { + parent::__construct($configuration, $plugin_id, $plugin_definition); $this->moduleHandler = $module_handler; @@ -115,6 +137,7 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory $this->languageManager = $language_manager; $this->urlGenerator = $url_generator; $this->dateFormatter = $date_formatter; + $this->database = $database; } /** @@ -130,7 +153,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('database') ); } @@ -496,7 +520,7 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory */ protected function getUsers() { $users = array(); - $result = db_query_range("SELECT uid FROM {users}", 0, 50); + $result = $this->database->queryRange("SELECT uid FROM {users}", 0, 50); foreach ($result as $record) { $users[] = $record->uid; } diff --git a/devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php b/devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php index 7c961a6..033eb60 100644 --- a/devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php +++ b/devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php @@ -3,6 +3,7 @@ namespace Drupal\devel_generate\Plugin\DevelGenerate; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; @@ -33,6 +34,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class MenuDevelGenerate extends DevelGenerateBase implements ContainerFactoryPluginInterface { /** + * Database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * The menu tree service. * * @var \Drupal\Core\Menu\MenuLinkTreeInterface @@ -77,14 +85,26 @@ class MenuDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu * The menu storage. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\Database\Connection $database + * Database connection. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, EntityStorageInterface $menu_storage, EntityStorageInterface $menu_link_storage, ModuleHandlerInterface $module_handler) { + public function __construct( + array $configuration, + $plugin_id, + $plugin_definition, + MenuLinkTreeInterface $menu_tree, + EntityStorageInterface $menu_storage, + EntityStorageInterface $menu_link_storage, + ModuleHandlerInterface $module_handler, + Connection $database) { + parent::__construct($configuration, $plugin_id, $plugin_definition); $this->menuLinkTree = $menu_tree; $this->menuStorage = $menu_storage; $this->menuLinkContentStorage = $menu_link_storage; $this->moduleHandler = $module_handler; + $this->database = $database; } /** @@ -97,7 +117,8 @@ class MenuDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu $container->get('menu.link_tree'), $entity_manager->getStorage('menu'), $entity_manager->getStorage('menu_link_content'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('database') ); } @@ -276,7 +297,7 @@ class MenuDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu // Delete menu links generated by devel. $link_ids = $this->menuLinkContentStorage->getQuery() ->condition('menu_name', 'devel', '<>') - ->condition('link__options', '%' . db_like('s:5:"devel";b:1') . '%', 'LIKE') + ->condition('link__options', '%' . $this->database->escapeLike('s:5:"devel";b:1') . '%', 'LIKE') ->execute(); if ($link_ids) { @@ -366,7 +387,7 @@ class MenuDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu switch ($link_types[$link_type]) { case 'node': // Grab a random node ID. - $select = db_select('node_field_data', 'n') + $select = $this->database->select('node_field_data', 'n') ->fields('n', array('nid', 'title')) ->condition('n.status', 1) ->range(0, 1) diff --git a/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php b/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php index f7aa39b..3727a08 100644 --- a/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php +++ b/devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php @@ -2,6 +2,7 @@ namespace Drupal\devel_generate\Plugin\DevelGenerate; +use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\Language; @@ -28,6 +29,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPluginInterface { /** + * Database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * The vocabulary storage. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -54,12 +62,22 @@ class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu * The vocabulary storage. * @param \Drupal\Core\Entity\EntityStorageInterface $term_storage * The term storage. + * @param \Drupal\Core\Database\Connection $database + * Database connection. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $vocabulary_storage, EntityStorageInterface $term_storage) { + public function __construct( + array $configuration, + $plugin_id, + $plugin_definition, + EntityStorageInterface $vocabulary_storage, + EntityStorageInterface $term_storage, + Connection $database) { + parent::__construct($configuration, $plugin_id, $plugin_definition); $this->vocabularyStorage = $vocabulary_storage; $this->termStorage = $term_storage; + $this->database = $database; } /** @@ -70,7 +88,8 @@ class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu return new static( $configuration, $plugin_id, $plugin_definition, $entity_manager->getStorage('taxonomy_vocabulary'), - $entity_manager->getStorage('taxonomy_term') + $entity_manager->getStorage('taxonomy_term'), + $container->get('database') ); } @@ -160,7 +179,7 @@ class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu $terms = array(); // Insert new data: - $max = db_query('SELECT MAX(tid) FROM {taxonomy_term_data}')->fetchField(); + $max = $this->database->query('SELECT MAX(tid) FROM {taxonomy_term_data}')->fetchField(); $start = time(); for ($i = 1; $i <= $records; $i++) { $name = $this->getRandom()->word(mt_rand(2, $maxlength)); @@ -184,7 +203,7 @@ class TermDevelGenerate extends DevelGenerateBase implements ContainerFactoryPlu while (TRUE) { // Keep trying to find a random parent. $candidate = mt_rand(1, $max); - $query = db_select('taxonomy_term_data', 't'); + $query = $this->database->select('taxonomy_term_data', 't'); $parent = $query ->fields('t', array('tid', 'vid')) ->condition('t.vid', array_keys($vocabs), 'IN')