/**
  * @see ChangeOp::apply()
  * - a new claim with $snak as mainsnak gets added when $claimGuid is empty and $snak is set
  * - the claim's mainsnak gets set to $snak when $claimGuid and $snak are set
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $entity->getStatements();
     if (empty($this->statementGuid)) {
         $this->addStatement($statements, $entity->getId(), $summary);
     } else {
         $this->setStatement($statements, $summary);
     }
     $entity->setStatements($statements);
 }
 /**
  * @see ChangeOp::apply()
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $entity->getStatements();
     $statement = $statements->getFirstStatementWithGuid($this->statementGuid);
     if ($statement === null) {
         throw new ChangeOpException("Entity does not have a statement with GUID {$this->statementGuid}");
     }
     $qualifiers = $statement->getQualifiers();
     $this->removeQualifier($qualifiers, $summary);
     $statement->setQualifiers($qualifiers);
     $entity->setStatements($statements);
 }
 /**
  * @see ChangeOp::apply
  *
  * @param Entity $entity
  * @param Summary|null $summary
  *
  * @throws InvalidArgumentException
  * @throws ChangeOpException
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $entity->getStatements();
     $statement = $statements->getFirstStatementWithGuid($this->guid);
     if ($statement === null) {
         throw new ChangeOpException("Entity does not have statement with GUID {$this->guid}");
     }
     $statements->removeStatementsWithGuid($this->guid);
     $entity->setStatements($statements);
     $removedSnak = $statement->getMainSnak();
     $this->updateSummary($summary, 'remove', '', $this->getSummaryArgs($removedSnak));
 }
 public function importStatements(Entity $entity)
 {
     $statements = $entity->getStatements();
     $this->logger->info('Adding statements: ' . $entity->getId()->getSerialization());
     if (!$statements->isEmpty()) {
         $localId = $this->entityMappingStore->getLocalId($entity->getId()->getSerialization());
         if (!$localId) {
             $this->logger->error($entity->getId()->getSerialization() . ' not found');
         }
         try {
             $this->addStatementList($this->idParser->parse($localId), $statements);
         } catch (\Exception $ex) {
             $this->logger->error($ex->getMessage());
         }
     }
 }
 /**
  * @see ChangeOp::apply()
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $entity->getStatements();
     $statement = $statements->getFirstStatementWithGuid($this->statementGuid);
     if ($statement === null) {
         throw new ChangeOpException("Entity does not have claim with GUID {$this->statementGuid}");
     }
     $references = $statement->getReferences();
     $this->removeReference($references, $summary);
     if ($summary !== null) {
         $summary->addAutoSummaryArgs($this->getSnakSummaryArgs($statement->getMainSnak()));
     }
     $statement->setReferences($references);
     $entity->setStatements($statements);
 }
 /**
  * @see ChangeOp::apply()
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $entity->getStatements();
     $statement = $statements->getFirstStatementWithGuid($this->statementGuid);
     if ($statement === null) {
         throw new ChangeOpException("Entity does not have a statement with GUID {$this->statementGuid}");
     }
     $oldRank = $statement->getRank();
     $statement->setRank($this->rank);
     $this->updateSummary($summary, null, '', $this->getSnakSummaryArgs($statement->getMainSnak()));
     if ($summary !== null) {
         $statementRankSerializer = new StatementRankSerializer();
         $summary->addAutoCommentArgs(array($statementRankSerializer->serialize($oldRank), $statementRankSerializer->serialize($this->rank)));
     }
     $entity->setStatements($statements);
 }
Example #7
0
 /**
  * @param array $params
  * @param Statement $statement
  * @param Entity $entity
  *
  * @throws InvalidArgumentException
  * @return Summary
  *
  * @todo this summary builder is ugly and summary stuff needs to be refactored
  */
 private function getSummary(array $params, Statement $statement, Entity $entity)
 {
     if (!$entity instanceof StatementListProvider) {
         throw new InvalidArgumentException('$entity must be a StatementListProvider');
     }
     $claimSummaryBuilder = new ClaimSummaryBuilder($this->getModuleName(), new ClaimDiffer(new OrderedListDiffer(new ComparableComparer())));
     $summary = $claimSummaryBuilder->buildClaimSummary($entity->getStatements()->getFirstStatementWithGuid($statement->getGuid()), $statement);
     if (isset($params['summary'])) {
         $summary->setUserSummary($params['summary']);
     }
     return $summary;
 }
 private function getReferencedEntities(Entity $entity)
 {
     $snaks = $entity->getStatements()->getAllSnaks();
     $entities = array();
     foreach ($snaks as $snak) {
         $entities[] = $snak->getPropertyId()->getSerialization();
         if ($snak instanceof PropertyValueSnak) {
             $value = $snak->getDataValue();
             if ($value instanceof EntityIdValue) {
                 $entities[] = $value->getEntityId()->getSerialization();
             }
         }
     }
     return array_unique($entities);
 }
 /**
  * @param Entity $entity
  * @param Summary|null $summary
  *
  * @throws InvalidArgumentException
  */
 private function applyClaimToEntity(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof StatementListHolder) {
         throw new InvalidArgumentException('$entity must be a StatementListHolder');
     }
     $statements = $this->removeStatement($entity->getStatements()->toArray(), $summary);
     $statements = $this->addStatement($statements);
     $entity->setStatements(new StatementList($statements));
 }