From 30a36d9d8c685a26f6efd44d5b91cd05eb7a043e Mon Sep 17 00:00:00 2001 From: Ingo Schommer <ingo@silverstripe.com> Date: Thu, 29 Aug 2013 23:59:37 +0200 Subject: [PATCH] Disallow creation of section editor panel on large page trees (#41) Stopgap solution until a better UI is found for this. Also backports an additional canCreate() check which is already in place for master. --- code/Dashboard.php | 2 +- code/panels/DashboardSectionEditorPanel.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/code/Dashboard.php b/code/Dashboard.php index 32a7bd8..c5f9b46 100644 --- a/code/Dashboard.php +++ b/code/Dashboard.php @@ -225,7 +225,7 @@ public function AllPanels() { foreach(SS_ClassLoader::instance()->getManifest()->getDescendantsOf("DashboardPanel") as $class) { $SNG = Injector::inst()->get($class); $SNG->Priority = Config::inst()->get($class, "priority", Config::INHERITED); - $set->push($SNG); + if($SNG->canCreate()) $set->push($SNG); } return $set->sort("Priority"); } diff --git a/code/panels/DashboardSectionEditorPanel.php b/code/panels/DashboardSectionEditorPanel.php index 05d2280..57994b8 100644 --- a/code/panels/DashboardSectionEditorPanel.php +++ b/code/panels/DashboardSectionEditorPanel.php @@ -25,8 +25,14 @@ class DashboardSectionEditorPanel extends DashboardPanel { static $configure_on_create = true; - - + /** + * @config Maximum number of records which should be displayed in this component. + * If the number is too high, the dashboard can time out or run out of PHP memory. + * @todo Temporary configuration value, to be replaced by a more flexible UI component + * for viewing the hierarchy without preloading all of it. + * @var integer + */ + static $record_limit = 250; public function getLabel() { return _t('Dashboard.SECTIONEDTIORLABEL','Section Editor'); @@ -38,7 +44,14 @@ public function getDescription() { return _t('Dashbaord.SECTIONEDITORDESCRIPTION','Pulls pages from a section of the website for viewing and creation'); } - + public function canCreate($member = null) { + $count = SiteTree::get()->Count(); + if($count > $this->config()->record_limit) { + return false; + } else { + return parent::canCreate($member); + } + } /** * Gets the icon for the panel. Use the icon of the subject page when possible, otherwise