RevisionStoreFactory.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * Attribution notice: when this file was created, much of its content was taken
  19. * from the Revision.php file as present in release 1.30. Refer to the history
  20. * of that file for original authorship.
  21. *
  22. * @file
  23. */
  24. namespace MediaWiki\Revision;
  25. use ActorMigration;
  26. use CommentStore;
  27. use Psr\Log\LoggerInterface;
  28. use MediaWiki\Storage\BlobStoreFactory;
  29. use MediaWiki\Storage\NameTableStoreFactory;
  30. use WANObjectCache;
  31. use Wikimedia\Assert\Assert;
  32. use Wikimedia\Rdbms\ILBFactory;
  33. /**
  34. * Factory service for RevisionStore instances. This allows RevisionStores to be created for
  35. * cross-wiki access.
  36. *
  37. * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
  38. * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
  39. * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
  40. * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
  41. * the old schema or b) there are no wikis that read only the new schema.
  42. *
  43. * @since 1.32
  44. */
  45. class RevisionStoreFactory {
  46. /** @var BlobStoreFactory */
  47. private $blobStoreFactory;
  48. /** @var ILBFactory */
  49. private $dbLoadBalancerFactory;
  50. /** @var WANObjectCache */
  51. private $cache;
  52. /** @var LoggerInterface */
  53. private $logger;
  54. /** @var CommentStore */
  55. private $commentStore;
  56. /** @var ActorMigration */
  57. private $actorMigration;
  58. /** @var int One of the MIGRATION_* constants */
  59. private $mcrMigrationStage;
  60. /**
  61. * @var bool
  62. * @see $wgContentHandlerUseDB
  63. */
  64. private $contentHandlerUseDB;
  65. /** @var NameTableStoreFactory */
  66. private $nameTables;
  67. /** @var SlotRoleRegistry */
  68. private $slotRoleRegistry;
  69. /**
  70. * @param ILBFactory $dbLoadBalancerFactory
  71. * @param BlobStoreFactory $blobStoreFactory
  72. * @param NameTableStoreFactory $nameTables
  73. * @param SlotRoleRegistry $slotRoleRegistry
  74. * @param WANObjectCache $cache
  75. * @param CommentStore $commentStore
  76. * @param ActorMigration $actorMigration
  77. * @param int $migrationStage
  78. * @param LoggerInterface $logger
  79. * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
  80. * for all wikis in the cluster. Will go away after MCR migration.
  81. */
  82. public function __construct(
  83. ILBFactory $dbLoadBalancerFactory,
  84. BlobStoreFactory $blobStoreFactory,
  85. NameTableStoreFactory $nameTables,
  86. SlotRoleRegistry $slotRoleRegistry,
  87. WANObjectCache $cache,
  88. CommentStore $commentStore,
  89. ActorMigration $actorMigration,
  90. $migrationStage,
  91. LoggerInterface $logger,
  92. $contentHandlerUseDB
  93. ) {
  94. Assert::parameterType( 'integer', $migrationStage, '$migrationStage' );
  95. $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
  96. $this->blobStoreFactory = $blobStoreFactory;
  97. $this->slotRoleRegistry = $slotRoleRegistry;
  98. $this->nameTables = $nameTables;
  99. $this->cache = $cache;
  100. $this->commentStore = $commentStore;
  101. $this->actorMigration = $actorMigration;
  102. $this->mcrMigrationStage = $migrationStage;
  103. $this->logger = $logger;
  104. $this->contentHandlerUseDB = $contentHandlerUseDB;
  105. }
  106. /**
  107. * @since 1.32
  108. *
  109. * @param bool|string $dbDomain DB domain of the relevant wiki or false for the current one
  110. *
  111. * @return RevisionStore for the given wikiId with all necessary services
  112. */
  113. public function getRevisionStore( $dbDomain = false ) {
  114. Assert::parameterType( 'string|boolean', $dbDomain, '$dbDomain' );
  115. $store = new RevisionStore(
  116. $this->dbLoadBalancerFactory->getMainLB( $dbDomain ),
  117. // @phan-suppress-next-line PhanAccessMethodInternal
  118. $this->blobStoreFactory->newSqlBlobStore( $dbDomain ),
  119. $this->cache, // Pass local cache instance; Leave cache sharing to RevisionStore.
  120. $this->commentStore,
  121. $this->nameTables->getContentModels( $dbDomain ),
  122. $this->nameTables->getSlotRoles( $dbDomain ),
  123. $this->slotRoleRegistry,
  124. $this->mcrMigrationStage,
  125. $this->actorMigration,
  126. $dbDomain
  127. );
  128. $store->setLogger( $this->logger );
  129. $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
  130. return $store;
  131. }
  132. }