Ejemplo n.º 1
0
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $entityId = $this->getEntityId($params);
     if (isset($params['baserevid'])) {
         $entityRevision = $this->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->loadEntityRevision($entityId);
     }
     $entity = $entityRevision->getEntity();
     if ($entity instanceof StatementListProvider) {
         $this->assertStatementListContainsGuids($entity->getStatements(), $params['claim']);
     }
     $summary = $this->modificationHelper->createSummary($params, $this);
     $changeOps = new ChangeOps();
     $changeOps->add($this->getChangeOps($params));
     try {
         $changeOps->apply($entity, $summary);
     } catch (ChangeOpException $e) {
         $this->errorReporter->dieException($e, 'failed-save');
     }
     $status = $this->saveChanges($entity, $summary);
     $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->getResultBuilder()->markSuccess();
     $this->getResultBuilder()->setList(null, 'claims', $params['claim'], 'claim');
 }
Ejemplo n.º 2
0
 /**
  * @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->loadEntityRevision($entityId, (int) $params['baserevid']);
     } else {
         $entityRevision = $this->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->saveChanges($entity, $summary);
     $this->getResultBuilder()->addRevisionIdFromStatusToResult($status, 'pageinfo');
     $this->getResultBuilder()->markSuccess();
 }
Ejemplo n.º 3
0
 public function apply()
 {
     // NOTE: we don't want to validate the ChangeOps individually, since they represent
     // data already present and saved on the system. Also, validating each would be
     // potentially expensive.
     $this->generateChangeOps();
     $this->fromChangeOps->apply($this->fromItem);
     $this->toChangeOps->apply($this->toItem);
     //NOTE: we apply constraint checks on the modified items, but no
     //      validation of individual change ops, since we are merging
     //      two valid items.
     $this->applyConstraintChecks($this->toItem, $this->fromItem->getId());
 }
 /**
  * @see ApiBase::execute
  *
  * @since 0.3
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     $guid = $params['statement'];
     $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);
     if (!$claim instanceof Statement) {
         $this->errorReporter->dieError('The referenced claim is not a statement and thus cannot have references', 'not-statement');
     }
     $referenceHashes = $this->getReferenceHashesFromParams($params, $claim);
     $changeOps = new ChangeOps();
     $changeOps->add($this->getChangeOps($guid, $referenceHashes));
     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();
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider changeOpsProvider
  */
 public function testApply(ChangeOps $changeOps, $language, $expectedLabel, $expectedDescription)
 {
     $entity = new Item();
     $changeOps->apply($entity);
     $this->assertEquals($expectedLabel, $entity->getFingerprint()->getLabel($language)->getText());
     $this->assertEquals($expectedDescription, $entity->getFingerprint()->getDescription($language)->getText());
 }