Merge pull request #252 from silverstripe-droptables/dependent-pages-fix

BUG Remove handwritten SQL and use the ORM.
This commit is contained in:
Ingo Schommer 2012-12-06 05:53:49 -08:00
commit 5922c1ea35

View File

@ -1709,25 +1709,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/** /**
* Return the number of {@link DependentPages()} * Return the number of {@link DependentPages()}
* *
* @deprecated 3.1 Use DependentPages()->Count() instead.
*
* @param $includeVirtuals Set to false to exlcude virtual pages. * @param $includeVirtuals Set to false to exlcude virtual pages.
*/ */
public function DependentPagesCount($includeVirtuals = true) { public function DependentPagesCount($includeVirtuals = true) {
$links = DB::query("SELECT COUNT(*) FROM \"SiteTree_LinkTracking\" Deprecation::notice('3.1', 'Use SiteTree->DependentPages()->Count() instead.');
INNER JOIN \"SiteTree\" ON \"SiteTree\".\"ID\" = \"SiteTree_LinkTracking\".\"SiteTreeID\" return $this->DependentPages($includeVirtuals)->Count();
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;
} }
/** /**
@ -1803,7 +1791,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$dependentTable = new LiteralField('DependentNote', '<p></p>'); $dependentTable = new LiteralField('DependentNote', '<p></p>');
// Create a table for showing pages linked to this one // Create a table for showing pages linked to this one
$dependentPagesCount = $this->DependentPagesCount(); $dependentPages = $this->DependentPages();
$dependentPagesCount = $dependentPages->Count();
if($dependentPagesCount) { if($dependentPagesCount) {
$dependentColumns = array( $dependentColumns = array(
'Title' => $this->fieldLabel('Title'), 'Title' => $this->fieldLabel('Title'),
@ -1816,7 +1805,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$dependentTable = GridField::create( $dependentTable = GridField::create(
'DependentPages', 'DependentPages',
false, false,
$this->DependentPages() $dependentPages
); );
$dependentTable->getConfig()->getComponentByType('GridFieldDataColumns') $dependentTable->getConfig()->getComponentByType('GridFieldDataColumns')
->setFieldFormatting(array( ->setFieldFormatting(array(