/**
  * @see SpecialSetEntity::setValue()
  *
  * @since 0.4
  *
  * @param Entity $entity
  * @param string $languageCode
  * @param string $value
  *
  * @return Summary
  */
 protected function setValue($entity, $languageCode, $value)
 {
     $summary = new Summary('wbsetaliases');
     if ($value === '') {
         $aliases = $entity->getFingerprint()->getAliasGroup($languageCode)->getAliases();
         $changeOp = $this->termChangeOpFactory->newRemoveAliasesOp($languageCode, $aliases);
     } else {
         $changeOp = $this->termChangeOpFactory->newSetAliasesOp($languageCode, explode('|', $value));
     }
     $this->applyChangeOp($changeOp, $entity, $summary);
     return $summary;
 }
Example #2
0
 /**
  * Validates this ChangeOp
  *
  * @see ChangeOp::validate()
  *
  * @since 0.5
  *
  * @param Entity $entity
  *
  * @return Result
  */
 public function validate(Entity $entity)
 {
     $languageValidator = $this->termValidatorFactory->getLanguageValidator();
     $termValidator = $this->termValidatorFactory->getLabelValidator($entity->getType());
     $fingerprintValidator = $this->termValidatorFactory->getFingerprintValidator($entity->getType());
     // check that the language is valid
     $result = $languageValidator->validate($this->languageCode);
     if ($result->isValid() && $this->label !== null) {
         // Check that the new label is valid
         $result = $termValidator->validate($this->label);
     }
     if (!$result->isValid()) {
         return $result;
     }
     // Check if the new fingerprint of the entity is valid (e.g. if the label is unique)
     $fingerprint = unserialize(serialize($entity->getFingerprint()));
     $this->updateFingerprint($fingerprint);
     $result = $fingerprintValidator->validateFingerprint($fingerprint, $entity->getId(), array($this->languageCode));
     return $result;
 }
 public function detectLabelDescriptionConflictsForEntity(Entity $entity)
 {
     foreach ($entity->getFingerprint()->getLabels()->toTextArray() as $lang => $label) {
         if (!$entity->getFingerprint()->hasDescription($lang)) {
             continue;
         }
         $description = $entity->getFingerprint()->getDescription($lang)->getText();
         if ($label === 'DUPE' && $description === 'DUPE') {
             return Result::newError(array(Error::newError('found conflicting terms', 'label', 'label-with-description-conflict', array('label', $lang, $label, 'Q666'))));
         }
     }
     return Result::newSuccess();
 }
 /**
  * @see ChangeOp::apply()
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     $fingerprint = $entity->getFingerprint();
     $this->updateSummary($summary, $this->action, $this->languageCode, $this->aliases);
     $this->updateFingerprint($fingerprint);
     $entity->setFingerprint($fingerprint);
 }
Example #5
0
 /**
  * @param Entity $entity
  */
 private function buildResult(Entity $entity)
 {
     $builder = $this->getResultBuilder();
     if ($entity instanceof FingerprintProvider) {
         $fingerprint = $entity->getFingerprint();
         $builder->addLabels($fingerprint->getLabels(), 'entity');
         $builder->addDescriptions($fingerprint->getDescriptions(), 'entity');
         $builder->addAliasGroupList($fingerprint->getAliasGroups(), 'entity');
     }
     if ($entity instanceof Item) {
         $builder->addSiteLinkList($entity->getSiteLinkList(), 'entity');
     }
     $builder->addStatements($entity->getClaims(), 'entity');
 }
 /**
  * @see SpecialModifyEntity::modifyEntity
  *
  * @param Entity $entity
  *
  * @return Summary|bool
  */
 protected function modifyEntity(Entity $entity)
 {
     $changeOps = $this->getChangeOps($entity->getFingerprint());
     $summary = false;
     $success = true;
     foreach ($changeOps as $module => $changeOp) {
         $summary = new Summary($module);
         try {
             $this->applyChangeOp($changeOp, $entity, $summary);
         } catch (ChangeOpException $ex) {
             $this->showErrorHTML($ex->getMessage());
             $success = false;
         }
     }
     if (!$success) {
         return false;
     } elseif (count($changeOps) === 1) {
         return $summary;
     }
     return $this->getSummaryForLabelDescriptionAliases();
 }