/**
  * @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));
 }
 /**
  * @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);
 }
 private function createEntity(Entity $entity)
 {
     $entity->setId(null);
     $entity->setStatements(new StatementList());
     if ($entity instanceof Item) {
         $siteLinkList = $this->badgeItemUpdater->replaceBadges($entity->getSiteLinkList());
         $entity->setSiteLinkList($siteLinkList);
     }
     return $this->entityStore->saveEntity($entity, 'Import entity', $this->importUser, EDIT_NEW);
 }
 /**
  * @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));
 }