From 377a8cdc7cdb1168fbe9c5c53781db6e54273e00 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sat, 10 Sep 2016 11:39:25 +1200 Subject: [PATCH] API: silverstripe-upgrader run for ss4 compatibility. --- _config.php | 2 ++ code/admin/GridFieldCategorisationConfig.php | 8 +++-- code/admin/GridFieldFormAction.php | 2 ++ code/admin/GridFieldMergeAction.php | 6 ++++ code/compat/pages/BlogHolder.php | 2 +- code/compat/tasks/BlogMigrationTask.php | 9 +++++- code/extensions/BlogCommentExtension.php | 2 ++ code/extensions/BlogFilter.php | 14 +++++++-- code/extensions/BlogMemberExtension.php | 10 ++++++- code/extensions/BlogPostFilter.php | 10 ++++++- code/extensions/BlogPostNotifications.php | 2 ++ code/extensions/URLSegmentExtension.php | 4 +++ code/forms/BlogAdminSidebar.php | 3 ++ .../forms/gridfield/GridFieldAddByDBField.php | 12 ++++++++ .../gridfield/GridFieldBlogPostState.php | 2 ++ code/model/Blog.php | 29 +++++++++++++++---- code/model/BlogCategory.php | 6 ++++ code/model/BlogPost.php | 22 ++++++++++++-- code/model/BlogTag.php | 6 ++++ code/widgets/BlogArchiveWidget.php | 6 ++++ code/widgets/BlogCategoriesWidget.php | 5 ++++ code/widgets/BlogRecentPostsWidget.php | 3 ++ code/widgets/BlogTagsCloudWidget.php | 6 ++++ code/widgets/BlogTagsWidget.php | 4 +++ tests/BlogCategoryTest.php | 26 ++++++++++------- tests/BlogPostFilterTest.php | 10 +++++-- tests/BlogPostNotificationsTest.php | 2 ++ tests/BlogPostTest.php | 14 +++++---- tests/BlogTagTest.php | 26 ++++++++++------- tests/BlogTagsCloudWidgetTest.php | 4 +++ tests/BlogTest.php | 25 +++++++++++----- 31 files changed, 230 insertions(+), 52 deletions(-) diff --git a/_config.php b/_config.php index d8ae592..4d7fd10 100755 --- a/_config.php +++ b/_config.php @@ -1,4 +1,6 @@ removeComponentsByType('GridFieldAddNewButton'); + $this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton'); $this->addComponent( new GridFieldAddByDBField('buttons-before-left') @@ -26,7 +28,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor /** * @var GridFieldDataColumns $columns */ - $columns = $this->getComponentByType('GridFieldDataColumns'); + $columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns->setFieldFormatting(array( 'BlogPostsCount' => function ($value, CategorisationObject $item) { @@ -45,7 +47,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor /** * @var GridFieldDataColumns $columns */ - $columns = $this->getComponentByType('GridFieldDataColumns'); + $columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns->setDisplayFields(array( 'Title' => 'Title', diff --git a/code/admin/GridFieldFormAction.php b/code/admin/GridFieldFormAction.php index 47d448f..59f4057 100644 --- a/code/admin/GridFieldFormAction.php +++ b/code/admin/GridFieldFormAction.php @@ -1,5 +1,7 @@ 'Member', + 'Owner' => 'SilverStripe\\Security\\Member', ); /** diff --git a/code/compat/tasks/BlogMigrationTask.php b/code/compat/tasks/BlogMigrationTask.php index 143fb7c..a098b00 100644 --- a/code/compat/tasks/BlogMigrationTask.php +++ b/code/compat/tasks/BlogMigrationTask.php @@ -1,5 +1,12 @@ filter('ClassName', $class); } else { $items = $class::get(); diff --git a/code/extensions/BlogCommentExtension.php b/code/extensions/BlogCommentExtension.php index de4576a..ed031b5 100644 --- a/code/extensions/BlogCommentExtension.php +++ b/code/extensions/BlogCommentExtension.php @@ -1,5 +1,7 @@ dataQuery() ->innerJoin('BlogPost', sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage)) - ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now()))); + ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); $staged = $staged->setDataQuery($dataQuery); } @@ -53,7 +63,7 @@ class BlogFilter extends Lumberjack if (!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) { $dataQuery = $staged->dataQuery() ->innerJoin('BlogPost', '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"') - ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now()))); + ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); $staged = $staged->setDataQuery($dataQuery); } diff --git a/code/extensions/BlogMemberExtension.php b/code/extensions/BlogMemberExtension.php index 1a3f2d7..f329f95 100644 --- a/code/extensions/BlogMemberExtension.php +++ b/code/extensions/BlogMemberExtension.php @@ -1,5 +1,13 @@ 'Image', + 'BlogProfileImage' => 'SilverStripe\\Assets\\Image', ); /** diff --git a/code/extensions/BlogPostFilter.php b/code/extensions/BlogPostFilter.php index 1795bc8..3a38123 100644 --- a/code/extensions/BlogPostFilter.php +++ b/code/extensions/BlogPostFilter.php @@ -1,5 +1,13 @@ addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now()))); + $query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); } } diff --git a/code/extensions/BlogPostNotifications.php b/code/extensions/BlogPostNotifications.php index e3d7ca2..f847bff 100644 --- a/code/extensions/BlogPostNotifications.php +++ b/code/extensions/BlogPostNotifications.php @@ -1,5 +1,7 @@ 'Member', - 'Writers' => 'Member', - 'Contributors' => 'Member', + 'Editors' => 'SilverStripe\\Security\\Member', + 'Writers' => 'SilverStripe\\Security\\Member', + 'Contributors' => 'SilverStripe\\Security\\Member', ); /** @@ -228,7 +247,7 @@ class Blog extends Page implements PermissionProvider public function RoleOf($member) { if (is_numeric($member)) { - $member = DataObject::get_by_id('Member', $member); + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); } if (!$member) { @@ -779,7 +798,7 @@ class Blog_Controller extends Page_Controller return (int) $year; } } elseif ($this->request->param('Action') == 'archive') { - return SS_Datetime::now()->Year(); + return DBDatetime::now()->Year(); } return null; diff --git a/code/model/BlogCategory.php b/code/model/BlogCategory.php index a678e40..9c86275 100644 --- a/code/model/BlogCategory.php +++ b/code/model/BlogCategory.php @@ -1,5 +1,11 @@ 'Image', + 'FeaturedImage' => 'SilverStripe\\Assets\\Image', ); /** @@ -46,7 +62,7 @@ class BlogPost extends Page private static $many_many = array( 'Categories' => 'BlogCategory', 'Tags' => 'BlogTag', - 'Authors' => 'Member', + 'Authors' => 'SilverStripe\\Security\\Member', ); /** @@ -419,7 +435,7 @@ class BlogPost extends Page $publishDate = $this->dbObject('PublishDate'); if (!$publishDate->getValue()) { - $this->PublishDate = SS_Datetime::now()->getValue(); + $this->PublishDate = DBDatetime::now()->getValue(); $this->write(); } } diff --git a/code/model/BlogTag.php b/code/model/BlogTag.php index 47c9e57..7b1c1c2 100644 --- a/code/model/BlogTag.php +++ b/code/model/BlogTag.php @@ -1,5 +1,11 @@ useDraftSite(); - $this->objFromFixture('Member', 'Admin'); + $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); @@ -87,8 +93,8 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); @@ -110,8 +116,8 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $category = singleton('BlogCategory'); @@ -123,8 +129,8 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); diff --git a/tests/BlogPostFilterTest.php b/tests/BlogPostFilterTest.php index e878e40..d62f746 100755 --- a/tests/BlogPostFilterTest.php +++ b/tests/BlogPostFilterTest.php @@ -1,5 +1,9 @@ assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts'); - SS_Datetime::set_mock_now('2020-01-01 00:00:00'); + DBDatetime::set_mock_now('2020-01-01 00:00:00'); $this->assertEquals(5, $blog->AllChildren()->Count(), 'Unfiltered blog posts'); } diff --git a/tests/BlogPostNotificationsTest.php b/tests/BlogPostNotificationsTest.php index 25f4073..4eb7634 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -1,5 +1,7 @@ objFromFixture('Member', $user); + $userRecord = $this->objFromFixture('SilverStripe\\Security\\Member', $user); $pageRecord = $this->objFromFixture('BlogPost', $page); - SS_Datetime::set_mock_now($date); + DBDatetime::set_mock_now($date); $this->assertEquals($canView, $pageRecord->canView($userRecord)); } @@ -88,10 +92,10 @@ class BlogPostTest extends SapphireTest { $blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate'); - $editor = $this->objFromFixture('Member', 'BlogEditor'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); $this->assertTrue($blogPost->canView($editor)); - $visitor = $this->objFromFixture('Member', 'Visitor'); + $visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); $this->assertFalse($blogPost->canView($visitor)); } diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index dcf886c..920475e 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -1,5 +1,11 @@ useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $tag = $this->objFromFixture('BlogTag', 'FirstTag'); @@ -93,8 +99,8 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $tag = $this->objFromFixture('BlogTag', 'FirstTag'); @@ -116,8 +122,8 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $tag = singleton('BlogTag'); @@ -129,8 +135,8 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); + $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $tag = $this->objFromFixture('BlogTag', 'FirstTag'); diff --git a/tests/BlogTagsCloudWidgetTest.php b/tests/BlogTagsCloudWidgetTest.php index d37a2bc..7c56852 100644 --- a/tests/BlogTagsCloudWidgetTest.php +++ b/tests/BlogTagsCloudWidgetTest.php @@ -1,5 +1,9 @@ objFromFixture('Member', 'BlogEditor'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); /** * @var Member $writer */ - $writer = $this->objFromFixture('Member', 'Writer'); + $writer = $this->objFromFixture('SilverStripe\\Security\\Member', 'Writer'); /** * @var Member $contributor */ - $contributor = $this->objFromFixture('Member', 'Contributor'); + $contributor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Contributor'); /** * @var Member $visitor */ - $visitor = $this->objFromFixture('Member', 'Visitor'); + $visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); $this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); @@ -321,7 +332,7 @@ class BlogTest extends SapphireTest */ protected function requestURL(ContentController $controller, $url) { - $request = new SS_HTTPRequest('get', $url); + $request = new HTTPRequest('get', $url); $request->match('$URLSegment//$Action/$ID/$OtherID'); $request->shift(); $controller->init();