From c0751df54e417de21ee2b471a1721e32892dab35 Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Wed, 5 Dec 2012 10:27:12 +1300 Subject: [PATCH 1/2] BUG Remove handwritten SQL and use the ORM. The custom SQL does not take subsites into account and breaks the CMS on certain pages - under some circumstances the custom count will return 1 or more, while the set will be in fact empty because of augmentation. --- code/model/SiteTree.php | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 39a78bec..9c6e7486 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1709,27 +1709,15 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid /** * Return the number of {@link DependentPages()} * + * @deprecated 3.1 Use DependentPages()->Count() instead. + * * @param $includeVirtuals Set to false to exlcude virtual pages. */ public function DependentPagesCount($includeVirtuals = true) { - $links = DB::query("SELECT COUNT(*) FROM \"SiteTree_LinkTracking\" - INNER JOIN \"SiteTree\" ON \"SiteTree\".\"ID\" = \"SiteTree_LinkTracking\".\"SiteTreeID\" - WHERE \"ChildID\" = $this->ID ")->value(); - if($includeVirtuals && class_exists('VirtualPage')) { - $virtuals = DB::query("SELECT COUNT(*) FROM \"VirtualPage\" - INNER JOIN \"SiteTree\" ON \"SiteTree\".\"ID\" = \"VirtualPage\".\"ID\" - WHERE \"CopyContentFromID\" = $this->ID")->value(); - } else { - $virtuals = 0; - } - $redirectors = DB::query("SELECT COUNT(*) FROM \"RedirectorPage\" - INNER JOIN \"SiteTree\" ON \"SiteTree\".\"ID\" = \"RedirectorPage\".\"ID\" - WHERE \"RedirectionType\" = 'Internal' AND \"LinkToID\" = $this->ID")->value(); - - - return 0 + $links + $virtuals + $redirectors; + Deprecation::notice('3.1', 'Use SiteTree->DependentPages()->Count() instead.'); + return $this->DependentPages($includeVirtuals)->Count(); } - + /** * Return all virtual pages that link to this page */ @@ -1803,7 +1791,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $dependentTable = new LiteralField('DependentNote', '

'); // Create a table for showing pages linked to this one - $dependentPagesCount = $this->DependentPagesCount(); + $dependentPages = $this->DependentPages(); + $dependentPagesCount = $dependentPages->Count(); if($dependentPagesCount) { $dependentColumns = array( 'Title' => $this->fieldLabel('Title'), @@ -1816,7 +1805,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $dependentTable = GridField::create( 'DependentPages', false, - $this->DependentPages() + $dependentPages ); $dependentTable->getConfig()->getComponentByType('GridFieldDataColumns') ->setFieldFormatting(array( From 4fa4ae726b9c4700ef0c7bec374a79fb3b6bc1e8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 10 Dec 2012 15:38:32 +0100 Subject: [PATCH 2/2] Adjusted Behat steps to new definition format --- tests/behat/features/edit-a-page.feature | 4 ++-- tests/behat/features/preview-a-page.feature | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/behat/features/edit-a-page.feature b/tests/behat/features/edit-a-page.feature index 0be2ba39..cf7684f2 100644 --- a/tests/behat/features/edit-a-page.feature +++ b/tests/behat/features/edit-a-page.feature @@ -20,10 +20,10 @@ Feature: Edit a page Then I should see an edit page form When I fill in "Title" with "About Us!" - And I fill in the content form with "my new content" + And I fill in the "Content" HTML field with "my new content" And I press the "Save Draft" button Then I should see a "Saved." notice When I follow "About Us" Then the "Title" field should contain "About Us!" - And the content form should contain "my new content" \ No newline at end of file + And the "Content" HTML field should contain "my new content" \ No newline at end of file diff --git a/tests/behat/features/preview-a-page.feature b/tests/behat/features/preview-a-page.feature index 279fdb27..9f2d75c6 100644 --- a/tests/behat/features/preview-a-page.feature +++ b/tests/behat/features/preview-a-page.feature @@ -25,7 +25,7 @@ Feature: Preview a page Then I should see "About Us" in CMS Tree When I follow "About Us" - And I fill in the content form with "my new content" + And I fill in the "Content" HTML field with "my new content" And I press the "Save Draft" button And I press the "Preview ยป" button