示例#1
0
 /**
  * @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->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->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->saveChanges($entity, $summary);
     $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->getResultBuilder()->markSuccess();
     $this->getResultBuilder()->addStatement($claim);
 }
 /**
  * @param array[] $statements array of serialized statements
  *
  * @return ChangeOp[]
  */
 private function getModifyStatementChangeOps(array $statements)
 {
     $opsToReturn = array();
     foreach ($statements as $statementArray) {
         if (!array_key_exists('remove', $statementArray)) {
             try {
                 $statement = $this->statementDeserializer->deserialize($statementArray);
                 if (!$statement instanceof Statement) {
                     throw new IllegalValueException('Statement serialization did not contained a Statement.');
                 }
                 $opsToReturn[] = $this->statementChangeOpFactory->newSetStatementOp($statement);
             } catch (IllegalValueException $ex) {
                 $this->errorReporter->dieException($ex, 'invalid-claim');
             } catch (MWException $ex) {
                 $this->errorReporter->dieException($ex, 'invalid-claim');
             }
         }
     }
     return $opsToReturn;
 }