Skip to content

Commit

Permalink
Skip "shift up children" if deleting whole exhibit
Browse files Browse the repository at this point in the history
Fixes a bug where an exhibit is undeletable if slugs conflict somewhere
(and also avoids some pointless DB churn).
  • Loading branch information
zerocrates committed Aug 25, 2015
1 parent aaddffa commit 6072811
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/Exhibit.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected function _delete()
//get all the pages and delete them
$pages = $this->getTable('ExhibitPage')->findBy(array('exhibit'=>$this->id));
foreach($pages as $page) {
$page->setFixChildrenOnDelete(false);
$page->delete();
}
$this->deleteTaggings();
Expand Down
21 changes: 21 additions & 0 deletions models/ExhibitPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class ExhibitPage extends Omeka_Record_AbstractRecord
*/
protected $_related = array('ExhibitPageBlocks' => 'getPageBlocks');

/**
* Whether to automatically shift the page's children up a level when the page is deleted.
*
* @var boolean
*/
private $_fixChildrenOnDelete = true;

/**
* Define mixins.
*
Expand Down Expand Up @@ -272,6 +279,10 @@ protected function _delete()
}
}

if (!$this->_fixChildrenOnDelete) {
return;
}

//bump all child pages up to being children of the parent
$childPages = $this->getChildPages();
foreach($childPages as $child) {
Expand Down Expand Up @@ -347,4 +358,14 @@ public function getRecordUrl($action = 'show')
return array('module' => 'exhibit-builder', 'controller' => 'exhibits',
'action' => $action, 'id' => $this->id);
}

/**
* Set whether to automatically shift the page's children up a level when the page is deleted.
*
* @param boolean $fix
*/
public function setFixChildrenOnDelete($fix)
{
$this->_fixChildrenOnDelete = (bool) $fix;
}
}

0 comments on commit 6072811

Please sign in to comment.