Exemplo n.º 1
0
 /**
  * @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->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->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->saveChanges($entity, $summary);
     $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->getResultBuilder()->markSuccess();
     $this->getResultBuilder()->addStatement($statement);
 }
Exemplo n.º 2
0
 /**
  * @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->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->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->saveChanges($entity, $summary);
     $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->getResultBuilder()->markSuccess();
     $this->getResultBuilder()->addStatement($claim);
 }