/** * @see ApiBase::execute * * @since 0.2 */ public function execute() { $params = $this->extractRequestParams(); $this->validateParameters($params); $entityId = $this->modificationHelper->getEntityIdFromString($params['entity']); if (isset($params['baserevid'])) { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId, (int) $params['baserevid']); } else { $entityRevision = $this->entityLoadingHelper->loadEntityRevision($entityId); } $entity = $entityRevision->getEntity(); $propertyId = $this->modificationHelper->getEntityIdFromString($params['property']); if (!$propertyId instanceof PropertyId) { $this->errorReporter->dieError($propertyId->getSerialization() . ' does not appear to be a property ID', 'param-illegal'); } $snak = $this->modificationHelper->getSnakInstance($params, $propertyId); $summary = $this->modificationHelper->createSummary($params, $this); /* @var ChangeOpMainSnak $changeOp */ $changeOp = $this->statementChangeOpFactory->newSetMainSnakOp('', $snak); $this->modificationHelper->applyChangeOp($changeOp, $entity, $summary); $statement = $entity->getStatements()->getFirstStatementWithGuid($changeOp->getStatementGuid()); $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.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); }
/** * @return ChangeOpQualifier */ private function getChangeOp() { $params = $this->extractRequestParams(); $guid = $params['claim']; $propertyId = $this->modificationHelper->getEntityIdFromString($params['property']); if (!$propertyId instanceof PropertyId) { $this->errorReporter->dieError($propertyId->getSerialization() . ' does not appear to be a property ID', 'param-illegal'); } $newQualifier = $this->modificationHelper->getSnakInstance($params, $propertyId); $snakHash = isset($params['snakhash']) ? $params['snakhash'] : ''; $changeOp = $this->statementChangeOpFactory->newSetQualifierOp($guid, $newQualifier, $snakHash); return $changeOp; }
/** * 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; }
/** * @param array $params */ private function validateParameters(array $params) { if (!$this->modificationHelper->validateStatementGuid($params['claim'])) { $this->errorReporter->dieError('Invalid claim guid', 'invalid-guid'); } }