NodeStorage.php 1.8 KB

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