/** * @since 0.4 * @see EntityRevisionLookup::getEntityRevision * * @param EntityId $entityId * @param int|string $revisionId The desired revision id, or LATEST_FROM_SLAVE or LATEST_FROM_MASTER. * * @throws RevisionedUnresolvedRedirectException * @throws StorageException * @return EntityRevision|null */ public function getEntityRevision(EntityId $entityId, $revisionId = self::LATEST_FROM_SLAVE) { wfDebugLog(__CLASS__, __FUNCTION__ . ': Looking up entity ' . $entityId . " (revision {$revisionId})."); // default changed from false to 0 and then to LATEST_FROM_SLAVE if ($revisionId === false || $revisionId === 0) { wfWarn('getEntityRevision() called with $revisionId = false or 0, ' . 'use EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER instead.'); $revisionId = self::LATEST_FROM_SLAVE; } /** @var EntityRevision $entityRevision */ $entityRevision = null; if (is_int($revisionId)) { $row = $this->entityMetaDataAccessor->loadRevisionInformationByRevisionId($entityId, $revisionId); } else { $rows = $this->entityMetaDataAccessor->loadRevisionInformation(array($entityId), $revisionId); $row = $rows[$entityId->getSerialization()]; } if ($row) { /** @var EntityRedirect $redirect */ try { list($entityRevision, $redirect) = $this->loadEntity($row); } catch (MWContentSerializationException $ex) { throw new StorageException('Failed to unserialize the content object.', 0, $ex); } if ($redirect !== null) { throw new RevisionedUnresolvedRedirectException($entityId, $redirect->getTargetId(), (int) $row->rev_id, $row->rev_timestamp); } if ($entityRevision === null) { // This only happens when there is a problem with the external store. wfLogWarning(__METHOD__ . ': Entity not loaded for ' . $entityId); } } if ($entityRevision !== null && !$entityRevision->getEntity()->getId()->equals($entityId)) { // This can happen when giving a revision ID that doesn't belong to the given entity, // or some meta data is incorrect. $actualEntityId = $entityRevision->getEntity()->getId()->getSerialization(); // Get the revision id we actually loaded, if none was passed explicitly $revisionId = is_int($revisionId) ? $revisionId : $entityRevision->getRevisionId(); throw new BadRevisionException("Revision {$revisionId} belongs to {$actualEntityId} instead of expected {$entityId}"); } if (is_int($revisionId) && $entityRevision === null) { // If a revision ID was specified, but that revision doesn't exist: throw new BadRevisionException("No such revision found for {$entityId}: {$revisionId}"); } return $entityRevision; }
/** * @see WikiPageEntityMetaDataAccessor::loadRevisionInformationByRevisionId * * @param EntityId $entityId * @param int $revisionId * * @return object|bool false if no such entity exists */ public function loadRevisionInformationByRevisionId(EntityId $entityId, $revisionId) { // Caching this would have little or no benefit, but would be rather complex. return $this->lookup->loadRevisionInformationByRevisionId($entityId, $revisionId); }