/** * @see EntityLookup::hasEntity * * @param EntityId $entityId * * @throws EntityLookupException * @return bool */ public function hasEntity(EntityId $entityId) { try { return $this->lookup->getLatestRevisionId($entityId) !== false; } catch (EntityLookupException $ex) { throw $ex; } catch (\Exception $ex) { // TODO: catch more specific exception once EntityRevisionLookup contract gets clarified throw new EntityLookupException($entityId, null, $ex); } }
/** * @see ModifyEntity::modifyEntity */ protected function modifyEntity(EntityDocument &$entity, array $params, $baseRevId) { $this->validateDataParameter($params); $data = json_decode($params['data'], true); $this->validateDataProperties($data, $entity, $baseRevId); $exists = $this->entityExists($entity->getId()); if ($params['clear']) { if ($params['baserevid'] && $exists) { $latestRevision = $this->revisionLookup->getLatestRevisionId($entity->getId(), EntityRevisionLookup::LATEST_FROM_MASTER); if (!$baseRevId === $latestRevision) { $this->errorReporter->dieError('Tried to clear entity using baserevid of entity not equal to current revision', 'editconflict'); } } $entity = $this->clearEntity($entity); } // if we create a new property, make sure we set the datatype if (!$exists && $entity instanceof Property) { if (!isset($data['datatype'])) { $this->errorReporter->dieError('No datatype given', 'param-illegal'); } else { $entity->setDataTypeId($data['datatype']); } } $changeOps = $this->getChangeOps($data, $entity); $this->applyChangeOp($changeOps, $entity); $this->buildResult($entity); return $this->getSummary($params); }
/** * Returns the latest revision ID. * * @return int 0 if the entity doesn't exist */ private function getLatestRevisionId() { // Don't do negative caching: We call this to see whether the entity yet exists // before creating. if ($this->latestRevId === 0) { $id = $this->newEntity->getId(); if ($this->latestRev !== null) { $this->latestRevId = $this->latestRev->getRevisionId(); } elseif ($id !== null) { $this->latestRevId = (int) $this->entityRevisionLookup->getLatestRevisionId($id, EntityRevisionLookup::LATEST_FROM_MASTER); } } return $this->latestRevId; }
/** * @see EntityRevisionLookup::getLatestRevisionId * * @note: If this lookup is configured to verify revisions, this just delegates * to the underlying lookup. Otherwise, it may return the ID of a cached * revision. * * @param EntityId $entityId * @param string $mode * * @return int|false */ public function getLatestRevisionId(EntityId $entityId, $mode = self::LATEST_FROM_SLAVE) { // If we do not need to verify the revision, and the revision isn't // needed for an update, we can get the revision from the cached object. // XXX: whether this is actually quicker depends on the cache. if (!($this->shouldVerifyRevision || $mode === self::LATEST_FROM_MASTER)) { $key = $this->getCacheKey($entityId); /** @var EntityRevision $entityRevision */ $entityRevision = $this->cache->get($key); if ($entityRevision) { return $entityRevision->getRevisionId(); } } return $this->lookup->getLatestRevisionId($entityId, $mode); }