/** * Returns modification updates for the given EntityContent. * * @see Content::getSecondaryDataUpdates * * @since 0.5 * * @param EntityContent $content * @param Title $title * * @return DataUpdate[] */ public function getEntityModificationUpdates(EntityContent $content, Title $title) { $updates = array(); $entityId = $content->getEntityId(); //FIXME: we should not need this! if ($entityId === null) { $entityId = $this->getIdForTitle($title); } if ($content->isRedirect()) { // Remove the entity from the terms table since it's now a redirect. $updates[] = new DataUpdateAdapter(array($this->termIndex, 'deleteTermsOfEntity'), $entityId); // Register the redirect from the EntityPerPage table. $updates[] = new DataUpdateAdapter(array($this->entityPerPage, 'addRedirectPage'), $entityId, $title->getArticleID(), $content->getEntityRedirect()->getTargetId()); } else { // Register the entity in the EntityPerPage table. $updates[] = new DataUpdateAdapter(array($this->entityPerPage, 'addEntityPage'), $entityId, $title->getArticleID()); // Register the entity in the terms table. $updates[] = new DataUpdateAdapter(array($this->termIndex, 'saveTermsOfEntity'), $content->getEntity()); } // Call the WikibaseEntityModificationUpdate hook. // Do this after doing all well-known updates. $updates[] = new DataUpdateAdapter('wfRunHooks', 'WikibaseEntityModificationUpdate', array($content, $title)); return $updates; }
/** * Returns a diff between this EntityContent and the given EntityContent. * * @param EntityContent $toContent * * @return EntityContentDiff */ public function getDiff(EntityContent $toContent) { $fromContent = $this; $differ = new MapDiffer(); $redirectDiffOps = $differ->doDiff($fromContent->getRedirectData(), $toContent->getRedirectData()); $redirectDiff = new Diff($redirectDiffOps, true); $fromEntity = $fromContent->isRedirect() ? $this->makeEmptyEntity() : $fromContent->getEntity(); $toEntity = $toContent->isRedirect() ? $this->makeEmptyEntity() : $toContent->getEntity(); $entityDiffer = new EntityDiffer(); $entityDiff = $entityDiffer->diffEntities($fromEntity, $toEntity); return new EntityContentDiff($entityDiff, $redirectDiff); }
/** * Returns a EntityChange based on the old and new content object, taking * redirects into consideration. * * @todo: Notify the client about changes to redirects explicitly. * * @param EntityContent $oldContent * @param EntityContent $newContent * * @return EntityChange|null */ private function getChangeForModification(EntityContent $oldContent, EntityContent $newContent) { $oldEntity = $oldContent->isRedirect() ? null : $oldContent->getEntity(); $newEntity = $newContent->isRedirect() ? null : $newContent->getEntity(); if ($oldEntity === null && $newEntity === null) { // Old and new versions are redirects. Nothing to do. return null; } elseif ($newEntity === null) { // The new version is a redirect. For now, treat that as a deletion. $action = EntityChange::REMOVE; } elseif ($oldEntity === null) { // The old version is a redirect. For now, treat that like restoring the entity. $action = EntityChange::RESTORE; } else { // No redirects involved $action = EntityChange::UPDATE; } $change = $this->changeFactory->newFromUpdate($action, $oldEntity, $newEntity); return $change; }
/** * Returns modification updates for the given EntityContent. * * @see EntityHandler::getEntityModificationUpdates * * @since 0.5 * * @param EntityContent $content * @param Title $title * * @return DataUpdate[] */ public function getEntityModificationUpdates(EntityContent $content, Title $title) { $updates = array(); if ($content->isRedirect()) { $updates[] = new DataUpdateAdapter(array($this->siteLinkStore, 'deleteLinksOfItem'), $content->getEntityId()); } else { $updates[] = new DataUpdateAdapter(array($this->siteLinkStore, 'saveLinksOfItem'), $content->getEntity()); } return array_merge($updates, parent::getEntityModificationUpdates($content, $title)); }