/** * @see ApiBase::execute * * @since 0.3 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $guid = $params['claim']; $entityId = $this->guidParser->parse($guid)->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $summary = $this->modificationHelper->createSummary($params, $this); $claim = $this->modificationHelper->getStatementFromEntity($guid, $entity); $qualifierHashes = $this->getQualifierHashesFromParams($params, $claim); $changeOps = new ChangeOps(); $changeOps->add($this->getChangeOps($guid, $qualifierHashes)); try { $changeOps->apply($entity, $summary); } catch (ChangeOpException $e) { $this->errorReporter->dieException($e, 'failed-save'); } $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE); $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->resultBuilder->markSuccess(); }
/** * @param Statement $statement * * @return string|null */ private function getEntityType(Statement $statement) { try { $guid = $this->guidParser->parse($statement->getGuid()); } catch (StatementGuidParsingException $ex) { // FIXME: Fail when there is a statement with no GUID? return null; } return $guid->getEntityId()->getEntityType(); }
/** * @see ApiBase::execute * * @since 0.4 */ public function execute() { $params = $this->extractRequestParams(); $claim = $this->getClaimFromParams($params); $guid = $claim->getGuid(); if ($guid === null) { $this->errorReporter->dieError('GUID must be set when setting a claim', 'invalid-claim'); } try { $claimGuid = $this->guidParser->parse($guid); } catch (StatementGuidParsingException $ex) { $this->errorReporter->dieException($ex, 'invalid-claim'); } $entityId = $claimGuid->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $summary = $this->getSummary($params, $claim, $entity); $changeop = $this->statementChangeOpFactory->newSetStatementOp($claim, isset($params['index']) ? $params['index'] : null); $this->modificationHelper->applyChangeOp($changeop, $entity, $summary); $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE); $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->resultBuilder->markSuccess(); $this->resultBuilder->addStatement($claim); }
private function getEntityIdFromStatementGuid($guid) { if ($this->guidValidator->validateFormat($guid) === false) { $this->errorReporter->dieError('Invalid claim guid', 'invalid-guid'); } return $this->guidParser->parse($guid)->getEntityId()->getSerialization(); }
/** * @see ChangeOp::apply * * @param Entity $entity * @param Summary|null $summary * * @throws ChangeOpException */ public function apply(Entity $entity, Summary $summary = null) { if ($this->statement->getGuid() === null) { $this->statement->setGuid($this->guidGenerator->newGuid($entity->getId())); } $guid = $this->guidParser->parse($this->statement->getGuid()); if ($this->guidValidator->validate($guid->getSerialization()) === false) { throw new ChangeOpException("Claim does not have a valid GUID"); } elseif (!$entity->getId()->equals($guid->getEntityId())) { throw new ChangeOpException("Claim GUID invalid for given entity"); } $this->applyClaimToEntity($entity, $summary); }
/** * @see ApiBase::execute * * @since 0.3 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $entityId = $this->guidParser->parse($params['claim'])->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $summary = $this->modificationHelper->createSummary($params, $this); $statement = $this->modificationHelper->getStatementFromEntity($params['claim'], $entity); if (isset($params['snakhash'])) { $this->validateQualifierHash($statement, $params['snakhash']); } $changeOp = $this->getChangeOp(); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE); $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->resultBuilder->markSuccess(); $this->resultBuilder->addStatement($statement); }
/** * @see ApiBase::execute * * @since 0.3 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $this->logFeatureUsage('action=wbsetclaimvalue'); $guid = $params['claim']; $entityId = $this->guidParser->parse($guid)->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $claim = $this->modificationHelper->getStatementFromEntity($guid, $entity); $snak = $this->modificationHelper->getSnakInstance($params, $claim->getMainSnak()->getPropertyId()); $summary = $this->modificationHelper->createSummary($params, $this); $changeOp = $this->statementChangeOpFactory->newSetMainSnakOp($guid, $snak); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE); $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->resultBuilder->markSuccess(); $this->resultBuilder->addStatement($claim); }
/** * @see ChangeOp::apply * * @param EntityDocument $entity * @param Summary|null $summary * * @throws ChangeOpException */ public function apply(EntityDocument $entity, Summary $summary = null) { if (!$entity instanceof StatementListHolder) { throw new InvalidArgumentException('$entity must be a StatementListHolder'); } if ($this->statement->getGuid() === null) { $this->statement->setGuid($this->guidGenerator->newGuid($entity->getId())); } $guid = $this->guidParser->parse($this->statement->getGuid()); if ($this->guidValidator->validate($guid->getSerialization()) === false) { throw new ChangeOpException("Claim does not have a valid GUID"); } elseif (!$entity->getId()->equals($guid->getEntityId())) { throw new ChangeOpException("Claim GUID invalid for given entity"); } $this->applyStatementToEntity($entity, $summary); }
/** * Validates the parameters and returns the EntityId to act upon on success * * @param array $params * * @return EntityId */ private function getEntityId(array $params) { $entityId = null; foreach ($params['claim'] as $guid) { if (!$this->modificationHelper->validateStatementGuid($guid)) { $this->errorReporter->dieError("Invalid claim guid {$guid}", 'invalid-guid'); } if (is_null($entityId)) { $entityId = $this->guidParser->parse($guid)->getEntityId(); } else { if (!$this->guidParser->parse($guid)->getEntityId()->equals($entityId)) { $this->errorReporter->dieError('All claims must belong to the same entity', 'invalid-guid'); } } } if (is_null($entityId)) { $this->errorReporter->dieError('Could not find an entity for the claims', 'invalid-guid'); } return $entityId; }
/** * @see ApiBase::execute * * @since 0.3 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $entityId = $this->guidParser->parse($params['statement'])->getEntityId(); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $summary = $this->modificationHelper->createSummary($params, $this); $claim = $this->modificationHelper->getStatementFromEntity($params['statement'], $entity); if (isset($params['reference'])) { $this->validateReferenceHash($claim, $params['reference']); } if (isset($params['snaks-order'])) { $snaksOrder = $this->getArrayFromParam($params['snaks-order'], 'snaks-order'); } else { $snaksOrder = array(); } $deserializer = $this->deserializerFactory->newSnakListDeserializer(); /** @var SnakList $snakList */ try { $snakList = $deserializer->deserialize($this->getArrayFromParam($params['snaks'], 'snaks')); } catch (DeserializationException $e) { $this->errorReporter->dieError('Failed to get reference from reference Serialization ' . $e->getMessage(), 'snak-instantiation-failure'); } $snakList->orderByProperty($snaksOrder); $newReference = new Reference($snakList); $changeOp = $this->getChangeOp($newReference); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $status = $this->entitySavingHelper->attemptSaveEntity($entity, $summary, EDIT_UPDATE); $this->resultBuilder->addRevisionIdFromStatusToResult($status, 'pageinfo'); $this->resultBuilder->markSuccess(); $this->resultBuilder->addReference($newReference); }