comparison core/modules/node/src/NodeStorage.php @ 0:4c8ae668cc8c

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