From e0afd2f772fb1df31372d9ea4d3885f06ffda95f Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 13 Mar 2015 17:16:25 +0000 Subject: [PATCH 1/2] Update use of DataObject methods (as per framework #3799) --- code/model/SiteTreeFileExtension.php | 11 ++++++++++- code/model/SiteTreeFolderExtension.php | 2 +- code/model/SiteTreeLinkTracking.php | 4 ++-- code/model/VirtualPage.php | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/code/model/SiteTreeFileExtension.php b/code/model/SiteTreeFileExtension.php index 0e7d6cb0..ee8d25a0 100644 --- a/code/model/SiteTreeFileExtension.php +++ b/code/model/SiteTreeFileExtension.php @@ -31,8 +31,17 @@ class SiteTreeFileExtension extends DataExtension { $rememberSubsiteFilter = Subsite::$disable_subsite_filter; Subsite::disable_subsite_filter(true); } + + if($filter || $sort || $join || $limit) { + Deprecation::notice('3.2', 'The $filter, $sort, $join and $limit parameters for + SiteTreeFileExtension::BackLinkTracking() have been deprecated. + Please manipluate the returned list directly.', Deprecation::SCOPE_GLOBAL); + } - $links = $this->owner->getManyManyComponents('BackLinkTracking', $filter, $sort, $join, $limit); + $links = $this->owner->getManyManyComponents('BackLinkTracking') + ->where($filter) + ->sort($sort) + ->limit($limit); $this->owner->extend('updateBackLinkTracking', $links); if(class_exists("Subsite")){ diff --git a/code/model/SiteTreeFolderExtension.php b/code/model/SiteTreeFolderExtension.php index 1e190c13..d8d278d5 100644 --- a/code/model/SiteTreeFolderExtension.php +++ b/code/model/SiteTreeFolderExtension.php @@ -27,7 +27,7 @@ class SiteTreeFolderExtension extends DataExtension { $ids = $query->execute()->column(); if(!count($ids)) continue; - foreach(singleton($className)->has_one() as $relName => $joinClass) { + foreach(singleton($className)->hasOne() as $relName => $joinClass) { if($joinClass == 'Image' || $joinClass == 'File') { $fieldName = $relName .'ID'; $query = DataList::create($className)->where("$fieldName > 0"); diff --git a/code/model/SiteTreeLinkTracking.php b/code/model/SiteTreeLinkTracking.php index 7d57cc0d..ab8dea8f 100644 --- a/code/model/SiteTreeLinkTracking.php +++ b/code/model/SiteTreeLinkTracking.php @@ -109,7 +109,7 @@ class SiteTreeLinkTracking extends DataExtension { } // Update the "LinkTracking" many_many - if($record->ID && $record->many_many('LinkTracking') && $tracker = $record->LinkTracking()) { + if($record->ID && $record->manyManyComponent('LinkTracking') && $tracker = $record->LinkTracking()) { $tracker->removeByFilter(sprintf( '"FieldName" = \'%s\' AND "%s" = %d', $fieldName, @@ -123,7 +123,7 @@ class SiteTreeLinkTracking extends DataExtension { } // Update the "ImageTracking" many_many - if($record->ID && $record->many_many('ImageTracking') && $tracker = $record->ImageTracking()) { + if($record->ID && $record->manyManyComponent('ImageTracking') && $tracker = $record->ImageTracking()) { $tracker->removeByFilter(sprintf( '"FieldName" = \'%s\' AND "%s" = %d', $fieldName, diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index b2ae015e..f9daae84 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -54,7 +54,7 @@ class VirtualPage extends Page { $record = $this->CopyContentFrom(); $allFields = $record->db(); - if($hasOne = $record->has_one()) foreach($hasOne as $link) $allFields[$link . 'ID'] = "Int"; + if($hasOne = $record->hasOne()) foreach($hasOne as $link) $allFields[$link . 'ID'] = "Int"; $virtualFields = array(); foreach($allFields as $field => $type) { if(!in_array($field, $nonVirtualFields)) $virtualFields[] = $field; From 94d354de4a2eea8af1c7833935f419dcfbfd7fa3 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 28 Apr 2015 23:34:26 +1200 Subject: [PATCH 2/2] Fixed BacklinkTracking filter usage Previous deprecation fixes made this method error out when called on the root node (ID=0), so when admin/assets is first called. --- code/model/SiteTreeFileExtension.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/model/SiteTreeFileExtension.php b/code/model/SiteTreeFileExtension.php index 0ec1ad0b..37cccd6c 100644 --- a/code/model/SiteTreeFileExtension.php +++ b/code/model/SiteTreeFileExtension.php @@ -72,10 +72,13 @@ class SiteTreeFileExtension extends DataExtension { Please manipluate the returned list directly.', Deprecation::SCOPE_GLOBAL); } - $links = $this->owner->getManyManyComponents('BackLinkTracking') - ->where($filter) - ->sort($sort) - ->limit($limit); + $links = $this->owner->getManyManyComponents('BackLinkTracking'); + if($this->owner->ID) { + $links = $links + ->where($filter) + ->sort($sort) + ->limit($limit); + } $this->owner->extend('updateBackLinkTracking', $links); if(class_exists("Subsite")){