Ejemplo n.º 1
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');
 }
Ejemplo n.º 2
0
 /**
  * @see ChangeOp::apply
  */
 public function apply(Entity $entity, Summary $summary = null)
 {
     if (!$entity instanceof Item) {
         throw new InvalidArgumentException('ChangeOpSiteLink can only be applied to Item instances');
     }
     $siteLinks = $entity->getSiteLinkList();
     if ($this->pageName === null && $this->badges === null || $this->pageName === '') {
         if ($siteLinks->hasLinkWithSiteId($this->siteId)) {
             $this->updateSummary($summary, 'remove', $this->siteId, $siteLinks->getBySiteId($this->siteId)->getPageName());
             $siteLinks->removeLinkWithSiteId($this->siteId);
         } else {
             //TODO: throw error, or ignore silently?
         }
     } else {
         $commentArgs = array();
         if ($this->pageName === null) {
             if (!$siteLinks->hasLinkWithSiteId($this->siteId)) {
                 throw new InvalidArgumentException('The sitelink does not exist');
             }
             // If page name is not set (but badges are) make sure that it remains intact
             $pageName = $siteLinks->getBySiteId($this->siteId)->getPageName();
         } else {
             $pageName = $this->pageName;
             $commentArgs[] = $pageName;
         }
         $action = $siteLinks->hasLinkWithSiteId($this->siteId) ? 'set' : 'add';
         $badges = $this->applyBadges($siteLinks, $action, $commentArgs);
         $this->updateSummary($summary, $action, $this->siteId, $commentArgs);
         // FIXME: Use SiteLinkList::setNewSiteLink.
         $siteLinks->removeLinkWithSiteId($this->siteId);
         $siteLinks->addNewSiteLink($this->siteId, $pageName, $badges);
     }
 }
Ejemplo n.º 3
0
 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);
 }