Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\node;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
Chris@0
|
6 use Drupal\Core\Session\AccountInterface;
|
Chris@0
|
7 use Drupal\Core\Language\LanguageInterface;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Defines the storage handler class for nodes.
|
Chris@0
|
11 *
|
Chris@0
|
12 * This extends the base storage class, adding required special handling for
|
Chris@0
|
13 * node entities.
|
Chris@0
|
14 */
|
Chris@0
|
15 class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterface {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * {@inheritdoc}
|
Chris@0
|
19 */
|
Chris@0
|
20 public function revisionIds(NodeInterface $node) {
|
Chris@0
|
21 return $this->database->query(
|
Chris@17
|
22 'SELECT vid FROM {' . $this->getRevisionTable() . '} WHERE nid=:nid ORDER BY vid',
|
Chris@0
|
23 [':nid' => $node->id()]
|
Chris@0
|
24 )->fetchCol();
|
Chris@0
|
25 }
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * {@inheritdoc}
|
Chris@0
|
29 */
|
Chris@0
|
30 public function userRevisionIds(AccountInterface $account) {
|
Chris@0
|
31 return $this->database->query(
|
Chris@17
|
32 'SELECT vid FROM {' . $this->getRevisionDataTable() . '} WHERE uid = :uid ORDER BY vid',
|
Chris@0
|
33 [':uid' => $account->id()]
|
Chris@0
|
34 )->fetchCol();
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * {@inheritdoc}
|
Chris@0
|
39 */
|
Chris@0
|
40 public function countDefaultLanguageRevisions(NodeInterface $node) {
|
Chris@17
|
41 return $this->database->query('SELECT COUNT(*) FROM {' . $this->getRevisionDataTable() . '} WHERE nid = :nid AND default_langcode = 1', [':nid' => $node->id()])->fetchField();
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * {@inheritdoc}
|
Chris@0
|
46 */
|
Chris@0
|
47 public function updateType($old_type, $new_type) {
|
Chris@17
|
48 return $this->database->update($this->getBaseTable())
|
Chris@0
|
49 ->fields(['type' => $new_type])
|
Chris@0
|
50 ->condition('type', $old_type)
|
Chris@0
|
51 ->execute();
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * {@inheritdoc}
|
Chris@0
|
56 */
|
Chris@0
|
57 public function clearRevisionsLanguage(LanguageInterface $language) {
|
Chris@17
|
58 return $this->database->update($this->getRevisionTable())
|
Chris@0
|
59 ->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
Chris@0
|
60 ->condition('langcode', $language->getId())
|
Chris@0
|
61 ->execute();
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 }
|