Skip to content

Commit

Permalink
api.delete.pre only needed for site pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley committed Dec 9, 2020
1 parent 9f8c338 commit e156a5b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions application/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
);

$sharedEventManager->attach(
'*',
'Omeka\Api\Adapter\SitePageAdapter',
'api.delete.pre',
[$this, 'deleteFulltextPre']
);
Expand Down Expand Up @@ -525,21 +525,20 @@ public function saveFulltext(ZendEvent $event)
}

/**
* Prepare to delete the fulltext of an API resource.
* Prepare to delete the fulltext of a site page.
*
* The site_pages resource uses a compound ID that cannot be read from the
* database. Here we set the actual entity ID to a request option so
* self::deleteFulltext() can handle it correctly.
*
* @param ZendEvent $event
*/
public function deleteFulltextPre(ZendEvent $event)
{
$request = $event->getParam('request');
if ('site_pages' === $request->getResource()) {
// The site_pages resource uses a compound ID that cannot be read
// from the database. Here we set the actual entity ID to a request
// option so self::deleteFulltext() can handle it correctly.
$em = $this->getServiceLocator()->get('Omeka\EntityManager');
$sitePage = $em->getRepository('Omeka\Entity\SitePage')->findOneBy($request->getId());
$request->setOption('deleted_entity_id', $sitePage->getId());
}
$em = $this->getServiceLocator()->get('Omeka\EntityManager');
$sitePage = $em->getRepository('Omeka\Entity\SitePage')->findOneBy($request->getId());
$request->setOption('deleted_entity_id', $sitePage->getId());
}

/**
Expand Down

0 comments on commit e156a5b

Please sign in to comment.