Mercurial > hg > cmmr2012-drupal-site
diff core/modules/comment/src/CommentStatistics.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
line wrap: on
line diff
--- a/core/modules/comment/src/CommentStatistics.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/comment/src/CommentStatistics.php Thu May 09 15:34:47 2019 +0100 @@ -3,15 +3,22 @@ namespace Drupal\comment; use Drupal\Core\Database\Connection; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\user\EntityOwnerInterface; class CommentStatistics implements CommentStatisticsInterface { + use DeprecatedServicePropertyTrait; + + /** + * {@inheritdoc} + */ + protected $deprecatedProperties = ['entityManager' => 'entity.manager']; /** * The current database connection. @@ -21,6 +28,13 @@ protected $database; /** + * The replica database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $databaseReplica; + + /** * The current logged in user. * * @var \Drupal\Core\Session\AccountInterface @@ -28,11 +42,11 @@ protected $currentUser; /** - * The entity manager service. + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * The state service. @@ -48,15 +62,18 @@ * The active database connection. * @param \Drupal\Core\Session\AccountInterface $current_user * The current logged in user. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. * @param \Drupal\Core\State\StateInterface $state * The state service. + * @param \Drupal\Core\Database\Connection|null $database_replica + * (Optional) the replica database connection. */ - public function __construct(Connection $database, AccountInterface $current_user, EntityManagerInterface $entity_manager, StateInterface $state) { + public function __construct(Connection $database, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, StateInterface $state, Connection $database_replica = NULL) { $this->database = $database; + $this->databaseReplica = $database_replica ?: $database; $this->currentUser = $current_user; - $this->entityManager = $entity_manager; + $this->entityTypeManager = $entity_type_manager; $this->state = $state; } @@ -64,8 +81,8 @@ * {@inheritdoc} */ public function read($entities, $entity_type, $accurate = TRUE) { - $options = $accurate ? [] : ['target' => 'replica']; - $stats = $this->database->select('comment_entity_statistics', 'ces', $options) + $connection = $accurate ? $this->database : $this->databaseReplica; + $stats = $connection->select('comment_entity_statistics', 'ces') ->fields('ces') ->condition('ces.entity_id', array_keys($entities), 'IN') ->condition('ces.entity_type', $entity_type) @@ -254,7 +271,7 @@ // Reset the cache of the commented entity so that when the entity is loaded // the next time, the statistics will be loaded again. - $this->entityManager->getStorage($comment->getCommentedEntityTypeId())->resetCache([$comment->getCommentedEntityId()]); + $this->entityTypeManager->getStorage($comment->getCommentedEntityTypeId())->resetCache([$comment->getCommentedEntityId()]); } }