/**
  * @dataProvider provideGetEntityId
  */
 public function testGetEntityId(EntityContent $content, $expected)
 {
     $actual = $content->getEntityId();
     $this->assertEquals($expected, $actual);
 }
 /**
  * Saves the entity. If the corresponding page does not exist yet, it will be created
  * (ie a new ID will be determined and a new page in the data NS created).
  *
  * @note: this method should not be overloaded, and should not be extended to save additional
  *        information to the database. Such things should be done in a way that will also be
  *        triggered when the save is performed by calling WikiPage::doEditContent.
  *
  * @see WikiPage::doEditContent
  *
  * @param EntityContent $entityContent the entity to save.
  * @param string $summary
  * @param null|User $user
  * @param int $flags Flags as used by WikiPage::doEditContent, use EDIT_XXX constants.
  * @param int|bool $baseRevId
  *
  * @throws StorageException
  * @return Revision The new revision (or the latest one, in case of a null edit).
  */
 private function saveEntityContent(EntityContent $entityContent, $summary = '', User $user = null, $flags = 0, $baseRevId = false)
 {
     $page = $this->getWikiPageForEntity($entityContent->getEntityId());
     if (($flags & EDIT_NEW) === EDIT_NEW) {
         $title = $page->getTitle();
         if ($title->exists()) {
             throw new StorageException(Status::newFatal('edit-already-exists'));
         }
     }
     /**
      * @note Make sure we start saving from a clean slate. Calling WikiPage::clearPreparedEdit
      * may cause the old content to be loaded from the database again. This may be necessary,
      * because EntityContent is mutable, so the cached object might have changed.
      *
      * @todo Might be able to further optimize handling of prepared edit in WikiPage.
      */
     $page->clear();
     $page->clearPreparedEdit();
     $status = $page->doEditContent($entityContent, $summary, $flags | EDIT_AUTOSUMMARY, $baseRevId, $user);
     if (!$status->isOK()) {
         throw new StorageException($status);
     }
     // As per convention defined by WikiPage, the new revision is in the status value:
     if (isset($status->value['revision'])) {
         $revision = $status->value['revision'];
     } else {
         // NOTE: No new revision was created (content didn't change). Report the old one.
         // There *might* be a race condition here, but since $page already loaded the
         // latest revision, it should still be cached, and should always be the correct one.
         $revision = $page->getRevision();
     }
     return $revision;
 }
 /**
  * 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 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));
 }