Merge pull request #1056 from stojg/issue/cms-1049

BUG: Delete parent page, child pages cannot be found anymore
This commit is contained in:
Damian Mooyman 2014-07-25 17:26:52 +12:00
commit 4967d3dbf6
3 changed files with 53 additions and 22 deletions

View File

@ -35,7 +35,12 @@ abstract class CMSSiteTreeFilter extends Object {
* @var String * @var String
*/ */
protected $childrenMethod = null; protected $childrenMethod = null;
/**
* @var string
*/
protected $numChildrenMethod = 'numChildren';
/** /**
* Returns a sorted array of all implementators of CMSSiteTreeFilter, suitable for use in a dropdown. * Returns a sorted array of all implementators of CMSSiteTreeFilter, suitable for use in a dropdown.
* *
@ -71,13 +76,21 @@ abstract class CMSSiteTreeFilter extends Object {
} }
/** /**
* @return String Method on {@link Hierarchy} objects * Method on {@link Hierarchy} objects which is used to traverse into children relationships.
* which is used to traverse into children relationships. *
* @return String
*/ */
public function getChildrenMethod() { public function getChildrenMethod() {
return $this->childrenMethod; return $this->childrenMethod;
} }
/**
* Method on {@link Hierarchy} objects which is used find the number of children for a parent page
*/
public function getNumChildrenMethod() {
return $this->numChildrenMethod;
}
/** /**
* @return Array Map of Page IDs to their respective ParentID values. * @return Array Map of Page IDs to their respective ParentID values.
*/ */
@ -101,17 +114,13 @@ abstract class CMSSiteTreeFilter extends Object {
} }
while(!empty($parents)) { while(!empty($parents)) {
$q = new SQLQuery(); $q = Versioned::get_including_deleted('SiteTree', '"RecordID" in ('.implode(',',array_keys($parents)).')');
$q->setSelect(array('"ID"','"ParentID"')) $list = $q->map('ID', 'ParentID');
->setFrom('"SiteTree"')
->setWhere('"ID" in ('.implode(',',array_keys($parents)).')');
$parents = array(); $parents = array();
foreach($list as $id => $parentID) {
foreach($q->execute() as $row) { if ($parentID) $parents[$parentID] = true;
if ($row['ParentID']) $parents[$row['ParentID']] = true; $this->_cache_ids[$id] = true;
$this->_cache_ids[$row['ID']] = true; $this->_cache_expanded[$id] = true;
$this->_cache_expanded[$row['ID']] = true;
} }
} }
} }
@ -202,8 +211,16 @@ abstract class CMSSiteTreeFilter extends Object {
* @subpackage content * @subpackage content
*/ */
class CMSSiteTreeFilter_DeletedPages extends CMSSiteTreeFilter { class CMSSiteTreeFilter_DeletedPages extends CMSSiteTreeFilter {
/**
* @var string
*/
protected $childrenMethod = "AllHistoricalChildren"; protected $childrenMethod = "AllHistoricalChildren";
/**
* @var string
*/
protected $numChildrenMethod = 'numHistoricalChildren';
static public function title() { static public function title() {
return _t('CMSSiteTreeFilter_DeletedPages.Title', "All pages, including deleted"); return _t('CMSSiteTreeFilter_DeletedPages.Title', "All pages, including deleted");
@ -302,8 +319,16 @@ class CMSSiteTreeFilter_StatusDraftPages extends CMSSiteTreeFilter {
* @subpackage content * @subpackage content
*/ */
class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter { class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter {
protected $childrenMethod = "AllHistoricalChildren"; /**
* @var string
*/
protected $childrenMethod = "AllHistoricalChildren";
/**
* @var string
*/
protected $numChildrenMethod = 'numHistoricalChildren';
static public function title() { static public function title() {
return _t('CMSSiteTreeFilter_StatusDeletedPages.Title', 'Deleted pages'); return _t('CMSSiteTreeFilter_StatusDeletedPages.Title', 'Deleted pages');
@ -318,6 +343,7 @@ class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter {
public function pagesIncluded() { public function pagesIncluded() {
$pages = Versioned::get_including_deleted('SiteTree'); $pages = Versioned::get_including_deleted('SiteTree');
$pages = $this->applyDefaultFilters($pages); $pages = $this->applyDefaultFilters($pages);
$pages = $pages->filterByCallback(function($page) { $pages = $pages->filterByCallback(function($page) {
// Doesn't exist on either stage or live // Doesn't exist on either stage or live
return $page->IsDeletedFromStage && !$page->ExistsOnLive; return $page->IsDeletedFromStage && !$page->ExistsOnLive;

View File

@ -2732,13 +2732,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return isset($stack[$level-1]) ? $stack[$level-1] : null; return isset($stack[$level-1]) ? $stack[$level-1] : null;
} }
/** /**
* Return the CSS classes to apply to this node in the CMS tree * Return the CSS classes to apply to this node in the CMS tree
* *
* @param string $numChildrenMethod
* @return string * @return string
*/ */
public function CMSTreeClasses() { public function CMSTreeClasses($numChildrenMethod="numChildren") {
$classes = sprintf('class-%s', $this->class); $classes = sprintf('class-%s', $this->class);
if($this->HasBrokenFile || $this->HasBrokenLink) { if($this->HasBrokenFile || $this->HasBrokenLink) {
$classes .= " BrokenLink"; $classes .= " BrokenLink";
@ -2765,7 +2766,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($this->hasExtension('Translatable') && $controller->Locale != Translatable::default_locale() && !$this->isTranslation()) if($this->hasExtension('Translatable') && $controller->Locale != Translatable::default_locale() && !$this->isTranslation())
$classes .= " untranslated "; $classes .= " untranslated ";
*/ */
$classes .= $this->markingClasses(); $classes .= $this->markingClasses($numChildrenMethod);
return $classes; return $classes;
} }

View File

@ -387,8 +387,12 @@ class VirtualPage extends Page {
$this->ImageTracking()->setByIdList($this->CopyContentFrom()->ImageTracking()->column('ID')); $this->ImageTracking()->setByIdList($this->CopyContentFrom()->ImageTracking()->column('ID'));
} }
public function CMSTreeClasses() { /**
return parent::CMSTreeClasses() . ' VirtualPage-' . $this->CopyContentFrom()->ClassName; * @param string $numChildrenMethod
* @return string
*/
public function CMSTreeClasses($numChildrenMethod="numChildren") {
return parent::CMSTreeClasses($numChildrenMethod) . ' VirtualPage-' . $this->CopyContentFrom()->ClassName;
} }
/** /**