diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 3ecd766..b0adc5e 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -312,7 +312,7 @@ protected function attachPropertyData(array &$entities, $revision_id = FALSE) { if ($this->revisionTable) { // Unless a revision ID was specified we are dealing with the default // revision. - $entities[$id]->getBCEntity()->isDefaultRevision = intval(empty($revision_id)); + $entities[$id]->isDefaultRevision(empty($revision_id)); } // Field values in default language are stored with LANGUAGE_DEFAULT as diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 42cb494..c91d431 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -279,37 +279,7 @@ function book_entity_view_mode_info() { * An array of all books. */ function book_get_books() { - $all_books = &drupal_static(__FUNCTION__); - - if (!isset($all_books)) { - $all_books = array(); - $nids = db_query("SELECT DISTINCT(bid) FROM {book}")->fetchCol(); - - if ($nids) { - $query = db_select('book', 'b', array('fetch' => PDO::FETCH_ASSOC)); - $query->join('node', 'nb', 'b.nid = nb.nid'); - $query->join('node_property_data', 'n', 'nb.nid = n.nid'); - $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); - $query->addField('nb', 'type', 'type'); - $query->fields('b'); - $query->fields('ml'); - $query->condition('nb.nid', $nids, 'IN'); - $query->condition('n.status', 1); - $query->orderBy('ml.weight'); - $query->orderBy('ml.link_title'); - $query->addTag('node_access'); - $result2 = $query->execute(); - foreach ($result2 as $link) { - $node = node_load($link['nid']); - $link['href'] = $link['link_path']; - $link['options'] = unserialize($link['options']); - $link['title'] = $node->label(); - $all_books[$link['bid']] = $link; - } - } - } - - return $all_books; + return Drupal::service('book.manager')->getAllBooks(); } /** diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 254c6ec..9d8c140 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -1,4 +1,4 @@ services: book.manager: class: Drupal\book\BookManager - arguments: ['@database'] + arguments: ['@database', '@plugin.manager.entity'] diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index cf2070b..50d7385 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -6,8 +6,9 @@ namespace Drupal\book; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Book Manager Service. @@ -22,6 +23,13 @@ class BookManager { protected $database; /** + * Entity manager Service Object. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** * Books Array. * * @var array @@ -31,8 +39,9 @@ class BookManager { /** * Constructs a BookManager object. */ - public function __construct(Connection $database) { + public function __construct(Connection $database, EntityManager $entityManager) { $this->database = $database; + $this->entityManager = $entityManager; } /** @@ -57,24 +66,27 @@ public function getAllBooks() { protected function loadBooks() { $this->books = array(); $nids = $this->database->query("SELECT DISTINCT(bid) FROM {book}")->fetchCol(); + if ($nids) { - $query = $this->database->select('book', 'b', array('fetch' => \PDO::FETCH_ASSOC)); - $query->join('node', 'n', 'b.nid = n.nid'); + $query = db_select('book', 'b', array('fetch' => \PDO::FETCH_ASSOC)); $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); - $query->addField('n', 'type', 'type'); - $query->addField('n', 'title', 'title'); $query->fields('b'); $query->fields('ml'); - $query->condition('n.nid', $nids, 'IN'); - $query->condition('n.status', 1); + $query->condition('b.nid', $nids); $query->orderBy('ml.weight'); $query->orderBy('ml.link_title'); - $query->addTag('node_access'); $book_links = $query->execute(); + + $nodes = $this->entityManager->getStorageController('node')->load($nids); + foreach ($book_links as $link) { - $link['href'] = $link['link_path']; - $link['options'] = unserialize($link['options']); - $this->books[$link['bid']] = $link; + $node = $nodes[$link['nid']]; + if ($node->status) { + $link['href'] = $link['link_path']; + $link['options'] = unserialize($link['options']); + $link['title'] = $node->label(); + $this->books[$link['bid']] = $link; + } } } } diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index a4737d8..42a527b 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -118,8 +118,8 @@ function hook_search_reset() { * @ingroup search */ function hook_search_status() { - $total = db_query('SELECT COUNT(*) FROM {example} WHERE status = 1')->fetchField(); - $remaining = db_query("SELECT COUNT(*) FROM {example} e LEFT JOIN {search_dataset} d ON d.type = 'example' AND d.sid = e.id WHERE e.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchField(); + $total = db_query('SELECT COUNT(*) FROM {node}')->fetchField(); + $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0")->fetchField(); return array('remaining' => $remaining, 'total' => $total); } @@ -205,17 +205,16 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $query = db_select('search_index', 'i', array('target' => 'slave')) ->extend('Drupal\search\SearchQuery') ->extend('Drupal\Core\Database\Query\PagerSelectExtender'); - $query->join('example', 'e', 'e.id = i.sid'); + $query->join('node', 'n', 'n.nid = i.sid'); $query - ->condition('e.status', 1) - ->addTag('example_access') - ->searchExpression($keys, 'example'); + ->addTag('node_access') + ->searchExpression($keys, 'node'); // Insert special keywords. - $query->setOption('type', 'e.type'); - $query->setOption('langcode', 'e.langcode'); + $query->setOption('type', 'n.type'); + $query->setOption('langcode', 'n.langcode'); if ($query->setOption('term', 'ti.tid')) { - $query->join('taxonomy_index', 'ti', 'e.id = ti.id'); + $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid'); } // Only continue if the first pass query matches. if (!$query->executeFirstPass()) { @@ -232,15 +231,15 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $results = array(); foreach ($find as $item) { // Render the node. - $example = example_load($item->sid); - $build = example_view($example, 'search_result', $item->langcode); + $node = node_load($item->sid); + $build = node_view($node, 'search_result', $item->langcode); unset($build['#theme']); - $example->rendered = drupal_render($build); + $node->rendered = drupal_render($build); // Fetch comments for snippet. - $example->rendered .= ' ' . module_invoke('comment', 'node_update_index', $example, $item->langcode); + $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node, $item->langcode); - $extra = module_invoke_all('node_search_result', $example, $item->langcode); + $extra = module_invoke_all('node_search_result', $node, $item->langcode); $language = language_load($item->langcode); $uri = $example->uri(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 16eea45..8bb6aca 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -273,11 +273,6 @@ protected function drupalCreateNode(array $settings = array()) { } $node->save(); - // Small hack to link revisions to our test user. -// db_update('node_revision') -// ->fields(array('uid' => $node->uid)) -// ->condition('vid', $node->vid) -// ->execute(); return $node; }