From 2ae1457068cddfdb5fad14c83ff5c5afedf13346 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Wed, 1 Jun 2016 17:28:59 +1200 Subject: [PATCH 01/31] Upgraded to work with silverstripe 4.x --- code/compat/pages/BlogEntry.php | 2 +- code/compat/pages/BlogHolder.php | 4 ++-- code/compat/pages/BlogTree.php | 4 ++-- code/extensions/BlogFilter.php | 2 +- code/extensions/BlogPostFilter.php | 16 +++++++++++----- code/model/Blog.php | 6 +++++- code/model/BlogCategory.php | 10 +++------- code/model/BlogPost.php | 2 +- code/model/BlogTag.php | 10 +++------- tests/blog.yml | 2 +- 10 files changed, 30 insertions(+), 28 deletions(-) diff --git a/code/compat/pages/BlogEntry.php b/code/compat/pages/BlogEntry.php index 190d475..3111a39 100644 --- a/code/compat/pages/BlogEntry.php +++ b/code/compat/pages/BlogEntry.php @@ -27,7 +27,7 @@ class BlogEntry extends BlogPost implements MigratableObject /** * {@inheritdoc} */ - public function canCreate($member = null) + public function canCreate($member = null, $context = array()) { return false; } diff --git a/code/compat/pages/BlogHolder.php b/code/compat/pages/BlogHolder.php index 49bc287..653a856 100644 --- a/code/compat/pages/BlogHolder.php +++ b/code/compat/pages/BlogHolder.php @@ -28,7 +28,7 @@ class BlogHolder extends BlogTree implements MigratableObject /** * {@inheritdoc} */ - public function canCreate($member = null) + public function canCreate($member = null, $context = array()) { return false; } @@ -64,7 +64,7 @@ class BlogHolder extends BlogTree implements MigratableObject } else { $message = "DRAFT: "; } - + return $message . $this->Title; } } diff --git a/code/compat/pages/BlogTree.php b/code/compat/pages/BlogTree.php index 0998de2..9fa2617 100644 --- a/code/compat/pages/BlogTree.php +++ b/code/compat/pages/BlogTree.php @@ -21,7 +21,7 @@ class BlogTree extends Page implements MigratableObject /** * {@inheritdoc} */ - public function canCreate($member = null) + public function canCreate($member = null, $context = array()) { return false; } @@ -43,7 +43,7 @@ class BlogTree extends Page implements MigratableObject } else { $message = "DRAFT: "; } - + return $message . $this->Title; } } diff --git a/code/extensions/BlogFilter.php b/code/extensions/BlogFilter.php index 65dc027..29dcd6c 100644 --- a/code/extensions/BlogFilter.php +++ b/code/extensions/BlogFilter.php @@ -17,7 +17,7 @@ class BlogFilter extends Lumberjack $staged = parent::stageChildren($showAll); if (!$this->shouldFilter() && $this->subclassForBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) { - $stage = Versioned::current_stage(); + $stage = Versioned::get_stage(); if ($stage == 'Stage') { $stage = ''; diff --git a/code/extensions/BlogPostFilter.php b/code/extensions/BlogPostFilter.php index 1795bc8..26949eb 100644 --- a/code/extensions/BlogPostFilter.php +++ b/code/extensions/BlogPostFilter.php @@ -14,16 +14,19 @@ class BlogPostFilter extends DataExtension * * @param SQLQuery $query */ - public function augmentSQL(SQLQuery &$query) + public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { - $stage = Versioned::current_stage(); + $stage = Versioned::get_stage(); if (Controller::curr() instanceof LeftAndMain) { return; } if ($stage == 'Live' || !Permission::check('VIEW_DRAFT_CONTENT')) { - $query->addWhere(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(SS_Datetime::now()))); + $query->addWhere(sprintf( + '"PublishDate" < \'%s\'', + Convert::raw2sql(SS_Datetime::now()) + )); } } @@ -38,8 +41,11 @@ class BlogPostFilter extends DataExtension * @param mixed $dataQuery * @param mixed $parent */ - public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent) - { + public function augmentLoadLazyFields( + SQLSelect &$query, + DataQuery &$dataQuery = null, + $dataObject + ) { $dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"'); } } diff --git a/code/model/Blog.php b/code/model/Blog.php index 0ce1b08..1d4ff6c 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -1,5 +1,7 @@ setValue($date); + return $obj; } return null; diff --git a/code/model/BlogCategory.php b/code/model/BlogCategory.php index a678e40..b9186ac 100644 --- a/code/model/BlogCategory.php +++ b/code/model/BlogCategory.php @@ -80,7 +80,7 @@ class BlogCategory extends DataObject implements CategorisationObject /** * {@inheritdoc} */ - protected function validate() + public function validate() { $validation = parent::validate(); if($validation->valid()) { @@ -131,13 +131,9 @@ class BlogCategory extends DataObject implements CategorisationObject } /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool + * {@inheritdoc} */ - public function canCreate($member = null) + public function canCreate($member = null, $context = array()) { $extended = $this->extendedCan(__FUNCTION__, $member); diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 7e6ac15..9c46862 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -218,7 +218,7 @@ class BlogPost extends Page 'Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray() - )->setMultiple(true); + ); $authorNames = TextField::create( 'AuthorNames', diff --git a/code/model/BlogTag.php b/code/model/BlogTag.php index 47c9e57..caf744e 100644 --- a/code/model/BlogTag.php +++ b/code/model/BlogTag.php @@ -81,7 +81,7 @@ class BlogTag extends DataObject implements CategorisationObject /** * {@inheritdoc} */ - protected function validate() + public function validate() { $validation = parent::validate(); if($validation->valid()) { @@ -132,13 +132,9 @@ class BlogTag extends DataObject implements CategorisationObject } /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool + * {@inheritdoc} */ - public function canCreate($member = null) + public function canCreate($member = null, $context = array()) { $extended = $this->extendedCan(__FUNCTION__, $member); diff --git a/tests/blog.yml b/tests/blog.yml index e664f88..cad0fc0 100755 --- a/tests/blog.yml +++ b/tests/blog.yml @@ -166,7 +166,7 @@ BlogPost: Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor NullPublishDate: Title: 'No publish date' - PublishDate: 'NULL' + PublishDate: '' Parent: =>Blog.FourthBlog Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor From f5974d80a2f23b95e4b1090baaa4b3db4bf602e5 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Thu, 2 Jun 2016 13:11:05 +1200 Subject: [PATCH 02/31] NEW Moved URLSegmentExtension, BlogTag and BlogCateogry shared functionality into a trait --- code/model/BlogCategory.php | 136 ++-------------------- code/model/BlogTag.php | 134 ++-------------------- code/traits/BlogObject.php | 221 ++++++++++++++++++++++++++++++++++++ tests/BlogCategoryTest.php | 2 + tests/BlogTagTest.php | 4 +- 5 files changed, 242 insertions(+), 255 deletions(-) create mode 100644 code/traits/BlogObject.php diff --git a/code/model/BlogCategory.php b/code/model/BlogCategory.php index b9186ac..c4ea804 100644 --- a/code/model/BlogCategory.php +++ b/code/model/BlogCategory.php @@ -8,11 +8,13 @@ * * @method Blog Blog() * + * @property string $Title * @property string $URLSegment * @property int $BlogID */ class BlogCategory extends DataObject implements CategorisationObject { + use BlogObject; /** * Use an exception code so that attempted writes can continue on @@ -21,13 +23,14 @@ class BlogCategory extends DataObject implements CategorisationObject * @const string * This must be a string because ValidationException has decided we can't use int */ - const DUPLICATE_EXCEPTION = "DUPLICATE"; + const DUPLICATE_EXCEPTION = 'DUPLICATE'; /** * @var array */ private static $db = array( 'Title' => 'Varchar(255)', + 'URLSegment' => 'Varchar(255)', ); /** @@ -45,140 +48,19 @@ class BlogCategory extends DataObject implements CategorisationObject ); /** - * @var array + * {@inheritdoc} */ - private static $extensions = array( - 'URLSegmentExtension', - ); - - /** - * @return DataList - */ - public function BlogPosts() + protected function getListUrlSegment() { - $blogPosts = parent::BlogPosts(); - - $this->extend("updateGetBlogPosts", $blogPosts); - - return $blogPosts; + return 'categories'; } /** * {@inheritdoc} */ - public function getCMSFields() + protected function getDuplicateError() { - $fields = new FieldList( - TextField::create('Title', _t('BlogCategory.Title', 'Title')) - ); - - $this->extend('updateCMSFields', $fields); - - return $fields; + return _t('BlogCategory.Duplicate', 'A blog category already exists with that name.'); } - /** - * {@inheritdoc} - */ - public function validate() - { - $validation = parent::validate(); - if($validation->valid()) { - // Check for duplicate categories - $blog = $this->Blog(); - if($blog && $blog->exists()) { - $existing = $blog->Categories()->filter('Title', $this->Title); - if($this->ID) { - $existing = $existing->exclude('ID', $this->ID); - } - if($existing->count() > 0) { - $validation->error(_t( - 'BlogCategory.Duplicate', - 'A blog category already exists with that name' - ), BlogCategory::DUPLICATE_EXCEPTION); - } - } - } - return $validation; - } - - /** - * Returns a relative link to this category. - * - * @return string - */ - public function getLink() - { - return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canView($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canView($member); - } - - /** - * {@inheritdoc} - */ - public function canCreate($member = null, $context = array()) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - $permission = Blog::config()->grant_user_permission; - - return Permission::checkMember($member, $permission); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canDelete($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canEdit($member); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canEdit($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canEdit($member); - } } diff --git a/code/model/BlogTag.php b/code/model/BlogTag.php index caf744e..7a6c181 100644 --- a/code/model/BlogTag.php +++ b/code/model/BlogTag.php @@ -14,6 +14,7 @@ */ class BlogTag extends DataObject implements CategorisationObject { + use BlogObject; /** * Use an exception code so that attempted writes can continue on @@ -29,6 +30,7 @@ class BlogTag extends DataObject implements CategorisationObject */ private static $db = array( 'Title' => 'Varchar(255)', + 'URLSegment' => 'Varchar(255)', ); /** @@ -46,140 +48,18 @@ class BlogTag extends DataObject implements CategorisationObject ); /** - * @var array + * {@inheritdoc} */ - private static $extensions = array( - 'URLSegmentExtension', - ); - - /** - * @return DataList - */ - public function BlogPosts() + protected function getListUrlSegment() { - $blogPosts = parent::BlogPosts(); - - $this->extend("updateGetBlogPosts", $blogPosts); - - return $blogPosts; + return 'tags'; } /** * {@inheritdoc} */ - public function getCMSFields() + protected function getDuplicateError() { - $fields = new FieldList( - TextField::create('Title', _t('BlogTag.Title', 'Title')) - ); - - $this->extend('updateCMSFields', $fields); - - return $fields; - } - - /** - * {@inheritdoc} - */ - public function validate() - { - $validation = parent::validate(); - if($validation->valid()) { - // Check for duplicate tags - $blog = $this->Blog(); - if($blog && $blog->exists()) { - $existing = $blog->Tags()->filter('Title', $this->Title); - if($this->ID) { - $existing = $existing->exclude('ID', $this->ID); - } - if($existing->count() > 0) { - $validation->error(_t( - 'BlogTag.Duplicate', - 'A blog tags already exists with that name' - ), BlogTag::DUPLICATE_EXCEPTION); - } - } - } - return $validation; - } - - /** - * Returns a relative URL for the tag link. - * - * @return string - */ - public function getLink() - { - return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canView($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canView($member); - } - - /** - * {@inheritdoc} - */ - public function canCreate($member = null, $context = array()) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - $permission = Blog::config()->grant_user_permission; - - return Permission::checkMember($member, $permission); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canDelete($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canEdit($member); - } - - /** - * Inherits from the parent blog or can be overwritten using a DataExtension. - * - * @param null|Member $member - * - * @return bool - */ - public function canEdit($member = null) - { - $extended = $this->extendedCan(__FUNCTION__, $member); - - if ($extended !== null) { - return $extended; - } - - return $this->Blog()->canEdit($member); + return _t('BlogTag.Duplicate', 'A blog tags already exists with that name.'); } } diff --git a/code/traits/BlogObject.php b/code/traits/BlogObject.php new file mode 100644 index 0000000..1d0b091 --- /dev/null +++ b/code/traits/BlogObject.php @@ -0,0 +1,221 @@ +extend('updateGetBlogPosts', $blogPosts); + + return $blogPosts; + } + + /** + * {@inheritdoc} + */ + public function getCMSFields() + { + $fields = new TabSet('Root', + new Tab('Main', + TextField::create('Title', _t(self::class . '.Title', 'Title')) + ) + ); + + $fields = FieldList::create($fields); + $this->extend('updateCMSFields', $fields); + + return $fields; + } + + /** + * {@inheritdoc} + */ + public function validate() + { + $validation = parent::validate(); + if(!$validation->valid()) { + return $validation; + } + + $blog = $this->Blog(); + if(!$blog || !$blog->exists()) { + return $validation; + } + + if($this->getDuplicatesByUrlSegment()->count() > 0) { + $validation->error($this->getDuplicateError(), self::DUPLICATE_EXCEPTION); + } + return $validation; + } + + /** + * Returns a relative link to this category. + * + * @return string + */ + public function getLink() + { + return Controller::join_links( + $this->Blog()->Link(), + $this->getListUrlSegment(), + $this->URLSegment + ); + } + + /** + * Inherits from the parent blog or can be overwritten using a DataExtension. + * + * @param null|Member $member + * + * @return bool + */ + public function canView($member = null) + { + $extended = $this->extendedCan(__FUNCTION__, $member); + + if ($extended !== null) { + return $extended; + } + + return $this->Blog()->canView($member); + } + + /** + * {@inheritdoc} + */ + public function canCreate($member = null, $context = array()) + { + $extended = $this->extendedCan(__FUNCTION__, $member); + + if ($extended !== null) { + return $extended; + } + + $permission = Blog::config()->grant_user_permission; + + return Permission::checkMember($member, $permission); + } + + /** + * Inherits from the parent blog or can be overwritten using a DataExtension. + * + * @param null|Member $member + * + * @return bool + */ + public function canDelete($member = null) + { + $extended = $this->extendedCan(__FUNCTION__, $member); + + if ($extended !== null) { + return $extended; + } + + return $this->Blog()->canEdit($member); + } + + /** + * Inherits from the parent blog or can be overwritten using a DataExtension. + * + * @param null|Member $member + * + * @return bool + */ + public function canEdit($member = null) + { + $extended = $this->extendedCan(__FUNCTION__, $member); + + if ($extended !== null) { + return $extended; + } + + return $this->Blog()->canEdit($member); + } + + /** + * {@inheritdoc} + */ + protected function onBeforeWrite() + { + parent::onBeforeWrite(); + if(empty($this->URLSegment)) { + return $this->generateURLSegment(); + } + } + + /** + * Generates a unique URLSegment from the title. + * + * @param int $increment + * + * @return string + */ + public function generateURLSegment($increment = 0) + { + $increment = (int) $increment; + $filter = new URLSegmentFilter(); + + $this->URLSegment = $filter->filter($this->owner->Title); + + if ($increment > 0) { + $this->URLSegment .= '-' . $increment; + } + + if ($this->getDuplicatesByUrlSegment()->count() > 0) { + $this->owner->generateURLSegment($increment+1); + } + + return $this->owner->URLSegment; + } + + /** + * Looks for objects of the same type by url segment. + * + * @return DataList + */ + protected function getDuplicatesByUrlSegment() + { + $duplicates = DataList::create(self::class)->filter(array( + 'URLSegment' => $this->URLSegment, + 'BlogID' => (int) $this->BlogID, + )); + + if ($this->ID) { + $duplicates = $duplicates->exclude('ID', $this->ID); + } + + return $duplicates; + } + + /** + * This returns the url segment for the listing page. + * eg. 'categories' in /my-blog/categories/category-url + * + * This is not editable at the moment, but a method is being used incase we want + * to make it editable in the future. We can use this method to provide logic + * without replacing multiple areas of the code base. We're also not being opinionated + * about how the segment should be obtained at the moment and allowing for the + * implementation to decide. + * + * @return string + */ + abstract protected function getListUrlSegment(); + + /** + * Returns an error message for this object when it tries to write a duplicate. + * + * @return string + */ + abstract protected function getDuplicateError(); + +} diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index c29aa95..c40e976 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -148,10 +148,12 @@ class BlogCategoryTest extends FunctionalTest $category = new BlogCategory(); $category->Title = 'Test'; $category->BlogID = $blog->ID; + $category->URLSegment = 'test'; $category->write(); $category = new BlogCategory(); $category->Title = 'Test'; + $category->URLSegment = 'test'; $category->BlogID = $blog->ID; try { $category->write(); diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index dcf886c..fd61cf5 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -162,7 +162,7 @@ class BlogTagTest extends FunctionalTest $tag2->Title = 'cat test'; $tag2->BlogID = $blog->ID; $tag2->write(); - $this->assertEquals('cat-test-0', $tag2->URLSegment); + $this->assertEquals('cat-test-1', $tag2->URLSegment); } @@ -174,10 +174,12 @@ class BlogTagTest extends FunctionalTest $tag = new BlogTag(); $tag->Title = 'Test'; $tag->BlogID = $blog->ID; + $tag->URLSegment = 'test'; $tag->write(); $tag = new BlogTag(); $tag->Title = 'Test'; + $tag->URLSegment = 'test'; $tag->BlogID = $blog->ID; try { $tag->write(); From 1e602a0ac11c65fc4ccd7fb14ecab56357602007 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Thu, 2 Jun 2016 16:00:28 +1200 Subject: [PATCH 03/31] Removed compass in favour of gulp --- .gitignore | 3 +- config.rb | 23 --- css/blog.css | 85 +++++------ css/cms.css | 157 +++++++++------------ gulpfile.js | 17 +++ package.json | 28 ++++ scss/cms.scss | 382 +++++++++++++++++++++++++------------------------- 7 files changed, 336 insertions(+), 359 deletions(-) delete mode 100755 config.rb create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index a5ffac4..3b7b7c6 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .ssh/* .bash* .profile -vendor/* +/vendor/* .sass-cache/* +/node_modules/ diff --git a/config.rb b/config.rb deleted file mode 100755 index 31c7f33..0000000 --- a/config.rb +++ /dev/null @@ -1,23 +0,0 @@ -# Require any additional compass plugins here. - -# Set this to the root of your project when deployed: -http_path = "/" -css_dir = "css" -sass_dir = "scss" -javascripts_dir = "javascript" - -# You can select your preferred output style here (can be overridden via the command line): -# output_style = :expanded or :nested or :compact or :compressed - -# To enable relative paths to assets via compass helper functions. Uncomment: -relative_assets = true - -# To disable debugging comments that display the original location of your selectors. Uncomment: -line_comments = false - - -# If you prefer the indented syntax, you might want to regenerate this -# project again passing --syntax sass, or you can uncomment this: -# preferred_syntax = :sass -# and then run: -# sass-convert -R --from scss --to sass scss scss && rm -rf sass && mv scss sass diff --git a/css/blog.css b/css/blog.css index fe370bc..a89a5eb 100644 --- a/css/blog.css +++ b/css/blog.css @@ -1,58 +1,43 @@ .no-sidebar .content-container.size3of4 { - width: 75%; -} + width: 75%; } .blog-entry .post-image img { - width: 98.75%; -} + width: 98.75%; } .blog-sidebar .WidgetHolder ul { - margin-left: 0; -} -.blog-sidebar .WidgetHolder ul li { - list-style-type: none; -} + margin-left: 0; } + .blog-sidebar .WidgetHolder ul li { + list-style-type: none; } + ul.blogTagCloud { list-style-type: none; - clear: both; -} -ul.blogTagCloud li { - float: left; - display: inline; - padding-right: 8px; -} -ul.blogTagCloud li a span { + clear: both; } + ul.blogTagCloud li { float: left; - line-height: 30px; text-align: center; - padding: 0px; -} -ul.blogTagCloud .tagCount10 { - font-size: 26pt; -} -ul.blogTagCloud .tagCount9 { - font-size: 24pt; -} -ul.blogTagCloud .tagCount8 { - font-size: 22pt; -} -ul.blogTagCloud .tagCount7 { - font-size: 20pt; -} -ul.blogTagCloud .tagCount6 { - font-size: 18pt; -} -ul.blogTagCloud .tagCount5 { - font-size: 16pt; -} -ul.blogTagCloud .tagCount4 { - font-size: 14pt; -} -ul.blogTagCloud .tagCount3 { - font-size: 12pt; -} -ul.blogTagCloud .tagCount2 { - font-size: 10pt; -} -ul.blogTagCloud .tagCount1 { - font-size: 8pt; -} + display: inline; + padding-right: 8px; } + ul.blogTagCloud li a span { + float: left; + line-height: 30px; + text-align: center; + padding: 0px; } + ul.blogTagCloud .tagCount10 { + font-size: 26pt; } + ul.blogTagCloud .tagCount9 { + font-size: 24pt; } + ul.blogTagCloud .tagCount8 { + font-size: 22pt; } + ul.blogTagCloud .tagCount7 { + font-size: 20pt; } + ul.blogTagCloud .tagCount6 { + font-size: 18pt; } + ul.blogTagCloud .tagCount5 { + font-size: 16pt; } + ul.blogTagCloud .tagCount4 { + font-size: 14pt; } + ul.blogTagCloud .tagCount3 { + font-size: 12pt; } + ul.blogTagCloud .tagCount2 { + font-size: 10pt; } + ul.blogTagCloud .tagCount1 { + font-size: 8pt; } diff --git a/css/cms.css b/css/cms.css index df0da49..41de718 100755 --- a/css/cms.css +++ b/css/cms.css @@ -7,19 +7,12 @@ /* * Sprite maps & Icons */ -.blog-icon-sprite, .gridfield-icon .blog-icon-timer { - background-image: url('../images/blog-icon-s0a5ab5f851.png'); - background-repeat: no-repeat; -} - -.gridfield-icon .blog-icon-timer { - background-position: 0 0; -} +.gridfield-icon.blog-icon-timer { + background: url("../images/blog-icon/timer.png") center no-repeat; } #FeaturedImage .middleColumn { clear: none; - float: left; -} + float: left; } .blog-admin-sidebar { width: 280px; @@ -28,60 +21,46 @@ position: absolute; right: 0px; bottom: 0px; - height: 100%; -} -.blog-admin-sidebar .cms-panel-toggle a { - text-align: left; -} -.blog-admin-sidebar ~ .blog-admin-outer { - width: 100%; - padding-right: 280px; - position: absolute; - height: 100%; - overflow-y: hidden; - overflow-x: hidden; - box-sizing: border-box; -} -.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset { - position: relative; - overflow: auto; - height: 100%; - width: 100%; -} -.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title label { - float: none; -} -.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title .middleColumn, .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title input { - width: 100%; - max-width: 100%; - margin-left: 0; -} -.blog-admin-sidebar .cms-content-view > .field + .field { - margin-top: 10px; -} -.blog-admin-sidebar .cms-content-view > .field.urlsegment .preview { - padding-top: 0; - line-height: 25px; -} -.blog-admin-sidebar .cms-content-view > .field.urlsegment .edit { - float: right; -} -.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .date { - width: 60%; -} -.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .time { - width: 36%; - float: right; -} -.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn .middleColumn, .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn input { - width: 100%; -} -.blog-admin-sidebar.collapsed ~ .blog-admin-outer { - padding-right: 41px; -} -.blog-admin-sidebar.cms-content-tools .cms-panel-content { - width: auto; -} + height: 100%; } + .blog-admin-sidebar .cms-panel-toggle a { + text-align: left; } + .blog-admin-sidebar ~ .blog-admin-outer { + width: 100%; + padding-right: 280px; + position: absolute; + height: 100%; + overflow-y: hidden; + overflow-x: hidden; + box-sizing: border-box; } + .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset { + position: relative; + overflow: auto; + height: 100%; + width: 100%; } + .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title label { + float: none; } + .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title .middleColumn, .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title input { + width: 100%; + max-width: 100%; + margin-left: 0; } + .blog-admin-sidebar .cms-content-view > .field + .field { + margin-top: 10px; } + .blog-admin-sidebar .cms-content-view > .field.urlsegment .preview { + padding-top: 0; + line-height: 25px; } + .blog-admin-sidebar .cms-content-view > .field.urlsegment .edit { + float: right; } + .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .date { + width: 60%; } + .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .time { + width: 36%; + float: right; } + .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn .middleColumn, .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn input { + width: 100%; } + .blog-admin-sidebar.collapsed ~ .blog-admin-outer { + padding-right: 41px; } + .blog-admin-sidebar.cms-content-tools .cms-panel-content { + width: auto; } .toggle-description { text-indent: -1000000px; @@ -89,63 +68,53 @@ background: url("../images/information.png") no-repeat center center; width: 20px; height: 20px; - margin-left: 4px; -} + margin-left: 4px; } .middleColumn.toggle-description-correct-middle { margin-left: 0; float: left; - width: 416px; -} + width: 416px; } label.right.toggle-description-correct-right { display: inline-block; margin-left: 0; clear: none; - float: left; -} + float: left; } .description.toggle-description-correct-description { width: 416px; - padding: 12px 0; -} + padding: 12px 0; } .custom-summary .ui-accordion-content .field { - margin: 0; -} + margin: 0; } + .custom-summary .ui-accordion-content, .custom-summary .ui-accordion-content .field { - padding: 0; -} + padding: 0; } + .custom-summary .ui-icon-triangle-1-e { - background-position: -16px -128px; -} + background-position: -16px -128px; } .cms table.ss-gridfield-table tr td.MergeAction { - width: 225px; -} -.cms table.ss-gridfield-table tr td.MergeAction a { - display: block; - height: 100%; - width: 100%; -} -.cms table.ss-gridfield-table tr td.MergeAction select { - width: 150px; -} + width: 225px; } + .cms table.ss-gridfield-table tr td.MergeAction a { + display: block; + height: 100%; + width: 100%; } + .cms table.ss-gridfield-table tr td.MergeAction select { + width: 150px; } .cms-content-actions, .cms-preview-controls { - z-index: 999; -} + z-index: 999; } .blog-cms-categorisation .MergeActionReveal { - margin-left: 10px; -} + margin-left: 10px; } + .blog-cms-categorisation .MergeActionReveal:after { content: ''; background: url("../images/move-icon.png"); display: inline-block; height: 16px; width: 16px; - margin-left: 4px; -} + margin-left: 4px; } diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..4aa2f74 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,17 @@ +var sass = require("gulp-sass"); +var gulp = require("gulp"); +var watch = require('gulp-watch'); + +gulp.task("scss", function () { + gulp.src("./scss/*.scss") + .pipe(sass().on('error', sass.logError)) + .pipe(gulp.dest("./css")); +}); + +gulp.task('watch', ['scss'], function() { + gulp.watch('./scss/*.scss', ['scss']); +}); + +gulp.task('default', ['scss'], function() { + // noop +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..4fe994b --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "silverstripe-blog", + "version": "3.0.0", + "description": "Silverstripe blog module", + "main": "index.js", + "directories": { + "doc": "docs", + "test": "tests" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/silverstripe/silverstripe-blog.git" + }, + "author": "", + "license": "BSD-3", + "bugs": { + "url": "https://github.com/silverstripe/silverstripe-blog/issues" + }, + "homepage": "https://github.com/silverstripe/silverstripe-blog#readme", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-sass": "^2.3.1", + "gulp-watch": "^4.3.6" + } +} diff --git a/scss/cms.scss b/scss/cms.scss index 42dcea6..20419f6 100755 --- a/scss/cms.scss +++ b/scss/cms.scss @@ -1,191 +1,191 @@ -/** - * CMS Styles - */ -/** - * Include Compass framework - */ -@import "compass"; -/* - * Sprite maps & Icons - */ -@import "compass/utilities/sprites/base"; -@import "blog-icon/*.png"; -// buttons - -.gridfield-icon { - @include all-blog-icon-sprites; -} - -#FeaturedImage .middleColumn { - clear: none; - float: left; -} - -.blog-admin-sidebar { - width: 280px; - border-right: none; - border-left: 1px solid #C0C0C2; - position: absolute; - right: 0px; - bottom: 0px; - height: 100%; - - .cms-panel-toggle a { - text-align: left; - } - - ~ .blog-admin-outer { - width: 100%; - padding-right: 280px; - position: absolute; - height: 100%; - overflow-y: hidden; - overflow-x: hidden; - box-sizing: border-box; - - > .ss-tabset { - position: relative; - overflow: auto; - height: 100%; - width: 100%; - - #Title { - label { - float: none; - } - .middleColumn, input { - width: 100%; - max-width: 100%; - margin-left: 0; - } - } - } - } - - .cms-content-view { - > .field { - + .field { - margin-top: 10px; - } - - &.urlsegment { - .preview { - padding-top: 0; - line-height: 25px; - } - - .edit { - float: right; - } - } - - &.datetime { - > .middleColumn { - > .date { - width: 60%; - } - - > .time { - width: 36%; - float: right; - } - - .middleColumn, input { - width: 100%; - } - } - } - } - } - - &.collapsed { - ~ .blog-admin-outer { - padding-right: 41px; - } - } - - &.cms-content-tools { - .cms-panel-content { - width: auto; - } - } -} - -.toggle-description { - text-indent: -1000000px; - display: inline-block; - background: url("../images/information.png") no-repeat center center; - width: 20px; - height: 20px; - margin-left: 4px; -} - -.middleColumn.toggle-description-correct-middle { - margin-left: 0; - float: left; - width: 416px; -} - -label.right.toggle-description-correct-right { - display: inline-block; - margin-left: 0; - clear: none; - float: left; -} - -.description.toggle-description-correct-description { - width: 416px; - padding: 12px 0; -} - -.custom-summary { - .ui-accordion-content .field { - margin: 0; - } - - .ui-accordion-content, - .ui-accordion-content .field { - padding: 0; - } - - .ui-icon-triangle-1-e { - background-position: -16px -128px; - } -} - -.cms table.ss-gridfield-table { - tr td.MergeAction { - width: 225px; - - a { - display: block; - height: 100%; - width: 100%; - } - - select { - width: 150px; - } - } -} - -.cms-content-actions, -.cms-preview-controls { - z-index: 999; -} - -.blog-cms-categorisation { - - .MergeActionReveal { - margin-left: 10px; - } - - .MergeActionReveal:after { - content: ''; - background: url('../images/move-icon.png'); - display: inline-block; - height: 16px; - width: 16px; - margin-left: 4px; - } -} +/** + * CMS Styles + */ +/** + * Include Compass framework + */ +// @import "compass"; +/* + * Sprite maps & Icons + */ +// @import "compass/utilities/sprites/base"; +// @import "blog-icon/*.png"; +// buttons + +.gridfield-icon.blog-icon-timer { + background: url('../images/blog-icon/timer.png') center no-repeat; +} + +#FeaturedImage .middleColumn { + clear: none; + float: left; +} + +.blog-admin-sidebar { + width: 280px; + border-right: none; + border-left: 1px solid #C0C0C2; + position: absolute; + right: 0px; + bottom: 0px; + height: 100%; + + .cms-panel-toggle a { + text-align: left; + } + + ~ .blog-admin-outer { + width: 100%; + padding-right: 280px; + position: absolute; + height: 100%; + overflow-y: hidden; + overflow-x: hidden; + box-sizing: border-box; + + > .ss-tabset { + position: relative; + overflow: auto; + height: 100%; + width: 100%; + + #Title { + label { + float: none; + } + .middleColumn, input { + width: 100%; + max-width: 100%; + margin-left: 0; + } + } + } + } + + .cms-content-view { + > .field { + + .field { + margin-top: 10px; + } + + &.urlsegment { + .preview { + padding-top: 0; + line-height: 25px; + } + + .edit { + float: right; + } + } + + &.datetime { + > .middleColumn { + > .date { + width: 60%; + } + + > .time { + width: 36%; + float: right; + } + + .middleColumn, input { + width: 100%; + } + } + } + } + } + + &.collapsed { + ~ .blog-admin-outer { + padding-right: 41px; + } + } + + &.cms-content-tools { + .cms-panel-content { + width: auto; + } + } +} + +.toggle-description { + text-indent: -1000000px; + display: inline-block; + background: url("../images/information.png") no-repeat center center; + width: 20px; + height: 20px; + margin-left: 4px; +} + +.middleColumn.toggle-description-correct-middle { + margin-left: 0; + float: left; + width: 416px; +} + +label.right.toggle-description-correct-right { + display: inline-block; + margin-left: 0; + clear: none; + float: left; +} + +.description.toggle-description-correct-description { + width: 416px; + padding: 12px 0; +} + +.custom-summary { + .ui-accordion-content .field { + margin: 0; + } + + .ui-accordion-content, + .ui-accordion-content .field { + padding: 0; + } + + .ui-icon-triangle-1-e { + background-position: -16px -128px; + } +} + +.cms table.ss-gridfield-table { + tr td.MergeAction { + width: 225px; + + a { + display: block; + height: 100%; + width: 100%; + } + + select { + width: 150px; + } + } +} + +.cms-content-actions, +.cms-preview-controls { + z-index: 999; +} + +.blog-cms-categorisation { + + .MergeActionReveal { + margin-left: 10px; + } + + .MergeActionReveal:after { + content: ''; + background: url('../images/move-icon.png'); + display: inline-block; + height: 16px; + width: 16px; + margin-left: 4px; + } +} From 37e5d106d2fa9f408de2e4d301d7231685873181 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Thu, 2 Jun 2016 17:11:56 +1200 Subject: [PATCH 04/31] FIX right sidebar was being forced to float left --- code/model/BlogPost.php | 22 ++++++++++------------ css/cms.css | 40 +++++++++++++++++++++++----------------- js/cms.js | 11 +++++++++++ scss/cms.scss | 16 +++++++++++++--- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 9c46862..4f5abb8 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -174,9 +174,7 @@ class BlogPost extends Page Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); - $self =& $this; - - $this->beforeUpdateCMSFields(function ($fields) use ($self) { + $this->beforeUpdateCMSFields(function ($fields) { $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); @@ -207,7 +205,7 @@ class BlogPost extends Page $fields->push(HiddenField::create('MenuTitle')); $urlSegment = $fields->dataFieldByName('URLSegment'); - $urlSegment->setURLPrefix($self->Parent()->RelativeLink()); + $urlSegment->setURLPrefix($this->Parent()->RelativeLink()); $fields->removeFieldsFromTab('Root.Main', array( 'MenuTitle', @@ -217,7 +215,7 @@ class BlogPost extends Page $authorField = ListboxField::create( 'Authors', _t('BlogPost.Authors', 'Authors'), - $self->getCandidateAuthors()->map()->toArray() + $this->getCandidateAuthors()->map()->toArray() ); $authorNames = TextField::create( @@ -230,14 +228,14 @@ class BlogPost extends Page 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.') ); - if (!$self->canEditAuthors()) { + if (!$this->canEditAuthors()) { $authorField = $authorField->performDisabledTransformation(); $authorNames = $authorNames->performDisabledTransformation(); } $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate->getDateField()->setConfig('showcalendar', true); - if (!$self->PublishDate) { + if (!$this->PublishDate) { $publishDate->setDescription(_t( 'BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.') @@ -245,7 +243,7 @@ class BlogPost extends Page } // Get categories and tags - $parent = $self->Parent(); + $parent = $this->Parent(); $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get(); @@ -260,17 +258,17 @@ class BlogPost extends Page 'Categories', _t('BlogPost.Categories', 'Categories'), $categories, - $self->Categories() + $this->Categories() ) - ->setCanCreate($self->canCreateCategories()) + ->setCanCreate($this->canCreateCategories()) ->setShouldLazyLoad(true), TagField::create( 'Tags', _t('BlogPost.Tags', 'Tags'), $tags, - $self->Tags() + $this->Tags() ) - ->setCanCreate($self->canCreateTags()) + ->setCanCreate($this->canCreateTags()) ->setShouldLazyLoad(true), $authorField, $authorNames diff --git a/css/cms.css b/css/cms.css index 41de718..2998d91 100755 --- a/css/cms.css +++ b/css/cms.css @@ -14,17 +14,21 @@ clear: none; float: left; } -.blog-admin-sidebar { +.has-panel .cms-content-tools.blog-admin-sidebar { width: 280px; border-right: none; border-left: 1px solid #C0C0C2; - position: absolute; + position: absolute !important; + /* overrides cms !imporant style */ right: 0px; - bottom: 0px; + top: 0; height: 100%; } - .blog-admin-sidebar .cms-panel-toggle a { - text-align: left; } - .blog-admin-sidebar ~ .blog-admin-outer { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-panel-toggle a { + text-align: left; + margin: 0; } + .has-panel .cms-content-tools.blog-admin-sidebar .cms-panel-toggle.south { + border-top: 1px solid #aaaaaa; } + .has-panel .cms-content-tools.blog-admin-sidebar ~ .blog-admin-outer { width: 100%; padding-right: 280px; position: absolute; @@ -32,34 +36,36 @@ overflow-y: hidden; overflow-x: hidden; box-sizing: border-box; } - .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset { + .has-panel .cms-content-tools.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset { position: relative; overflow: auto; height: 100%; width: 100%; } - .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title label { + .has-panel .cms-content-tools.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title label { float: none; } - .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title .middleColumn, .blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title input { + .has-panel .cms-content-tools.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title .middleColumn, .has-panel .cms-content-tools.blog-admin-sidebar ~ .blog-admin-outer > .ss-tabset #Title input { width: 100%; max-width: 100%; margin-left: 0; } - .blog-admin-sidebar .cms-content-view > .field + .field { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field + .field { margin-top: 10px; } - .blog-admin-sidebar .cms-content-view > .field.urlsegment .preview { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.urlsegment .preview { padding-top: 0; line-height: 25px; } - .blog-admin-sidebar .cms-content-view > .field.urlsegment .edit { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.urlsegment .edit { float: right; } - .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .date { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .date { width: 60%; } - .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .time { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn > .time { width: 36%; float: right; } - .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn .middleColumn, .blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn input { + .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn .middleColumn, .has-panel .cms-content-tools.blog-admin-sidebar .cms-content-view > .field.datetime > .middleColumn input { width: 100%; } - .blog-admin-sidebar.collapsed ~ .blog-admin-outer { + .has-panel .cms-content-tools.blog-admin-sidebar.collapsed ~ .blog-admin-outer { padding-right: 41px; } - .blog-admin-sidebar.cms-content-tools .cms-panel-content { + .has-panel .cms-content-tools.blog-admin-sidebar.collapsed ~ .blog-admin-outer #Root_Main { + margin-right: 15px; } + .has-panel .cms-content-tools.blog-admin-sidebar.cms-content-tools .cms-panel-content { width: auto; } .toggle-description { diff --git a/js/cms.js b/js/cms.js index 6dbefdf..36fb506 100644 --- a/js/cms.js +++ b/js/cms.js @@ -113,6 +113,10 @@ if(!this.hasClass('collapsed') && ($(".blog-admin-outer").width() < this.getMinInnerWidth())) { this.collapsePanel(); } + + window.onresize = function() { + this.updateLayout(); + }.bind(this); }, togglePanel: function(bool, silent) { this._super(bool, silent); @@ -124,9 +128,16 @@ * @returns {undefined} */ updateLayout: function() { + $(this).css('height', '100%'); + var currentHeight = $(this).outerHeight(); + var bottomHeight = $('.cms-content-actions').eq(0).outerHeight(); + $(this).css('height', (currentHeight - bottomHeight) + "px"); + $(this).css('bottom', bottomHeight + "px"); + $('.cms-container').updateLayoutOptions({ minContentWidth: 820 + this.width() }); + } }); diff --git a/scss/cms.scss b/scss/cms.scss index 20419f6..670f2d4 100755 --- a/scss/cms.scss +++ b/scss/cms.scss @@ -21,19 +21,24 @@ float: left; } -.blog-admin-sidebar { +.has-panel .cms-content-tools.blog-admin-sidebar { width: 280px; border-right: none; border-left: 1px solid #C0C0C2; - position: absolute; + position: absolute !important; /* overrides cms !imporant style */ right: 0px; - bottom: 0px; + top: 0; height: 100%; .cms-panel-toggle a { text-align: left; + margin: 0; } + .cms-panel-toggle.south { + border-top: 1px solid #aaaaaa; + } + ~ .blog-admin-outer { width: 100%; padding-right: 280px; @@ -101,7 +106,12 @@ &.collapsed { ~ .blog-admin-outer { padding-right: 41px; + + #Root_Main { + margin-right: 15px; + } } + } &.cms-content-tools { From 4313643a0b2439ec4bf8c2740b3677da950ea77c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 14 Dec 2016 12:04:09 +1300 Subject: [PATCH 05/31] Add composer alias for 3.x and update requirements for SS4 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index fe52322..76fae8b 100755 --- a/composer.json +++ b/composer.json @@ -8,12 +8,12 @@ ], "type": "silverstripe-module", "require": { - "silverstripe/cms": "^3.1.0", - "silverstripe/lumberjack": "~1.1", - "silverstripe/tagfield": "^1.0" + "silverstripe/cms": "^4.0", + "silverstripe/lumberjack": "^2.0", + "silverstripe/tagfield": "^2.0" }, "require-dev": { - "phpunit/PHPUnit": "~3.7@stable" + "phpunit/PHPUnit": "~4.8" }, "extra": { "branch-alias": { From 13a5badff5876b8d77c68db4937a4ce2190522c0 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 15 Dec 2016 16:41:49 +1300 Subject: [PATCH 06/31] Move "code" to PSR-4 friendly "src" folders. Add namespacing. --- _config.php | 16 +- _config/comments.yml | 6 +- _config/config.yml | 4 +- code/compat/pages/BlogEntry.php | 112 ---- code/compat/pages/BlogHolder.php | 77 --- code/compat/pages/BlogTree.php | 56 -- code/compat/tasks/BlogMigrationTask.php | 92 --- code/compat/tasks/MigratableObject.php | 9 - code/compat/widgets/ArchiveWidget.php | 54 -- code/compat/widgets/TagCloudWidget.php | 47 -- composer.json | 79 +-- src/.upgrade.yml | 28 + .../Admin}/GridFieldCategorisationConfig.php | 21 +- .../Admin}/GridFieldFormAction.php | 4 + .../Admin}/GridFieldMergeAction.php | 11 + src/Controllers/BlogController.php | 517 ++++++++++++++++ src/Controllers/BlogPostController.php | 14 + .../forms => src/Forms}/BlogAdminSidebar.php | 5 + .../GridField}/GridFieldAddByDBField.php | 17 +- .../GridField}/GridFieldBlogPostState.php | 7 + .../GridField}/GridFieldConfig_BlogPost.php | 4 + {code/model => src/Model}/Blog.php | 561 ++---------------- {code/model => src/Model}/BlogCategory.php | 20 +- .../Model}/BlogCommentExtension.php | 5 + {code/extensions => src/Model}/BlogFilter.php | 25 +- .../Model}/BlogMemberExtension.php | 20 +- {code/traits => src/Model}/BlogObject.php | 43 +- {code/model => src/Model}/BlogPost.php | 70 ++- .../Model}/BlogPostFilter.php | 29 +- .../Model}/BlogPostNotifications.php | 4 + {code/model => src/Model}/BlogTag.php | 22 +- .../Model}/CategorisationObject.php | 3 + .../Widgets}/BlogArchiveWidget.php | 8 +- .../Widgets}/BlogCategoriesWidget.php | 10 +- .../Widgets}/BlogRecentPostsWidget.php | 10 +- .../Widgets}/BlogTagsCloudWidget.php | 8 +- .../Widgets}/BlogTagsWidget.php | 10 +- tests/BlogCategoryTest.php | 57 +- tests/BlogPostFilterTest.php | 12 +- tests/BlogPostNotificationsTest.php | 13 +- tests/BlogPostTest.php | 26 +- tests/BlogTagTest.php | 64 +- tests/BlogTagsCloudWidgetTest.php | 15 +- tests/BlogTest.php | 70 ++- tests/blog.yml | 130 ++-- 45 files changed, 1143 insertions(+), 1272 deletions(-) delete mode 100644 code/compat/pages/BlogEntry.php delete mode 100644 code/compat/pages/BlogHolder.php delete mode 100644 code/compat/pages/BlogTree.php delete mode 100644 code/compat/tasks/BlogMigrationTask.php delete mode 100644 code/compat/tasks/MigratableObject.php delete mode 100644 code/compat/widgets/ArchiveWidget.php delete mode 100644 code/compat/widgets/TagCloudWidget.php create mode 100644 src/.upgrade.yml rename {code/admin => src/Admin}/GridFieldCategorisationConfig.php (72%) rename {code/admin => src/Admin}/GridFieldFormAction.php (89%) rename {code/admin => src/Admin}/GridFieldMergeAction.php (95%) create mode 100644 src/Controllers/BlogController.php create mode 100644 src/Controllers/BlogPostController.php rename {code/forms => src/Forms}/BlogAdminSidebar.php (73%) rename {code/forms/gridfield => src/Forms/GridField}/GridFieldAddByDBField.php (89%) rename {code/forms/gridfield => src/Forms/GridField}/GridFieldBlogPostState.php (94%) rename {code/forms/gridfield => src/Forms/GridField}/GridFieldConfig_BlogPost.php (81%) rename {code/model => src/Model}/Blog.php (56%) rename {code/model => src/Model}/BlogCategory.php (71%) rename {code/extensions => src/Model}/BlogCommentExtension.php (82%) rename {code/extensions => src/Model}/BlogFilter.php (78%) rename {code/extensions => src/Model}/BlogMemberExtension.php (81%) rename {code/traits => src/Model}/BlogObject.php (82%) rename {code/model => src/Model}/BlogPost.php (91%) rename {code/extensions => src/Model}/BlogPostFilter.php (64%) rename {code/extensions => src/Model}/BlogPostNotifications.php (91%) rename {code/model => src/Model}/BlogTag.php (68%) rename {code/model => src/Model}/CategorisationObject.php (69%) rename {code/widgets => src/Widgets}/BlogArchiveWidget.php (94%) rename {code/widgets => src/Widgets}/BlogCategoriesWidget.php (90%) rename {code/widgets => src/Widgets}/BlogRecentPostsWidget.php (86%) rename {code/widgets => src/Widgets}/BlogTagsCloudWidget.php (92%) rename {code/widgets => src/Widgets}/BlogTagsWidget.php (90%) diff --git a/_config.php b/_config.php index d8ae592..f45d2d2 100755 --- a/_config.php +++ b/_config.php @@ -1,8 +1,8 @@ - 'SS_Datetime', - 'Author' => 'Text', - 'Tags' => 'Text', - ); - - /** - * {@inheritdoc} - */ - public function canCreate($member = null, $context = array()) - { - return false; - } - - /** - * {@inheritdoc} - */ - public function up() - { - - //Migrate comma separated tags into BlogTag objects. - foreach ($this->TagNames() as $tag) { - $existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID)); - if ($existingTag->count()) { - //if tag already exists we will simply add it to this post. - $tagObject = $existingTag->First(); - } else { - //if the tag is now we create it and add it to this post. - $tagObject = new BlogTag(); - $tagObject->Title = $tag; - $tagObject->BlogID = $this->ParentID; - $tagObject->write(); - } - - if ($tagObject) { - $this->Tags()->add($tagObject); - } - } - - //Store if the original entity was published or not (draft) - $published = $this->IsPublished(); - // If a user has subclassed BlogEntry, it should not be turned into a BlogPost. - if ($this->ClassName === 'BlogEntry') { - $this->ClassName = 'BlogPost'; - $this->RecordClassName = 'BlogPost'; - } - //Migrate these key data attributes - $this->PublishDate = $this->Date; - $this->AuthorNames = $this->Author; - $this->InheritSideBar = true; - - //Write and additionally publish the item if it was published before. - $this->write(); - if ($published) { - $this->publish('Stage', 'Live'); - $message = "PUBLISHED: "; - } else { - $message = "DRAFT: "; - } - - return $message . $this->Title; - } - - /** - * Safely split and parse all distinct tags assigned to this BlogEntry. - * - * @deprecated since version 2.0 - * - * @return array - */ - public function TagNames() - { - $tags = preg_split('/\s*,\s*/', trim($this->Tags)); - - $results = array(); - - foreach ($tags as $tag) { - if ($tag) { - $results[mb_strtolower($tag)] = $tag; - } - } - - return $results; - } -} - -/** - * @deprecated since version 2.0 - */ -class BlogEntry_Controller extends BlogPost_Controller -{ -} diff --git a/code/compat/pages/BlogHolder.php b/code/compat/pages/BlogHolder.php deleted file mode 100644 index 653a856..0000000 --- a/code/compat/pages/BlogHolder.php +++ /dev/null @@ -1,77 +0,0 @@ - 'Boolean', - 'ShowFullEntry' => 'Boolean', - ); - - /** - * @var array - */ - private static $has_one = array( - 'Owner' => 'Member', - ); - - /** - * {@inheritdoc} - */ - public function canCreate($member = null, $context = array()) - { - return false; - } - - - //Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error. - public function validURLSegment() - { - return true; - } - public function syncLinkTracking() - { - return null; - } - - /** - * {@inheritdoc} - */ - public function up() - { - $published = $this->IsPublished(); - - if ($this->ClassName === 'BlogHolder') { - $this->ClassName = 'Blog'; - $this->RecordClassName = 'Blog'; - $this->PostsPerPage = 10; - $this->write(); - } - - if ($published) { - $this->publish('Stage', 'Live'); - $message = "PUBLISHED: "; - } else { - $message = "DRAFT: "; - } - - return $message . $this->Title; - } -} - -/** - * @deprecated since version 2.0 - */ -class BlogHolder_Controller extends BlogTree_Controller -{ -} diff --git a/code/compat/pages/BlogTree.php b/code/compat/pages/BlogTree.php deleted file mode 100644 index 9fa2617..0000000 --- a/code/compat/pages/BlogTree.php +++ /dev/null @@ -1,56 +0,0 @@ - 'Varchar(255)', - 'LandingPageFreshness' => 'Varchar', - ); - - /** - * {@inheritdoc} - */ - public function canCreate($member = null, $context = array()) - { - return false; - } - - /** - * {@inheritdoc} - */ - public function up() - { - $published = $this->IsPublished(); - if ($this->ClassName === 'BlogTree') { - $this->ClassName = 'Page'; - $this->RecordClassName = 'Page'; - $this->write(); - } - if ($published) { - $this->publish('Stage', 'Live'); - $message = "PUBLISHED: "; - } else { - $message = "DRAFT: "; - } - - return $message . $this->Title; - } -} - -/** - * @deprecated since version 2.0 - */ -class BlogTree_Controller extends Page_Controller -{ -} diff --git a/code/compat/tasks/BlogMigrationTask.php b/code/compat/tasks/BlogMigrationTask.php deleted file mode 100644 index 143fb7c..0000000 --- a/code/compat/tasks/BlogMigrationTask.php +++ /dev/null @@ -1,92 +0,0 @@ -message('Migrating legacy blog records'); - - foreach ($classes as $class) { - $this->upClass($class); - } - } - - /** - * @param string $text - */ - protected function message($text) - { - if (Controller::curr() instanceof DatabaseAdmin) { - DB::alteration_message($text, 'obsolete'); - } else { - echo $text . "
"; - } - } - - /** - * Migrate records of a single class - * - * @param string $class - * @param null|string $stage - */ - protected function upClass($class) - { - if (!class_exists($class)) { - return; - } - - if (is_subclass_of($class, 'SiteTree')) { - $items = SiteTree::get()->filter('ClassName', $class); - } else { - $items = $class::get(); - } - - if ($count = $items->count()) { - $this->message( - sprintf( - 'Migrating %s legacy %s records.', - $count, - $class - ) - ); - - foreach ($items as $item) { - $cancel = $item->extend('onBeforeUp'); - - if ($cancel && min($cancel) === false) { - continue; - } - - /** - * @var MigratableObject $item - */ - $result = $item->up(); - $this->message($result); - - $item->extend('onAfterUp'); - } - } - } - - /** - * {@inheritdoc} - */ - public function down() - { - $this->message('BlogMigrationTask::down() not implemented'); - } -} diff --git a/code/compat/tasks/MigratableObject.php b/code/compat/tasks/MigratableObject.php deleted file mode 100644 index 2c747a8..0000000 --- a/code/compat/tasks/MigratableObject.php +++ /dev/null @@ -1,9 +0,0 @@ - 'Varchar', - ); - - /** - * @var array - */ - private static $only_available_in = array( - 'none', - ); - - /** - * {@inheritdoc} - */ - public function canCreate($member = null) - { - return false; - } - - /** - * {@inheritdoc} - */ - public function up() - { - if ($this->DisplayMode) { - $this->ArchiveType = 'Monthly'; - - if ($this->DisplayMode === 'year') { - $this->ArchiveType = 'Yearly'; - } - } - - $this->ClassName = 'BlogArchiveWidget'; - $this->write(); - return "Migrated " . $this->ArchiveType . " archive widget"; - } -} diff --git a/code/compat/widgets/TagCloudWidget.php b/code/compat/widgets/TagCloudWidget.php deleted file mode 100644 index a527ddd..0000000 --- a/code/compat/widgets/TagCloudWidget.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Varchar', - 'Limit' => 'Int', - 'Sortby' => 'Varchar', - ); - - /** - * @var array - */ - private static $only_available_in = array( - 'none', - ); - - /** - * {@inheritdoc} - */ - public function canCreate($member = null) - { - return false; - } - - /** - * {@inheritdoc} - */ - public function up() - { - $this->ClassName = 'BlogTagsWidget'; - $this->write(); - return "Migrated " . $this->Title . " widget"; - } -} diff --git a/composer.json b/composer.json index 76fae8b..ae08702 100755 --- a/composer.json +++ b/composer.json @@ -1,39 +1,44 @@ { - "name": "silverstripe/blog", - "description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.", - "keywords": [ - "silverstripe", - "blog", - "news" - ], - "type": "silverstripe-module", - "require": { - "silverstripe/cms": "^4.0", - "silverstripe/lumberjack": "^2.0", - "silverstripe/tagfield": "^2.0" - }, - "require-dev": { - "phpunit/PHPUnit": "~4.8" - }, - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, - "license": "BSD-2-Clause", - "authors": [ - { - "name": "Michael Strong", - "email": "github@michaelstrong.co.uk" - } - ], - "suggest": { - "silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.", - "silverstripe/comments": "This module adds comments to your blog." - }, - "replace": { - "micmania1/silverstripe-blog": "*" - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "silverstripe/blog", + "description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.", + "keywords": [ + "silverstripe", + "blog", + "news" + ], + "type": "silverstripe-module", + "require": { + "silverstripe/cms": "^4.0", + "silverstripe/lumberjack": "^2.0", + "silverstripe/tagfield": "^2.0" + }, + "require-dev": { + "phpunit/PHPUnit": "~4.8" + }, + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "SilverStripe\\Blog\\": "src/" + } + }, + "license": "BSD-2-Clause", + "authors": [ + { + "name": "Michael Strong", + "email": "github@michaelstrong.co.uk" + } + ], + "suggest": { + "silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.", + "silverstripe/comments": "This module adds comments to your blog." + }, + "replace": { + "micmania1/silverstripe-blog": "*" + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/.upgrade.yml b/src/.upgrade.yml new file mode 100644 index 0000000..cefd607 --- /dev/null +++ b/src/.upgrade.yml @@ -0,0 +1,28 @@ +mappings: + GridFieldCategorisationConfig: SilverStripe\Blog\Admin\GridFieldCategorisationConfig + GridFieldFormAction: SilverStripe\Blog\Admin\GridFieldFormAction + GridFieldMergeAction: SilverStripe\Blog\Admin\GridFieldMergeAction + BlogCommentExtension: SilverStripe\Blog\Model\BlogCommentExtension + BlogFilter: SilverStripe\Blog\Model\BlogFilter + BlogFilter_GridField: SilverStripe\Blog\Model\BlogFilter_GridField + BlogMemberExtension: SilverStripe\Blog\Model\BlogMemberExtension + BlogPostFilter: SilverStripe\Blog\Model\BlogPostFilter + BlogPostNotifications: SilverStripe\Blog\Model\BlogPostNotifications + Blog: SilverStripe\Blog\Model\Blog + Blog_Controller: SilverStripe\Blog\Controllers\BlogController + BlogController: SilverStripe\Blog\Controllers\BlogController + BlogCategory: SilverStripe\Blog\Model\BlogCategory + BlogPost: SilverStripe\Blog\Model\BlogPost + BlogPost_Controller: SilverStripe\Blog\Controllers\BlogPostController + BlogPostController: SilverStripe\Blog\Controllers\BlogPostController + BlogTag: SilverStripe\Blog\Model\BlogTag + CategorisationObject: SilverStripe\Blog\Model\CategorisationObject + BlogAdminSidebar: SilverStripe\Blog\Forms\BlogAdminSidebar + GridFieldAddByDBField: SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField + GridFieldBlogPostState: SilverStripe\Blog\Forms\GridField\GridFieldBlogPostState + GridFieldConfig_BlogPost: SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost + BlogArchiveWidget: SilverStripe\Blog\Widgets\BlogArchiveWidget + BlogCategoriesWidget: SilverStripe\Blog\Widgets\BlogCategoriesWidget + BlogRecentPostsWidget: SilverStripe\Blog\Widgets\BlogRecentPostsWidget + BlogTagsCloudWidget: SilverStripe\Blog\Widgets\BlogTagsCloudWidget + BlogTagsWidget: SilverStripe\Blog\Widgets\BlogTagsWidget diff --git a/code/admin/GridFieldCategorisationConfig.php b/src/Admin/GridFieldCategorisationConfig.php similarity index 72% rename from code/admin/GridFieldCategorisationConfig.php rename to src/Admin/GridFieldCategorisationConfig.php index e390bff..0b0f88f 100644 --- a/code/admin/GridFieldCategorisationConfig.php +++ b/src/Admin/GridFieldCategorisationConfig.php @@ -1,5 +1,12 @@ getComponentByType('GridFieldDataColumns'); - $columns->setDisplayFields(array( - 'Title' => 'Title', - 'BlogPostsCount' => 'Posts', - 'MergeAction' => 'MergeAction', - 'Actions' => 'Actions', - )); + $columns->setDisplayFields( + array( + 'Title' => 'Title', + 'BlogPostsCount' => 'Posts', + 'MergeAction' => 'MergeAction', + 'Actions' => 'Actions' + ) + ); } } diff --git a/code/admin/GridFieldFormAction.php b/src/Admin/GridFieldFormAction.php similarity index 89% rename from code/admin/GridFieldFormAction.php rename to src/Admin/GridFieldFormAction.php index 47d448f..e48ba80 100644 --- a/code/admin/GridFieldFormAction.php +++ b/src/Admin/GridFieldFormAction.php @@ -1,5 +1,9 @@ 'tag', + 'category/$Category!/$Rss' => 'category', + 'archive/$Year!/$Month/$Day' => 'archive', + 'profile/$URLSegment!' => 'profile' + ); + + /** + * @var array + */ + private static $casting = array( + 'MetaTitle' => 'Text', + 'FilterDescription' => 'Text' + ); + + /** + * The current Blog Post DataList query. + * + * @var DataList + */ + protected $blogPosts; + + /** + * @return string + */ + public function index() + { + /** + * @var Blog $dataRecord + */ + $dataRecord = $this->dataRecord; + + $this->blogPosts = $dataRecord->getBlogPosts(); + + return $this->render(); + } + + /** + * Renders a Blog Member's profile. + * + * @return SS_HTTPResponse + */ + public function profile() + { + $profile = $this->getCurrentProfile(); + + if (!$profile) { + return $this->httpError(404, 'Not Found'); + } + + $this->blogPosts = $this->getCurrentProfilePosts(); + + return $this->render(); + } + + /** + * Get the Member associated with the current URL segment. + * + * @return null|Member + */ + public function getCurrentProfile() + { + $urlSegment = $this->request->param('URLSegment'); + + if ($urlSegment) { + return Member::get() + ->filter('URLSegment', $urlSegment) + ->first(); + } + + return null; + } + + /** + * Get posts related to the current Member profile. + * + * @return null|DataList + */ + public function getCurrentProfilePosts() + { + $profile = $this->getCurrentProfile(); + + if ($profile) { + return $profile->BlogPosts()->filter('ParentID', $this->ID); + } + + return null; + } + + /** + * Renders an archive for a specified date. This can be by year or year/month. + * + * @return null|SS_HTTPResponse + */ + public function archive() + { + /** + * @var Blog $dataRecord + */ + $dataRecord = $this->dataRecord; + + $year = $this->getArchiveYear(); + $month = $this->getArchiveMonth(); + $day = $this->getArchiveDay(); + + if ($this->request->param('Month') && !$month) { + $this->httpError(404, 'Not Found'); + } + + if ($month && $this->request->param('Day') && !$day) { + $this->httpError(404, 'Not Found'); + } + + if ($year) { + $this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day); + + return $this->render(); + } + + $this->httpError(404, 'Not Found'); + + return null; + } + + /** + * Fetches the archive year from the url. + * + * @return int + */ + public function getArchiveYear() + { + if ($this->request->param('Year')) { + if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) { + return (int) $year; + } + } elseif ($this->request->param('Action') == 'archive') { + return DBDatetime::now()->Year(); + } + + return null; + } + + /** + * Fetches the archive money from the url. + * + * @return null|int + */ + public function getArchiveMonth() + { + $month = $this->request->param('Month'); + + if (preg_match('/^[0-9]{1,2}$/', $month)) { + if ($month > 0 && $month < 13) { + if (checkdate($month, 01, $this->getArchiveYear())) { + return (int) $month; + } + } + } + + return null; + } + + /** + * Fetches the archive day from the url. + * + * @return null|int + */ + public function getArchiveDay() + { + $day = $this->request->param('Day'); + + if (preg_match('/^[0-9]{1,2}$/', $day)) { + if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) { + return (int) $day; + } + } + + return null; + } + + /** + * Renders the blog posts for a given tag. + * + * @return null|HTTPResponse + */ + public function tag() + { + $tag = $this->getCurrentTag(); + + if ($tag) { + $this->blogPosts = $tag->BlogPosts(); + + if($this->isRSS()) { + return $this->rssFeed($this->blogPosts, $tag->getLink()); + } else { + return $this->render(); + } + } + + $this->httpError(404, 'Not Found'); + + return null; + } + + /** + * Tag Getter for use in templates. + * + * @return null|BlogTag + */ + public function getCurrentTag() + { + /** + * @var Blog $dataRecord + */ + $dataRecord = $this->dataRecord; + $tag = $this->request->param('Tag'); + if ($tag) { + return $dataRecord->Tags() + ->filter('URLSegment', array($tag, rawurlencode($tag))) + ->first(); + } + return null; + } + + /** + * Renders the blog posts for a given category. + * + * @return null|SS_HTTPResponse + */ + public function category() + { + $category = $this->getCurrentCategory(); + + if ($category) { + $this->blogPosts = $category->BlogPosts(); + + if($this->isRSS()) { + return $this->rssFeed($this->blogPosts, $category->getLink()); + } else { + return $this->render(); + } + } + + $this->httpError(404, 'Not Found'); + + return null; + } + + /** + * Category Getter for use in templates. + * + * @return null|BlogCategory + */ + public function getCurrentCategory() + { + /** + * @var Blog $dataRecord + */ + $dataRecord = $this->dataRecord; + $category = $this->request->param('Category'); + if ($category) { + return $dataRecord->Categories() + ->filter('URLSegment', array($category, rawurlencode($category))) + ->first(); + } + return null; + } + + /** + * Get the meta title for the current action. + * + * @return string + */ + public function getMetaTitle() + { + $title = $this->data()->getTitle(); + $filter = $this->getFilterDescription(); + + if ($filter) { + $title = sprintf('%s - %s', $title, $filter); + } + + $this->extend('updateMetaTitle', $title); + + return $title; + } + + /** + * Returns a description of the current filter. + * + * @return string + */ + public function getFilterDescription() + { + $items = array(); + + $list = $this->PaginatedList(); + $currentPage = $list->CurrentPage(); + + if ($currentPage > 1) { + $items[] = _t( + 'Blog.FILTERDESCRIPTION_PAGE', + 'Page {page}', + null, + array( + 'page' => $currentPage + ) + ); + } + + if ($author = $this->getCurrentProfile()) { + $items[] = _t( + 'Blog.FILTERDESCRIPTION_AUTHOR', + 'By {author}', + null, + array( + 'author' => $author->Title + ) + ); + } + + if ($tag = $this->getCurrentTag()) { + $items[] = _t( + 'Blog.FILTERDESCRIPTION_TAG', + 'Tagged with {tag}', + null, + array( + 'tag' => $tag->Title + ) + ); + } + + if ($category = $this->getCurrentCategory()) { + $items[] = _t( + 'Blog.FILTERDESCRIPTION_CATEGORY', + 'In category {category}', + null, + array( + 'category' => $category->Title + ) + ); + } + + if ($this->owner->getArchiveYear()) { + if ($this->owner->getArchiveDay()) { + $date = $this->owner->getArchiveDate()->Nice(); + } elseif ($this->owner->getArchiveMonth()) { + $date = $this->owner->getArchiveDate()->format('F, Y'); + } else { + $date = $this->owner->getArchiveDate()->format('Y'); + } + + $items[] = _t( + 'Blog.FILTERDESCRIPTION_DATE', + 'In {date}', + null, + array( + 'date' => $date, + ) + ); + } + + $result = ''; + + if ($items) { + $result = implode(', ', $items); + } + + $this->extend('updateFilterDescription', $result); + + return $result; + } + + /** + * Returns a list of paginated blog posts based on the BlogPost dataList. + * + * @return PaginatedList + */ + public function PaginatedList() + { + $allPosts = $this->blogPosts ?: ArrayList::create(); + + $posts = PaginatedList::create($allPosts); + + // Set appropriate page size + if ($this->PostsPerPage > 0) { + $pageSize = $this->PostsPerPage; + } elseif ($count = $allPosts->count()) { + $pageSize = $count; + } else { + $pageSize = 99999; + } + $posts->setPageLength($pageSize); + + // Set current page + $start = $this->request->getVar($posts->getPaginationGetVar()); + $posts->setPageStart($start); + + return $posts; + } + + /** + * Displays an RSS feed of blog posts. + * + * @return string + */ + public function rss() + { + /** + * @var Blog $dataRecord + */ + $dataRecord = $this->dataRecord; + + $this->blogPosts = $dataRecord->getBlogPosts(); + + return $this->rssFeed($this->blogPosts, $this->Link()); + } + + /** + * Returns the current archive date. + * + * @return null|Date + */ + public function getArchiveDate() + { + $year = $this->getArchiveYear(); + $month = $this->getArchiveMonth(); + $day = $this->getArchiveDay(); + + if ($year) { + if ($month) { + $date = sprintf('%s-%s-01', $year, $month); + + if ($day) { + $date = sprintf('%s-%s-%s', $year, $month, $day); + } + } else { + $date = sprintf('%s-01-01', $year); + } + + $obj = DBDatetime::create('date'); + $obj->setValue($date); + return $obj; + } + + return null; + } + + /** + * Returns a link to the RSS feed. + * + * @return string + */ + public function getRSSLink() + { + return $this->Link('rss'); + } + + /** + * Displays an RSS feed of the given blog posts. + * + * @param DataList $blogPosts + * @param string $link + * + * @return string + */ + protected function rssFeed($blogPosts, $link) + { + $rss = new RSSFeed($blogPosts, $link, $this->MetaTitle, $this->MetaDescription); + + $this->extend('updateRss', $rss); + + return $rss->outputToBrowser(); + } + + /** + * Returns true if the $Rss sub-action for categories/tags has been set to "rss" + * + * @return bool + */ + protected function isRSS() + { + $rss = $this->request->param('Rss'); + return (is_string($rss) && strcasecmp($rss, 'rss') == 0); + } +} diff --git a/src/Controllers/BlogPostController.php b/src/Controllers/BlogPostController.php new file mode 100644 index 0000000..56f7dc2 --- /dev/null +++ b/src/Controllers/BlogPostController.php @@ -0,0 +1,14 @@ +Fields->push($addAction); return array( - $this->targetFragment => $forTemplate->renderWith('GridFieldAddByDBField') + $this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Form\\GridField\\GridFieldAddByDBField') ); } } diff --git a/code/forms/gridfield/GridFieldBlogPostState.php b/src/Forms/GridField/GridFieldBlogPostState.php similarity index 94% rename from code/forms/gridfield/GridFieldBlogPostState.php rename to src/Forms/GridField/GridFieldBlogPostState.php index 3d01ce4..609f014 100644 --- a/code/forms/gridfield/GridFieldBlogPostState.php +++ b/src/Forms/GridField/GridFieldBlogPostState.php @@ -1,5 +1,12 @@ 'BlogTag', - 'Categories' => 'BlogCategory', + 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', + 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', ); /** * @var array */ private static $many_many = array( - 'Editors' => 'Member', - 'Writers' => 'Member', - 'Contributors' => 'Member', + 'Editors' => 'SilverStripe\\Security\\Member', + 'Writers' => 'SilverStripe\\Security\\Member', + 'Contributors' => 'SilverStripe\\Security\\Member', ); /** * @var array */ private static $allowed_children = array( - 'BlogPost', + 'SilverStripe\\Blog\\Model\\BlogPost', ); /** * @var array */ private static $extensions = array( - 'BlogFilter', + 'SilverStripe\\Blog\\Model\\BlogFilter', ); /** @@ -95,7 +123,7 @@ class Blog extends Page implements PermissionProvider */ private static $defaults = array( 'ProvideComments' => false, - 'PostsPerPage' => 10, + 'PostsPerPage' => 10 ); /** @@ -124,14 +152,14 @@ class Blog extends Page implements PermissionProvider 'Categories', _t('Blog.Categories', 'Categories'), $self->Categories(), - GridFieldCategorisationConfig::create(15, $self->Categories()->sort('Title'), 'BlogCategory', 'Categories', 'BlogPosts') + GridFieldCategorisationConfig::create(15, $self->Categories()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories', 'BlogPosts') ); $tags = GridField::create( 'Tags', _t('Blog.Tags', 'Tags'), $self->Tags(), - GridFieldCategorisationConfig::create(15, $self->Tags()->sort('Title'), 'BlogTag', 'Tags', 'BlogPosts') + GridFieldCategorisationConfig::create(15, $self->Tags()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags', 'BlogPosts') ); /** @@ -473,7 +501,7 @@ class Blog extends Page implements PermissionProvider $stage = '_' . $stage; } - $query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)); + $query->innerJoin('SilverStripe\\Blog\\Model\\BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)); $conn = DB::getConn(); @@ -624,512 +652,3 @@ class Blog extends Page implements PermissionProvider return $group; } } - -/** - * @package silverstripe - * @subpackage blog - */ -class Blog_Controller extends Page_Controller -{ - /** - * @var array - */ - private static $allowed_actions = array( - 'archive', - 'tag', - 'category', - 'rss', - 'profile', - ); - - /** - * @var array - */ - private static $url_handlers = array( - 'tag/$Tag!/$Rss' => 'tag', - 'category/$Category!/$Rss' => 'category', - 'archive/$Year!/$Month/$Day' => 'archive', - 'profile/$URLSegment!' => 'profile', - ); - - /** - * @var array - */ - private static $casting = array( - 'MetaTitle' => 'Text', - 'FilterDescription' => 'Text', - ); - - /** - * The current Blog Post DataList query. - * - * @var DataList - */ - protected $blogPosts; - - /** - * @return string - */ - public function index() - { - /** - * @var Blog $dataRecord - */ - $dataRecord = $this->dataRecord; - - $this->blogPosts = $dataRecord->getBlogPosts(); - - return $this->render(); - } - - /** - * Renders a Blog Member's profile. - * - * @return SS_HTTPResponse - */ - public function profile() - { - $profile = $this->getCurrentProfile(); - - if (!$profile) { - return $this->httpError(404, 'Not Found'); - } - - $this->blogPosts = $this->getCurrentProfilePosts(); - - return $this->render(); - } - - /** - * Get the Member associated with the current URL segment. - * - * @return null|Member - */ - public function getCurrentProfile() - { - $urlSegment = $this->request->param('URLSegment'); - - if ($urlSegment) { - return Member::get() - ->filter('URLSegment', $urlSegment) - ->first(); - } - - return null; - } - - /** - * Get posts related to the current Member profile. - * - * @return null|DataList - */ - public function getCurrentProfilePosts() - { - $profile = $this->getCurrentProfile(); - - if ($profile) { - return $profile->BlogPosts()->filter('ParentID', $this->ID); - } - - return null; - } - - /** - * Renders an archive for a specified date. This can be by year or year/month. - * - * @return null|SS_HTTPResponse - */ - public function archive() - { - /** - * @var Blog $dataRecord - */ - $dataRecord = $this->dataRecord; - - $year = $this->getArchiveYear(); - $month = $this->getArchiveMonth(); - $day = $this->getArchiveDay(); - - if ($this->request->param('Month') && !$month) { - $this->httpError(404, 'Not Found'); - } - - if ($month && $this->request->param('Day') && !$day) { - $this->httpError(404, 'Not Found'); - } - - if ($year) { - $this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day); - - return $this->render(); - } - - $this->httpError(404, 'Not Found'); - - return null; - } - - /** - * Fetches the archive year from the url. - * - * @return int - */ - public function getArchiveYear() - { - if ($this->request->param('Year')) { - if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) { - return (int) $year; - } - } elseif ($this->request->param('Action') == 'archive') { - return SS_Datetime::now()->Year(); - } - - return null; - } - - /** - * Fetches the archive money from the url. - * - * @return null|int - */ - public function getArchiveMonth() - { - $month = $this->request->param('Month'); - - if (preg_match('/^[0-9]{1,2}$/', $month)) { - if ($month > 0 && $month < 13) { - if (checkdate($month, 01, $this->getArchiveYear())) { - return (int) $month; - } - } - } - - return null; - } - - /** - * Fetches the archive day from the url. - * - * @return null|int - */ - public function getArchiveDay() - { - $day = $this->request->param('Day'); - - if (preg_match('/^[0-9]{1,2}$/', $day)) { - if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) { - return (int) $day; - } - } - - return null; - } - - /** - * Renders the blog posts for a given tag. - * - * @return null|SS_HTTPResponse - */ - public function tag() - { - $tag = $this->getCurrentTag(); - - if ($tag) { - $this->blogPosts = $tag->BlogPosts(); - - if($this->isRSS()) { - return $this->rssFeed($this->blogPosts, $tag->getLink()); - } else { - return $this->render(); - } - } - - $this->httpError(404, 'Not Found'); - - return null; - } - - /** - * Tag Getter for use in templates. - * - * @return null|BlogTag - */ - public function getCurrentTag() - { - /** - * @var Blog $dataRecord - */ - $dataRecord = $this->dataRecord; - $tag = $this->request->param('Tag'); - if ($tag) { - return $dataRecord->Tags() - ->filter('URLSegment', array($tag, rawurlencode($tag))) - ->first(); - } - return null; - } - - /** - * Renders the blog posts for a given category. - * - * @return null|SS_HTTPResponse - */ - public function category() - { - $category = $this->getCurrentCategory(); - - if ($category) { - $this->blogPosts = $category->BlogPosts(); - - if($this->isRSS()) { - return $this->rssFeed($this->blogPosts, $category->getLink()); - } else { - return $this->render(); - } - } - - $this->httpError(404, 'Not Found'); - - return null; - } - - /** - * Category Getter for use in templates. - * - * @return null|BlogCategory - */ - public function getCurrentCategory() - { - /** - * @var Blog $dataRecord - */ - $dataRecord = $this->dataRecord; - $category = $this->request->param('Category'); - if ($category) { - return $dataRecord->Categories() - ->filter('URLSegment', array($category, rawurlencode($category))) - ->first(); - } - return null; - } - - /** - * Get the meta title for the current action. - * - * @return string - */ - public function getMetaTitle() - { - $title = $this->data()->getTitle(); - $filter = $this->getFilterDescription(); - - if ($filter) { - $title = sprintf('%s - %s', $title, $filter); - } - - $this->extend('updateMetaTitle', $title); - - return $title; - } - - /** - * Returns a description of the current filter. - * - * @return string - */ - public function getFilterDescription() - { - $items = array(); - - $list = $this->PaginatedList(); - $currentPage = $list->CurrentPage(); - - if ($currentPage > 1) { - $items[] = _t( - 'Blog.FILTERDESCRIPTION_PAGE', - 'Page {page}', - null, - array( - 'page' => $currentPage, - ) - ); - } - - if ($author = $this->getCurrentProfile()) { - $items[] = _t( - 'Blog.FILTERDESCRIPTION_AUTHOR', - 'By {author}', - null, - array( - 'author' => $author->Title, - ) - ); - } - - if ($tag = $this->getCurrentTag()) { - $items[] = _t( - 'Blog.FILTERDESCRIPTION_TAG', - 'Tagged with {tag}', - null, - array( - 'tag' => $tag->Title, - ) - ); - } - - if ($category = $this->getCurrentCategory()) { - $items[] = _t( - 'Blog.FILTERDESCRIPTION_CATEGORY', - 'In category {category}', - null, - array( - 'category' => $category->Title, - ) - ); - } - - if ($this->owner->getArchiveYear()) { - if ($this->owner->getArchiveDay()) { - $date = $this->owner->getArchiveDate()->Nice(); - } elseif ($this->owner->getArchiveMonth()) { - $date = $this->owner->getArchiveDate()->format('F, Y'); - } else { - $date = $this->owner->getArchiveDate()->format('Y'); - } - - $items[] = _t( - 'Blog.FILTERDESCRIPTION_DATE', - 'In {date}', - null, - array( - 'date' => $date, - ) - ); - } - - $result = ''; - - if ($items) { - $result = implode(', ', $items); - } - - $this->extend('updateFilterDescription', $result); - - return $result; - } - - /** - * Returns a list of paginated blog posts based on the BlogPost dataList. - * - * @return PaginatedList - */ - public function PaginatedList() - { - $allPosts = $this->blogPosts ?: new ArrayList(); - - $posts = new PaginatedList($allPosts); - - // Set appropriate page size - if ($this->PostsPerPage > 0) { - $pageSize = $this->PostsPerPage; - } elseif ($count = $allPosts->count()) { - $pageSize = $count; - } else { - $pageSize = 99999; - } - $posts->setPageLength($pageSize); - - // Set current page - $start = $this->request->getVar($posts->getPaginationGetVar()); - $posts->setPageStart($start); - - return $posts; - } - - /** - * Displays an RSS feed of blog posts. - * - * @return string - */ - public function rss() - { - /** - * @var Blog $dataRecord - */ - $dataRecord = $this->dataRecord; - - $this->blogPosts = $dataRecord->getBlogPosts(); - - return $this->rssFeed($this->blogPosts, $this->Link()); - } - - /** - * Returns the current archive date. - * - * @return null|Date - */ - public function getArchiveDate() - { - $year = $this->getArchiveYear(); - $month = $this->getArchiveMonth(); - $day = $this->getArchiveDay(); - - if ($year) { - if ($month) { - $date = sprintf('%s-%s-01', $year, $month); - - if ($day) { - $date = sprintf('%s-%s-%s', $year, $month, $day); - } - } else { - $date = sprintf('%s-01-01', $year); - } - - $obj = new DBDatetime('date'); - $obj->setValue($date); - return $obj; - } - - return null; - } - - /** - * Returns a link to the RSS feed. - * - * @return string - */ - public function getRSSLink() - { - return $this->Link('rss'); - } - - /** - * Displays an RSS feed of the given blog posts. - * - * @param DataList $blogPosts - * @param string $link - * - * @return string - */ - protected function rssFeed($blogPosts, $link) - { - $rss = new RSSFeed($blogPosts, $link, $this->MetaTitle, $this->MetaDescription); - - $this->extend('updateRss', $rss); - - return $rss->outputToBrowser(); - } - - /** - * Returns true if the $Rss sub-action for categories/tags has been set to "rss" - */ - private function isRSS() - { - $rss = $this->request->param('Rss'); - if(is_string($rss) && strcasecmp($rss, "rss") == 0) { - return true; - } else { - return false; - } - } -} diff --git a/code/model/BlogCategory.php b/src/Model/BlogCategory.php similarity index 71% rename from code/model/BlogCategory.php rename to src/Model/BlogCategory.php index c4ea804..28b6dd5 100644 --- a/code/model/BlogCategory.php +++ b/src/Model/BlogCategory.php @@ -1,5 +1,11 @@ 'Varchar(255)', - 'URLSegment' => 'Varchar(255)', + 'Title' => 'Varchar(255)', + 'URLSegment' => 'Varchar(255)' ); /** * @var array */ private static $has_one = array( - 'Blog' => 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'BlogPost', + 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', ); /** diff --git a/code/extensions/BlogCommentExtension.php b/src/Model/BlogCommentExtension.php similarity index 82% rename from code/extensions/BlogCommentExtension.php rename to src/Model/BlogCommentExtension.php index de4576a..9768a60 100644 --- a/code/extensions/BlogCommentExtension.php +++ b/src/Model/BlogCommentExtension.php @@ -1,5 +1,10 @@ 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); } @@ -40,7 +55,7 @@ class BlogFilter extends Lumberjack */ protected function subclassForBlog() { - return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog')); + return in_array(get_class($this->owner), ClassInfo::subclassesFor('Blog')); } /** @@ -53,7 +68,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); } @@ -82,14 +97,14 @@ class BlogFilter extends Lumberjack 'ClassName' => $excluded )); - $gridField = new BlogFilter_GridField( + $gridField = BlogFilter_GridField::create( 'ChildPages', $this->getLumberjackTitle(), $pages, $this->getLumberjackGridFieldConfig() ); - $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField); + $tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField); $fields->insertBefore($tab, 'Main'); } diff --git a/code/extensions/BlogMemberExtension.php b/src/Model/BlogMemberExtension.php similarity index 81% rename from code/extensions/BlogMemberExtension.php rename to src/Model/BlogMemberExtension.php index 1a3f2d7..eb2c152 100644 --- a/code/extensions/BlogMemberExtension.php +++ b/src/Model/BlogMemberExtension.php @@ -1,5 +1,16 @@ 'BlogPost', + 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', ); /** @@ -80,7 +91,6 @@ class BlogMemberExtension extends DataExtension return $conflict->count() == 0; } - /** * {@inheritdoc} */ @@ -97,13 +107,13 @@ class BlogMemberExtension extends DataExtension Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); - $tab = new Tab('BlogPosts', 'Blog Posts'); + $tab = Tab::create('BlogPosts', 'Blog Posts'); - $gridField = new GridField( + $gridField = GridField::create( 'BlogPosts', 'Blog Posts', $this->owner->BlogPosts(), - new GridFieldConfig_BlogPost() + GridFieldConfig_BlogPost::create() ); $tab->Fields()->add($gridField); diff --git a/code/traits/BlogObject.php b/src/Model/BlogObject.php similarity index 82% rename from code/traits/BlogObject.php rename to src/Model/BlogObject.php index 1d0b091..07fd0d1 100644 --- a/code/traits/BlogObject.php +++ b/src/Model/BlogObject.php @@ -1,13 +1,24 @@ valid()) { + if (!$validation->isValid()) { return $validation; } $blog = $this->Blog(); - if(!$blog || !$blog->exists()) { + if (!$blog || !$blog->exists()) { return $validation; } - if($this->getDuplicatesByUrlSegment()->count() > 0) { - $validation->error($this->getDuplicateError(), self::DUPLICATE_EXCEPTION); + if ($this->getDuplicatesByUrlSegment()->count() > 0) { + $validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION); } return $validation; } @@ -163,7 +176,7 @@ trait BlogObject { public function generateURLSegment($increment = 0) { $increment = (int) $increment; - $filter = new URLSegmentFilter(); + $filter = URLSegmentFilter::create(); $this->URLSegment = $filter->filter($this->owner->Title); @@ -185,10 +198,13 @@ trait BlogObject { */ protected function getDuplicatesByUrlSegment() { - $duplicates = DataList::create(self::class)->filter(array( - 'URLSegment' => $this->URLSegment, - 'BlogID' => (int) $this->BlogID, - )); + $duplicates = DataList::create(self::class) + ->filter( + array( + 'URLSegment' => $this->URLSegment, + 'BlogID' => (int) $this->BlogID, + ) + ); if ($this->ID) { $duplicates = $duplicates->exclude('ID', $this->ID); @@ -217,5 +233,4 @@ trait BlogObject { * @return string */ abstract protected function getDuplicateError(); - } diff --git a/code/model/BlogPost.php b/src/Model/BlogPost.php similarity index 91% rename from code/model/BlogPost.php rename to src/Model/BlogPost.php index 4f5abb8..aaf93af 100644 --- a/code/model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -1,5 +1,27 @@ 'SS_Datetime', + 'PublishDate' => 'Datetime', 'AuthorNames' => 'Varchar(1024)', - 'Summary' => 'HTMLText', + 'Summary' => 'HTMLText', ); /** * @var array */ private static $has_one = array( - 'FeaturedImage' => 'Image', + 'FeaturedImage' => 'SilverStripe\\Assets\\Image', ); /** * @var array */ private static $many_many = array( - 'Categories' => 'BlogCategory', - 'Tags' => 'BlogTag', - 'Authors' => 'Member', + 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', + 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', + 'Authors' => 'SilverStripe\\Security\\Member', ); /** * @var array */ private static $defaults = array( - 'ShowInMenus' => false, - 'InheritSideBar' => true, + 'ShowInMenus' => false, + 'InheritSideBar' => true, 'ProvideComments' => true, ); @@ -62,21 +90,21 @@ class BlogPost extends Page * @var array */ private static $extensions = array( - 'BlogPostFilter', + 'SilverStripe\\Blog\\Model\\BlogPostFilter' ); /** * @var array */ private static $searchable_fields = array( - 'Title', + 'Title' ); /** * @var array */ private static $summary_fields = array( - 'Title', + 'Title' ); /** @@ -84,7 +112,7 @@ class BlogPost extends Page */ private static $casting = array( 'Excerpt' => 'HTMLText', - 'Date' => 'SS_Datetime', + 'Date' => 'SS_Datetime' ); /** @@ -412,12 +440,12 @@ class BlogPost extends Page public function onBeforePublish() { /** - * @var SS_Datetime $publishDate + * @var DBDatetime $publishDate */ $publishDate = $this->dbObject('PublishDate'); if (!$publishDate->getValue()) { - $this->PublishDate = SS_Datetime::now()->getValue(); + $this->PublishDate = DBDatetime::now()->getValue(); $this->write(); } } @@ -464,7 +492,7 @@ class BlogPost extends Page } /** - * @var SS_Datetime $publishDate + * @var DBDatetime $publishDate */ $publishDate = $this->dbObject('PublishDate'); if(!$publishDate->exists()) { @@ -563,7 +591,7 @@ class BlogPost extends Page public function getMonthlyArchiveLink($type = 'day') { /** - * @var SS_Datetime $date + * @var DBDatetime $date */ $date = $this->dbObject('PublishDate'); @@ -591,7 +619,7 @@ class BlogPost extends Page public function getYearlyArchiveLink() { /** - * @var SS_Datetime $date + * @var DBDatetime $date */ $date = $this->dbObject('PublishDate'); @@ -706,11 +734,3 @@ class BlogPost extends Page } } } - -/** - * @package silverstripe - * @subpackage blog - */ -class BlogPost_Controller extends Page_Controller -{ -} diff --git a/code/extensions/BlogPostFilter.php b/src/Model/BlogPostFilter.php similarity index 64% rename from code/extensions/BlogPostFilter.php rename to src/Model/BlogPostFilter.php index 26949eb..3efd13a 100644 --- a/code/extensions/BlogPostFilter.php +++ b/src/Model/BlogPostFilter.php @@ -1,5 +1,17 @@ addWhere(sprintf( '"PublishDate" < \'%s\'', - Convert::raw2sql(SS_Datetime::now()) + Convert::raw2sql(DBDatetime::now()) )); } } /** + * {@inheritDoc} + * * This is a fix so that when we try to fetch subclasses of BlogPost, lazy loading includes the * BlogPost table in its query. Leaving this table out means the default sort order column * PublishDate causes an error. * * @see https://github.com/silverstripe/silverstripe-framework/issues/1682 * - * @param SQLQuery $query - * @param mixed $dataQuery - * @param mixed $parent + * @param SQLSelect $query + * @param DataQuery $dataQuery + * @param DataObject $dataObject */ - public function augmentLoadLazyFields( - SQLSelect &$query, - DataQuery &$dataQuery = null, - $dataObject - ) { + public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) + { $dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"'); } } diff --git a/code/extensions/BlogPostNotifications.php b/src/Model/BlogPostNotifications.php similarity index 91% rename from code/extensions/BlogPostNotifications.php rename to src/Model/BlogPostNotifications.php index e3d7ca2..733c338 100644 --- a/code/extensions/BlogPostNotifications.php +++ b/src/Model/BlogPostNotifications.php @@ -1,5 +1,9 @@ 'Varchar(255)', - 'URLSegment' => 'Varchar(255)', + 'Title' => 'Varchar(255)', + 'URLSegment' => 'Varchar(255)' ); /** * @var array */ private static $has_one = array( - 'Blog' => 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'BlogPost', + 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', ); /** diff --git a/code/model/CategorisationObject.php b/src/Model/CategorisationObject.php similarity index 69% rename from code/model/CategorisationObject.php rename to src/Model/CategorisationObject.php index 811419e..827035b 100644 --- a/code/model/CategorisationObject.php +++ b/src/Model/CategorisationObject.php @@ -1,8 +1,11 @@ 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** @@ -72,7 +76,7 @@ class BlogArchiveWidget extends Widget * @var FieldList $fields */ $fields->merge(array( - DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'Blog'), Blog::get()->map()), + DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()), DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type), NumericField::create('NumberToDisplay', _t('BlogArchiveWidget.NumberToDisplay', 'No. to Display')) )); diff --git a/code/widgets/BlogCategoriesWidget.php b/src/Widgets/BlogCategoriesWidget.php similarity index 90% rename from code/widgets/BlogCategoriesWidget.php rename to src/Widgets/BlogCategoriesWidget.php index 1429dab..6cc1ccc 100644 --- a/code/widgets/BlogCategoriesWidget.php +++ b/src/Widgets/BlogCategoriesWidget.php @@ -1,6 +1,10 @@ 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** @@ -47,7 +51,7 @@ class BlogCategoriesWidget extends Widget { $this->beforeUpdateCMSFields(function (FieldList $fields) { $fields[] = DropdownField::create( - 'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map() + 'BlogID', _t('BlogCategoriesWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map() ); $fields[] = NumericField::create( diff --git a/code/widgets/BlogRecentPostsWidget.php b/src/Widgets/BlogRecentPostsWidget.php similarity index 86% rename from code/widgets/BlogRecentPostsWidget.php rename to src/Widgets/BlogRecentPostsWidget.php index 2456cb4..a097fda 100644 --- a/code/widgets/BlogRecentPostsWidget.php +++ b/src/Widgets/BlogRecentPostsWidget.php @@ -1,6 +1,10 @@ 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** @@ -50,7 +54,7 @@ class BlogRecentPostsWidget extends Widget * @var FieldList $fields */ $fields->merge(array( - DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()), + DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()), NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts')) )); }); diff --git a/code/widgets/BlogTagsCloudWidget.php b/src/Widgets/BlogTagsCloudWidget.php similarity index 92% rename from code/widgets/BlogTagsCloudWidget.php rename to src/Widgets/BlogTagsCloudWidget.php index 7f81e3e..baf2805 100644 --- a/code/widgets/BlogTagsCloudWidget.php +++ b/src/Widgets/BlogTagsCloudWidget.php @@ -1,5 +1,9 @@ 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** @@ -47,7 +51,7 @@ class BlogTagsCloudWidget extends Widget */ $fields->push( DropdownField::create('BlogID', _t('BlogTagsCloudWidget.Blog', - 'Blog'), Blog::get()->map()) + 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()) ); }); diff --git a/code/widgets/BlogTagsWidget.php b/src/Widgets/BlogTagsWidget.php similarity index 90% rename from code/widgets/BlogTagsWidget.php rename to src/Widgets/BlogTagsWidget.php index f2b4677..bcc2564 100644 --- a/code/widgets/BlogTagsWidget.php +++ b/src/Widgets/BlogTagsWidget.php @@ -1,6 +1,10 @@ 'Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', ); /** @@ -47,7 +51,7 @@ class BlogTagsWidget extends Widget { $this->beforeUpdateCMSFields(function (Fieldlist $fields) { $fields[] = DropdownField::create( - 'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map() + 'BlogID', _t('BlogTagsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map() ); $fields[] = NumericField::create( diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index c40e976..2c1d0cb 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -1,5 +1,13 @@ logout(); } - $this->objFromFixture('BlogPost', 'FirstBlogPost'); + $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); /** * @var BlogCategory $category */ - $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); } @@ -72,10 +80,10 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $this->objFromFixture('Member', 'Admin'); + $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('Member', 'Editor'); - $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); + $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); } @@ -87,20 +95,20 @@ 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'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); - $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); - $category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); @@ -110,10 +118,10 @@ 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'); + $category = singleton('SilverStripe\\Blog\\Model\\BlogCategory'); $this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.'); $this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); @@ -123,24 +131,25 @@ 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'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); - $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); - $category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); + $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); } - public function testDuplicateCategories() { + public function testDuplicateCategories() + { $blog = new Blog(); $blog->Title = 'Testing for duplicate categories'; $blog->write(); @@ -159,9 +168,9 @@ class BlogCategoryTest extends FunctionalTest $category->write(); $this->fail('Duplicate BlogCategory written'); } catch (ValidationException $e) { - $codeList = $e->getResult()->codeList(); - $this->assertCount(1, $codeList); - $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]); + $messages = $e->getResult()->getMessages(); + $this->assertCount(1, $messages); + $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']); } } } diff --git a/tests/BlogPostFilterTest.php b/tests/BlogPostFilterTest.php index e878e40..a43026d 100755 --- a/tests/BlogPostFilterTest.php +++ b/tests/BlogPostFilterTest.php @@ -1,5 +1,9 @@ objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $this->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..417502b 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -1,8 +1,11 @@ markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture('BlogPost', 'PostC'); + $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); $comment = new Comment(); $comment->Comment = 'This is a comment'; $comment->write(); @@ -27,8 +30,10 @@ class BlogPostNotificationsTest extends SapphireTest } sort($segments); - $this->assertEquals(array('blog-contributor', 'blog-editor', - 'blog-writer', ), $segments); + $this->assertEquals( + array('blog-contributor', 'blog-editor', 'blog-writer'), + $segments + ); } public function testUpdateNotificationSubject() @@ -36,7 +41,7 @@ class BlogPostNotificationsTest extends SapphireTest if (!class_exists('CommentNotifier')) { $this->markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture('BlogPost', 'PostC'); + $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); $comment = new Comment(); $comment->Comment = 'This is a comment'; $comment->write(); diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index c527604..a5c5a69 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -1,8 +1,13 @@ objFromFixture('Member', $user); - $pageRecord = $this->objFromFixture('BlogPost', $page); - SS_Datetime::set_mock_now($date); + $userRecord = $this->objFromFixture('SilverStripe\\Security\\Member', $user); + $pageRecord = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', $page); + DBDatetime::set_mock_now($date); $this->assertEquals($canView, $pageRecord->canView($userRecord)); } + /** + * @return array + */ public function canViewProvider() { $someFutureDate = '2013-10-10 20:00:00'; @@ -70,12 +78,12 @@ class BlogPostTest extends SapphireTest public function testCandidateAuthors() { - $blogpost = $this->objFromFixture('BlogPost', 'PostC'); + $blogpost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); //Set the group to draw Members from - Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'blogusers'); + Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'restrict_authors_to_group', 'blogusers'); $this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); @@ -86,12 +94,12 @@ class BlogPostTest extends SapphireTest public function testCanViewFuturePost() { - $blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate'); + $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\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 fd61cf5..c27a46c 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -1,11 +1,19 @@ logout(); } - $this->objFromFixture('BlogPost', 'FirstBlogPost'); + $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); /** * @var BlogTag $tag */ - $tag = $this->objFromFixture('BlogTag', 'FirstTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); } @@ -75,15 +83,15 @@ 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'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); - $tag = $this->objFromFixture('BlogTag', 'SecondTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); @@ -93,20 +101,20 @@ 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'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); - $tag = $this->objFromFixture('BlogTag', 'SecondTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); - $tag = $this->objFromFixture('BlogTag', 'ThirdTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); @@ -116,10 +124,10 @@ 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'); + $tag = singleton('SilverStripe\\Blog\\Model\\BlogTag'); $this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.'); $this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); @@ -129,26 +137,27 @@ 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'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); - $tag = $this->objFromFixture('BlogTag', 'SecondTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); - $tag = $this->objFromFixture('BlogTag', 'ThirdTag'); + $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); } - public function testDuplicateTagsForURLSegment() { + public function testDuplicateTagsForURLSegment() + { $blog = new Blog(); $blog->Title = 'Testing for duplicates blog'; $blog->write(); @@ -163,10 +172,10 @@ class BlogTagTest extends FunctionalTest $tag2->BlogID = $blog->ID; $tag2->write(); $this->assertEquals('cat-test-1', $tag2->URLSegment); - } - public function testDuplicateTags() { + public function testDuplicateTags() + { $blog = new Blog(); $blog->Title = 'Testing for duplicate tags'; $blog->write(); @@ -185,10 +194,9 @@ class BlogTagTest extends FunctionalTest $tag->write(); $this->fail('Duplicate BlogTag written'); } catch (ValidationException $e) { - $codeList = $e->getResult()->codeList(); - $this->assertCount(1, $codeList); - $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]); + $messages = $e->getResult()->getMessages(); + $this->assertCount(1, $messages); + $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']); } } - } diff --git a/tests/BlogTagsCloudWidgetTest.php b/tests/BlogTagsCloudWidgetTest.php index d37a2bc..f2564cc 100644 --- a/tests/BlogTagsCloudWidgetTest.php +++ b/tests/BlogTagsCloudWidgetTest.php @@ -1,13 +1,19 @@ markTestSkipped('Widgets module not installed'); } @@ -23,12 +29,13 @@ class BlogTagsCloudWidgetTest extends SapphireTest { $this->assertEquals($expected, $names); } - public function testGetTags() { + public function testGetTags() + { if (!class_exists('Widget')) { $this->markTestSkipped('Widgets module not installed'); } $widget = new BlogTagsCloudWidget(); - $blog = $this->objFromFixture('Blog', 'FourthBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); $widget->BlogID = $blog->ID; $widget->write(); $tags = $widget->getTags()->toArray(); diff --git a/tests/BlogTest.php b/tests/BlogTest.php index bfe63fb..1eeaab0 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -1,5 +1,17 @@ objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog->publish('Stage', 'Live'); } @@ -33,7 +45,7 @@ class BlogTest extends SapphireTest */ public function tearDown() { - SS_Datetime::clear_mock_now(); + DBDatetime::clear_mock_now(); Config::unnest(); parent::tearDown(); @@ -50,17 +62,17 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); - Config::inst()->update('BlogPost', 'show_in_sitetree', true); + Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', true); $classes = $blog->getExcludedSiteTreeClassNames(); - $this->assertNotContains('BlogPost', $classes, 'BlogPost class should be hidden.'); + $this->assertNotContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); - Config::inst()->update('BlogPost', 'show_in_sitetree', false); + Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', false); $classes = $blog->getExcludedSiteTreeClassNames(); - $this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.'); + $this->assertContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); } public function testGetArchivedBlogPosts() @@ -74,7 +86,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $archive = $blog->getArchivedBlogPosts(2013); @@ -96,7 +108,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '01'); @@ -135,8 +147,8 @@ class BlogTest extends SapphireTest */ public function testArchiveYear() { - $blog = $this->objFromFixture('Blog', 'FirstBlog'); - $controller = new Blog_Controller($blog); + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $controller = new BlogController($blog); $this->requestURL($controller, 'first-post/archive/'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); } @@ -156,47 +168,47 @@ class BlogTest extends SapphireTest /** * @var Blog $firstBlog */ - $firstBlog = $this->objFromFixture('Blog', 'FirstBlog'); + $firstBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); /** * @var Blog $fourthBlog */ - $fourthBlog = $this->objFromFixture('Blog', 'FourthBlog'); + $fourthBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); /** * @var BlogPost $postA */ - $postA = $this->objFromFixture('BlogPost', 'PostA'); + $postA = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostA'); /** * @var BlogPost $postB */ - $postB = $this->objFromFixture('BlogPost', 'PostB'); + $postB = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostB'); /** * @var BlogPost $postC */ - $postC = $this->objFromFixture('BlogPost', 'PostC'); + $postC = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); /** * @var Member $editor */ - $editor = $this->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)); @@ -274,9 +286,9 @@ class BlogTest extends SapphireTest public function testFilteredCategories() { - $blog = $this->objFromFixture('Blog', 'FirstBlog'); - $controller = new Blog_Controller($blog); - + $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $controller = new BlogController($blog); + // Root url $this->requestURL($controller, 'first-post'); $this->assertIDsEquals( @@ -293,10 +305,10 @@ class BlogTest extends SapphireTest ); // Posts - $firstPostID = $this->idFromFixture('BlogPost', 'FirstBlogPost'); - $secondPostID = $this->idFromFixture('BlogPost', 'SecondBlogPost'); - $firstFuturePostID = $this->idFromFixture('BlogPost', 'FirstFutureBlogPost'); - $secondFuturePostID = $this->idFromFixture('BlogPost', 'SecondFutureBlogPost'); + $firstPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); + $secondPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondBlogPost'); + $firstFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstFutureBlogPost'); + $secondFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondFutureBlogPost'); // Request first tag $this->requestURL($controller, 'first-post/tag/first-tag'); @@ -321,7 +333,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(); diff --git a/tests/blog.yml b/tests/blog.yml index cad0fc0..79a09f3 100755 --- a/tests/blog.yml +++ b/tests/blog.yml @@ -1,6 +1,6 @@ # Mock date is set to 2013-10-01 20:00:00 -Group: +SilverStripe\Security\Group: Administrators: Title: Administrators Editors: @@ -9,193 +9,193 @@ Group: Title: Blog Users Code: blogusers -Permission: +SilverStripe\Security\Permission: Administrators: Code: ADMIN - Group: =>Group.Administrators + Group: =>SilverStripe\Security\Group.Administrators Editors: Code: CMS_ACCESS_CMSMain - Group: =>Group.Editors + Group: =>SilverStripe\Security\Group.Editors BlogUsers: Code: CMS_ACCESS_CMSMain - Group: =>Group.BlogUsers + Group: =>SilverStripe\Security\Group.BlogUsers -SiteConfig: +SilverStripe\SiteConfig\SiteConfig: Default: CanEditType: 'OnlyTheseUsers' CanCreateTopLevelType: 'OnlyTheseUsers' - EditorGroups: =>Group.Administrators,=>Group.Editors - CreateTopLevelGroups: =>Group.Administrators,=>Group.Editors + EditorGroups: =>SilverStripe\Security\Group.Administrators,=>SilverStripe\Security\Group.Editors + CreateTopLevelGroups: =>SilverStripe\Security\Group.Administrators,=>SilverStripe\Security\Group.Editors -Member: +SilverStripe\Security\Member: Admin: FirstName: Test Surname: Administrator - Groups: =>Group.Administrators + Groups: =>SilverStripe\Security\Group.Administrators Editor: FirstName: Test Surname: Editor - Groups: =>Group.Editors + Groups: =>SilverStripe\Security\Group.Editors BlogEditor: FirstName: Blog Surname: Editor - Groups: =>Group.BlogUsers + Groups: =>SilverStripe\Security\Group.BlogUsers Writer: FirstName: Blog Surname: Writer - Groups: =>Group.BlogUsers + Groups: =>SilverStripe\Security\Group.BlogUsers Contributor: FirstName: Blog Surname: Contributor - Groups: =>Group.BlogUsers + Groups: =>SilverStripe\Security\Group.BlogUsers Visitor: FirstName: Blog Surname: Visitor -Blog: +SilverStripe\Blog\Model\Blog: FirstBlog: Title: 'First Blog' SecondBlog: Title: 'Second Blog' CanViewType: 'OnlyTheseUsers' CanEditType: 'OnlyTheseUsers' - ViewerGroups: =>Group.Administrators - EditorGroups: =>Group.Administrators + ViewerGroups: =>SilverStripe\Security\Group.Administrators + EditorGroups: =>SilverStripe\Security\Group.Administrators ThirdBlog: Title: 'Third Blog' CanEditType: 'OnlyTheseUsers' - EditorGroups: =>Group.Editors + EditorGroups: =>SilverStripe\Security\Group.Editors FourthBlog: Title: 'Fourth Blog' - Editors: =>Member.BlogEditor - Writers: =>Member.Writer - Contributors: =>Member.Contributor + Editors: =>SilverStripe\Security\Member.BlogEditor + Writers: =>SilverStripe\Security\Member.Writer + Contributors: =>SilverStripe\Security\Member.Contributor -BlogTag: +SilverStripe\Blog\Model\BlogTag: FirstTag: Title: 'First Tag' URLSegment: 'first-tag' - Blog: =>Blog.FirstBlog + Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog SecondTag: Title: 'Second Tag' URLSegment: 'second-tag' - Blog: =>Blog.SecondBlog + Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog ThirdTag: Title: 'Third Tag' URLSegment: 'third-tag' - Blog: =>Blog.ThirdBlog + Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog #Tags for Tag Cloud widget PopularTag: Title: 'Popular' URLSegment: 'popular-tag' - Blog: =>Blog.FourthBlog + Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog CoolTag: Title: 'Cool' URLSegment: 'cool-tag' - Blog: =>Blog.FourthBlog + Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog CatTag: Title: 'Cat' URLSegment: 'cat-tag' - Blog: =>Blog.FourthBlog + Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog KiwiTag: Title: 'Kiwi' URLSegment: 'kiwi-tag' - Blog: =>Blog.FourthBlog + Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog -BlogCategory: +SilverStripe\Blog\Model\BlogCategory: FirstCategory: Title: 'First Category' URLSegment: 'first-category' - Blog: =>Blog.FirstBlog + Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog SecondCategory: Title: 'Second Category' URLSegment: 'second-category' - Blog: =>Blog.SecondBlog + Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog ThirdCategory: Title: 'Third Category' URLSegment: 'third-category' - Blog: =>Blog.ThirdBlog + Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog -BlogPost: +SilverStripe\Blog\Model\BlogPost: FirstBlogPost: Title: 'First Post' URLSegment: first-post PublishDate: '2013-10-01 15:00:00' - Parent: =>Blog.FirstBlog - Tags: =>BlogTag.FirstTag - Categories: =>BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory SecondBlogPost: Title: 'Second Post' URLSegment: second-post PublishDate: '2013-09-01 15:00:00' - Parent: =>Blog.FirstBlog + Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog ThirdBlogPost: Title: 'Old Post' URLSegment: old-post PublishDate: '2012-01-09 15:00:00' - Parent: =>Blog.FirstBlog + Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog FirstFutureBlogPost: Title: 'Future Post' URLSegment: future-post PublishDate: '2015-01-01 00:00:00' - Tags: =>BlogTag.FirstTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FirstBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog SecondFutureBlogPost: Title: 'Future Post 2' URLSegment: future-post-2 PublishDate: '2013-11-01 00:00:00' - Tags: =>BlogTag.FirstTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FirstBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog PostA: Title: 'One Post' PublishDate: '2012-01-09 15:00:00' - Parent: =>Blog.FourthBlog - Authors: =>Member.Writer,=>Member.Contributor + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog + Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor PostB: Title: 'Second Post' PublishDate: '2012-01-09 15:00:00' - Parent: =>Blog.FourthBlog - Authors: =>Member.BlogEditor + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog + Authors: =>SilverStripe\Security\Member.BlogEditor PostC: Title: 'Third Post' PublishDate: '2012-01-09 15:00:00' - Parent: =>Blog.FourthBlog - Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog + Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor NullPublishDate: Title: 'No publish date' PublishDate: '' - Parent: =>Blog.FourthBlog - Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog + Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor #Posts for the tag cloud widget test TaggedPost1: Title: 'Tagged Post 1' URLSegment: tagged-post-1 PublishDate: '2012-01-09 15:00:00' - Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FourthBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog TaggedPost2: Title: 'Tagged Post 2' URLSegment: tagged-post-2 PublishDate: '2012-01-09 15:00:00' - Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag,=>BlogTag.CatTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FourthBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog TaggedPost3: Title: 'Tagged Post 3' URLSegment: tagged-post-3 PublishDate: '2012-01-09 17:20:00' - Tags: =>BlogTag.PopularTag,=>BlogTag.CoolTag,=>BlogTag.CatTag,=>BlogTag.KiwiTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FourthBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag,=>SilverStripe\Blog\Model\BlogTag.KiwiTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog TaggedPost4: Title: 'Tagged Post 4' URLSegment: tagged-post-4 PublishDate: '2012-04-09 15:00:00' - Tags: =>BlogTag.PopularTag - Categories: =>BlogCategory.FirstCategory - Parent: =>Blog.FourthBlog + Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag + Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory + Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog From 72a9f041c28caec7df02d72e9192117fac957e9e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 16 Dec 2016 11:57:25 +1300 Subject: [PATCH 07/31] Fix some incorrect table/model namespace issues --- src/Controllers/BlogController.php | 4 +-- src/Model/Blog.php | 54 +++++++++++++++++++++--------- src/Model/BlogFilter.php | 13 +++++-- src/Model/BlogMemberExtension.php | 8 ++--- src/Model/BlogObject.php | 4 +-- src/Model/BlogPost.php | 18 +++++----- src/Model/BlogPostFilter.php | 6 +++- src/Model/BlogTag.php | 4 +-- tests/BlogPostFilterTest.php | 5 +++ 9 files changed, 78 insertions(+), 38 deletions(-) diff --git a/src/Controllers/BlogController.php b/src/Controllers/BlogController.php index fe8ce6a..f95cd04 100644 --- a/src/Controllers/BlogController.php +++ b/src/Controllers/BlogController.php @@ -121,7 +121,7 @@ class BlogController extends Page_Controller /** * Renders an archive for a specified date. This can be by year or year/month. * - * @return null|SS_HTTPResponse + * @return null|HTTPResponse */ public function archive() { @@ -256,7 +256,7 @@ class BlogController extends Page_Controller /** * Renders the blog posts for a given category. * - * @return null|SS_HTTPResponse + * @return null|HTTPResponse */ public function category() { diff --git a/src/Model/Blog.php b/src/Model/Blog.php index 4590f50..8479ae3 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -152,23 +152,38 @@ class Blog extends Page implements PermissionProvider 'Categories', _t('Blog.Categories', 'Categories'), $self->Categories(), - GridFieldCategorisationConfig::create(15, $self->Categories()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories', 'BlogPosts') + GridFieldCategorisationConfig::create( + 15, + $self->Categories()->sort('Title'), + BlogCategory::class, + 'Categories', + 'BlogPosts' + ) ); $tags = GridField::create( 'Tags', _t('Blog.Tags', 'Tags'), $self->Tags(), - GridFieldCategorisationConfig::create(15, $self->Tags()->sort('Title'), 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags', 'BlogPosts') + GridFieldCategorisationConfig::create( + 15, + $self->Tags()->sort('Title'), + BlogTag::class, + 'Tags', + 'BlogPosts' + ) ); /** * @var FieldList $fields */ - $fields->addFieldsToTab('Root.Categorisation', array( - $categories, - $tags - )); + $fields->addFieldsToTab( + 'Root.Categorisation', + array( + $categories, + $tags + ) + ); $fields->findOrMakeTab('Root.Categorisation')->addExtraClass('blog-cms-categorisation'); }); @@ -258,7 +273,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(Member::class, $member); } if (!$member) { @@ -331,7 +346,8 @@ class Blog extends Page implements PermissionProvider { $fields = parent::getSettingsFields(); - $fields->addFieldToTab('Root.Settings', + $fields->addFieldToTab( + 'Root.Settings', NumericField::create('PostsPerPage', _t('Blog.PostsPerPage', 'Posts Per Page')) ); @@ -387,11 +403,14 @@ class Blog extends Page implements PermissionProvider $contributorField = $contributorField->performDisabledTransformation(); } - $fields->addFieldsToTab('Root.Users', array( - $editorField, - $writerField, - $contributorField - )); + $fields->addFieldsToTab( + 'Root.Users', + array( + $editorField, + $writerField, + $contributorField + ) + ); return $fields; } @@ -501,7 +520,10 @@ class Blog extends Page implements PermissionProvider $stage = '_' . $stage; } - $query->innerJoin('SilverStripe\\Blog\\Model\\BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)); + $query->innerJoin( + DataObject::getSchema()->tableName(BlogPost::class), + sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage) + ); $conn = DB::getConn(); @@ -638,13 +660,13 @@ class Blog extends Page implements PermissionProvider return $group; } - $group = new Group(); + $group = Group::create(); $group->Title = 'Blog users'; $group->Code = $code; $group->write(); - $permission = new Permission(); + $permission = Permission::create(); $permission->Code = $this->config()->grant_user_permission; $group->Permissions()->add($permission); diff --git a/src/Model/BlogFilter.php b/src/Model/BlogFilter.php index b850fec..8896004 100644 --- a/src/Model/BlogFilter.php +++ b/src/Model/BlogFilter.php @@ -11,6 +11,7 @@ use SilverStripe\Forms\FormTransformation; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\Tab; use SilverStripe\Lumberjack\Model\Lumberjack; +use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\Versioning\Versioned; use SilverStripe\Security\Permission; @@ -41,7 +42,10 @@ class BlogFilter extends Lumberjack } $dataQuery = $staged->dataQuery() - ->innerJoin('BlogPost', sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage)) + ->innerJoin( + DataObject::getSchema()->tableName(BlogPost::class), + sprintf('"BlogPost%s"."ID" = "SiteTree%s"."ID"', $stage, $stage) + ) ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); $staged = $staged->setDataQuery($dataQuery); @@ -55,7 +59,7 @@ class BlogFilter extends Lumberjack */ protected function subclassForBlog() { - return in_array(get_class($this->owner), ClassInfo::subclassesFor('Blog')); + return in_array(get_class($this->owner), ClassInfo::subclassesFor(Blog::class)); } /** @@ -67,7 +71,10 @@ 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"') + ->innerJoin( + DataObject::getSchema()->tableName(BlogPost::class), + '"BlogPost_Live"."ID" = "SiteTree_Live"."ID"' + ) ->where(sprintf('"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()))); $staged = $staged->setDataQuery($dataQuery); diff --git a/src/Model/BlogMemberExtension.php b/src/Model/BlogMemberExtension.php index eb2c152..405145a 100644 --- a/src/Model/BlogMemberExtension.php +++ b/src/Model/BlogMemberExtension.php @@ -23,22 +23,22 @@ class BlogMemberExtension extends DataExtension * @var array */ private static $db = array( - 'URLSegment' => 'Varchar', - 'BlogProfileSummary' => 'Text', + 'URLSegment' => 'Varchar', + 'BlogProfileSummary' => 'Text' ); /** * @var array */ private static $has_one = array( - 'BlogProfileImage' => 'Image', + 'BlogProfileImage' => 'SilverStripe\\Assets\\Image' ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', + 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' ); /** diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index 07fd0d1..419def1 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -161,7 +161,7 @@ trait BlogObject protected function onBeforeWrite() { parent::onBeforeWrite(); - if(empty($this->URLSegment)) { + if (empty($this->URLSegment)) { return $this->generateURLSegment(); } } @@ -185,7 +185,7 @@ trait BlogObject } if ($this->getDuplicatesByUrlSegment()->count() > 0) { - $this->owner->generateURLSegment($increment+1); + $this->owner->generateURLSegment($increment + 1); } return $this->owner->URLSegment; diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index aaf93af..69e8c36 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -264,9 +264,11 @@ class BlogPost extends Page $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate->getDateField()->setConfig('showcalendar', true); if (!$this->PublishDate) { - $publishDate->setDescription(_t( + $publishDate->setDescription( + _t( 'BlogPost.PublishDate_Description', - 'Will be set to "now" if published without a value.') + 'Will be set to "now" if published without a value.' + ) ); } @@ -323,11 +325,11 @@ class BlogPost extends Page { if ($this->config()->restrict_authors_to_group) { return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members(); - } else { - $list = Member::get(); - $this->extend('updateCandidateAuthors', $list); - return $list; } + + $list = Member::get(); + $this->extend('updateCandidateAuthors', $list); + return $list; } /** @@ -487,7 +489,7 @@ class BlogPost extends Page return false; } - if($this->canEdit($member)) { + if ($this->canEdit($member)) { return true; } @@ -495,7 +497,7 @@ class BlogPost extends Page * @var DBDatetime $publishDate */ $publishDate = $this->dbObject('PublishDate'); - if(!$publishDate->exists()) { + if (!$publishDate->exists()) { return false; } diff --git a/src/Model/BlogPostFilter.php b/src/Model/BlogPostFilter.php index 3efd13a..f222e66 100644 --- a/src/Model/BlogPostFilter.php +++ b/src/Model/BlogPostFilter.php @@ -6,6 +6,7 @@ use SilverStripe\Admin\LeftAndMain; use SilverStripe\Control\Controller; use SilverStripe\Core\Convert; use SilverStripe\ORM\DataExtension; +use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\Queries\SQLSelect; @@ -57,6 +58,9 @@ class BlogPostFilter extends DataExtension */ public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) { - $dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"'); + $dataQuery->innerJoin( + DataObject::getSchema()->tableName(BlogPost::class), + '"SiteTree"."ID" = "BlogPost"."ID"' + ); } } diff --git a/src/Model/BlogTag.php b/src/Model/BlogTag.php index 5f829a3..fc96537 100644 --- a/src/Model/BlogTag.php +++ b/src/Model/BlogTag.php @@ -49,14 +49,14 @@ class BlogTag extends DataObject implements CategorisationObject * @var array */ private static $has_one = array( - 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => 'SilverStripe\\Blog\\Model\\Blog' ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', + 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' ); /** diff --git a/tests/BlogPostFilterTest.php b/tests/BlogPostFilterTest.php index a43026d..04aa271 100755 --- a/tests/BlogPostFilterTest.php +++ b/tests/BlogPostFilterTest.php @@ -6,6 +6,7 @@ use SilverStripe\Security\Member; /** * @mixin PHPUnit_Framework_TestCase + * @coversDefaultClass \SilverStripe\Blog\Model\BlogPostFilter */ class BlogPostFilterTest extends SapphireTest { @@ -28,6 +29,10 @@ class BlogPostFilterTest extends SapphireTest parent::tearDown(); } + /** + * Tests that unpublished articles are not returned + * @covers ::augmentSQL + */ public function testFilter() { $member = Member::currentUser(); From 58e5ebb652792a893d653977618ab1dc5b284b96 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 16 Dec 2016 17:10:38 +1300 Subject: [PATCH 08/31] Fix controller names, removed Listbox methods, namespacing bugs, template locations --- src/Admin/GridFieldCategorisationConfig.php | 18 ++++++++++-------- src/Admin/GridFieldFormAction.php | 2 +- src/Admin/GridFieldMergeAction.php | 19 ++++++++++--------- ...Controller.php => BlogPost_Controller.php} | 2 +- ...BlogController.php => Blog_Controller.php} | 2 +- src/Forms/GridField/GridFieldAddByDBField.php | 2 +- src/Model/Blog.php | 6 +++--- .../Forms/GridField}/GridFieldAddByDBField.ss | 0 8 files changed, 27 insertions(+), 24 deletions(-) rename src/Controllers/{BlogPostController.php => BlogPost_Controller.php} (72%) rename src/Controllers/{BlogController.php => Blog_Controller.php} (99%) rename templates/{ => SilverStripe/Blog/Forms/GridField}/GridFieldAddByDBField.ss (100%) diff --git a/src/Admin/GridFieldCategorisationConfig.php b/src/Admin/GridFieldCategorisationConfig.php index 0b0f88f..6455903 100644 --- a/src/Admin/GridFieldCategorisationConfig.php +++ b/src/Admin/GridFieldCategorisationConfig.php @@ -2,7 +2,7 @@ namespace SilverStripe\Blog\Admin; -use SilverStripe\Blog\Form\GridField\GridFieldAddByDBField; +use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField; use SilverStripe\Blog\Admin\GridFieldMergeAction; use SilverStripe\Blog\Model\CategorisationObject; use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; @@ -33,13 +33,15 @@ 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) { - return $item->BlogPosts()->Count(); - } - )); + $columns->setFieldFormatting( + array( + 'BlogPostsCount' => function ($value, CategorisationObject $item) { + return $item->BlogPosts()->Count(); + } + ) + ); $this->changeColumnOrder(); } @@ -52,7 +54,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor /** * @var GridFieldDataColumns $columns */ - $columns = $this->getComponentByType('GridFieldDataColumns'); + $columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns->setDisplayFields( array( diff --git a/src/Admin/GridFieldFormAction.php b/src/Admin/GridFieldFormAction.php index e48ba80..dfcc629 100644 --- a/src/Admin/GridFieldFormAction.php +++ b/src/Admin/GridFieldFormAction.php @@ -2,7 +2,7 @@ namespace SilverStripe\Blog\Admin; -use GridField_FormAction; +use SilverStripe\Forms\GridField\GridField_FormAction; class GridFieldFormAction extends GridField_FormAction { diff --git a/src/Admin/GridFieldMergeAction.php b/src/Admin/GridFieldMergeAction.php index 25d92f4..f932a8e 100644 --- a/src/Admin/GridFieldMergeAction.php +++ b/src/Admin/GridFieldMergeAction.php @@ -2,15 +2,16 @@ namespace SilverStripe\Blog\Admin; -use GridField_ColumnProvider; -use GridField_ActionProvider; -use DropdownField; - -use GridField; -use Controller; use SilverStripe\Blog\Admin\GridFieldFormAction; +use SilverStripe\Control\Controller; +use Silverstripe\Forms\DropdownField; +use SilverStripe\Forms\GridField\GridField; +use SilverStripe\Forms\GridField\GridField_ActionProvider; +use SilverStripe\Forms\GridField\GridField_ColumnProvider; - +/** + * @package blog + */ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider { /** @@ -81,11 +82,11 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action public function getColumnContent($gridField, $record, $columnName) { if ($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) { - $dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map()); + $dropdown = DropdownField::create('Target', 'Target', $this->records->exclude('ID', $record->ID)->map()); $dropdown->setAttribute('id', 'Target_'.$record->ID); $prefix = strtolower($this->parentMethod . '-' . $this->childMethod); - $action = GridFieldFormAction::create( + $action = new GridFieldFormAction( $gridField, 'MergeAction' . $record->ID, 'Move', diff --git a/src/Controllers/BlogPostController.php b/src/Controllers/BlogPost_Controller.php similarity index 72% rename from src/Controllers/BlogPostController.php rename to src/Controllers/BlogPost_Controller.php index 56f7dc2..5eb57d1 100644 --- a/src/Controllers/BlogPostController.php +++ b/src/Controllers/BlogPost_Controller.php @@ -8,7 +8,7 @@ use Page_Controller; * @package silverstripe * @subpackage blog */ -class BlogPostController extends Page_Controller +class BlogPost_Controller extends Page_Controller { } diff --git a/src/Controllers/BlogController.php b/src/Controllers/Blog_Controller.php similarity index 99% rename from src/Controllers/BlogController.php rename to src/Controllers/Blog_Controller.php index f95cd04..65ee60c 100644 --- a/src/Controllers/BlogController.php +++ b/src/Controllers/Blog_Controller.php @@ -13,7 +13,7 @@ use SilverStripe\Security\Member; * @package silverstripe * @subpackage blog */ -class BlogController extends Page_Controller +class Blog_Controller extends Page_Controller { /** * @var array diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 1e4e577..18c5b47 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -210,7 +210,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP $forTemplate->Fields->push($addAction); return array( - $this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Form\\GridField\\GridFieldAddByDBField') + $this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField') ); } } diff --git a/src/Model/Blog.php b/src/Model/Blog.php index 8479ae3..fde1c84 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -354,7 +354,7 @@ class Blog extends Page implements PermissionProvider $members = $this->getCandidateUsers()->map()->toArray(); $editorField = ListboxField::create('Editors', 'Editors', $members) - ->setMultiple(true) + // ->setMultiple(true) ->setRightTitle('help') ->setDescription(' An editor has control over specific Blogs, and all posts included within it. Short of being able to assign other editors to a blog, they are able to handle most changes to their assigned blog.
@@ -373,7 +373,7 @@ class Blog extends Page implements PermissionProvider } $writerField = ListboxField::create('Writers', 'Writers', $members) - ->setMultiple(true) + // ->setMultiple(true) ->setRightTitle('help') ->setDescription(' A writer has full control over creating, editing and publishing BlogPosts they have authored or have been assigned to. Writers are unable to edit BlogPosts to which they are not assigned.
@@ -389,7 +389,7 @@ class Blog extends Page implements PermissionProvider } $contributorField = ListboxField::create('Contributors', 'Contributors', $members) - ->setMultiple(true) + // ->setMultiple(true) ->setRightTitle('help') ->setDescription(' Contributors have the ability to create or edit BlogPosts, but are unable to publish without authorisation of an editor. They are also unable to assign other contributing authors to any of their BlogPosts.
diff --git a/templates/GridFieldAddByDBField.ss b/templates/SilverStripe/Blog/Forms/GridField/GridFieldAddByDBField.ss similarity index 100% rename from templates/GridFieldAddByDBField.ss rename to templates/SilverStripe/Blog/Forms/GridField/GridFieldAddByDBField.ss From 413e94e186bb4ffe82b142c7858df5a6f92beacc Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 10:06:30 +1300 Subject: [PATCH 09/31] Add legacy class map for migrating ClassName in SiteTree --- _config/legacy.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 _config/legacy.yml diff --git a/_config/legacy.yml b/_config/legacy.yml new file mode 100644 index 0000000..e769aaf --- /dev/null +++ b/_config/legacy.yml @@ -0,0 +1,9 @@ +--- +Name: bloglegacy +--- +SilverStripe\ORM\DatabaseAdmin: + classname_value_remapping: + Blog: SilverStripe\Blog\Model\Blog + BlogCategory: SilverStripe\Blog\Model\BlogCategory + BlogPost: SilverStripe\Blog\Model\BlogPost + BlogTag: SilverStripe\Blog\Model\BlogTag From f35c6049d7347625484b047e68212935d0acfb1f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 10:07:08 +1300 Subject: [PATCH 10/31] Move blog layouts to namespaced folder location --- .../{forms => SilverStripe/Blog/Forms}/TabSet_holder.ss | 8 ++++---- templates/{ => SilverStripe/Blog/Model}/Layout/Blog.ss | 0 .../{ => SilverStripe/Blog/Model}/Layout/BlogPost.ss | 0 .../{ => SilverStripe/Blog/Model}/Layout/Blog_profile.ss | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename templates/{forms => SilverStripe/Blog/Forms}/TabSet_holder.ss (93%) rename templates/{ => SilverStripe/Blog/Model}/Layout/Blog.ss (100%) rename templates/{ => SilverStripe/Blog/Model}/Layout/BlogPost.ss (100%) rename templates/{ => SilverStripe/Blog/Model}/Layout/Blog_profile.ss (100%) diff --git a/templates/forms/TabSet_holder.ss b/templates/SilverStripe/Blog/Forms/TabSet_holder.ss similarity index 93% rename from templates/forms/TabSet_holder.ss rename to templates/SilverStripe/Blog/Forms/TabSet_holder.ss index 85bc11c..dd2337d 100644 --- a/templates/forms/TabSet_holder.ss +++ b/templates/SilverStripe/Blog/Forms/TabSet_holder.ss @@ -1,4 +1,4 @@ -
- <%-- this resets ths template (from TabSet_holder) and renders using forTemplate --%> - $setTemplate('') -
\ No newline at end of file +
+ <%-- this resets ths template (from TabSet_holder) and renders using forTemplate --%> + $setTemplate('') +
diff --git a/templates/Layout/Blog.ss b/templates/SilverStripe/Blog/Model/Layout/Blog.ss similarity index 100% rename from templates/Layout/Blog.ss rename to templates/SilverStripe/Blog/Model/Layout/Blog.ss diff --git a/templates/Layout/BlogPost.ss b/templates/SilverStripe/Blog/Model/Layout/BlogPost.ss similarity index 100% rename from templates/Layout/BlogPost.ss rename to templates/SilverStripe/Blog/Model/Layout/BlogPost.ss diff --git a/templates/Layout/Blog_profile.ss b/templates/SilverStripe/Blog/Model/Layout/Blog_profile.ss similarity index 100% rename from templates/Layout/Blog_profile.ss rename to templates/SilverStripe/Blog/Model/Layout/Blog_profile.ss From 71890778db97f42452f92b1f3b2e93ac2c47937a Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 10:25:36 +1300 Subject: [PATCH 11/31] Move controllers to same namespace as their model --- src/{Controllers => Model}/BlogPost_Controller.php | 2 +- src/{Controllers => Model}/Blog_Controller.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename src/{Controllers => Model}/BlogPost_Controller.php (77%) rename src/{Controllers => Model}/Blog_Controller.php (99%) diff --git a/src/Controllers/BlogPost_Controller.php b/src/Model/BlogPost_Controller.php similarity index 77% rename from src/Controllers/BlogPost_Controller.php rename to src/Model/BlogPost_Controller.php index 5eb57d1..139d6ac 100644 --- a/src/Controllers/BlogPost_Controller.php +++ b/src/Model/BlogPost_Controller.php @@ -1,6 +1,6 @@ blogPosts ?: ArrayList::create(); - $posts = PaginatedList::create($allPosts); // Set appropriate page size From f376b1c2f15004a7cdbec4f955cb8773bbca2494 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 11:50:42 +1300 Subject: [PATCH 12/31] Update deprecated image manipulation calls --- src/Model/BlogPost.php | 6 ++- templates/Includes/MemberDetails.ss | 2 +- templates/Includes/PostSummary.ss | 2 +- .../Blog/Model/Layout/BlogPost.ss | 40 +++++++++---------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 69e8c36..72b5be8 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -251,9 +251,11 @@ class BlogPost extends Page _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024 - )->setDescription(_t( + )->setDescription( + _t( 'BlogPost.AdditionalCredits_Description', - 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.') + 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.' + ) ); if (!$this->canEditAuthors()) { diff --git a/templates/Includes/MemberDetails.ss b/templates/Includes/MemberDetails.ss index b968786..d423c48 100644 --- a/templates/Includes/MemberDetails.ss +++ b/templates/Includes/MemberDetails.ss @@ -3,7 +3,7 @@
<% if $CurrentProfile.BlogProfileImage %>
- $CurrentProfile.BlogProfileImage.setWidth(180) + $CurrentProfile.BlogProfileImage.ScaleWidth(180)
<% end_if %>
diff --git a/templates/Includes/PostSummary.ss b/templates/Includes/PostSummary.ss index 91a699a..b06d1f1 100644 --- a/templates/Includes/PostSummary.ss +++ b/templates/Includes/PostSummary.ss @@ -8,7 +8,7 @@

"> - $FeaturedImage.setWidth(795) + $FeaturedImage.ScaleWidth(795)

diff --git a/templates/SilverStripe/Blog/Model/Layout/BlogPost.ss b/templates/SilverStripe/Blog/Model/Layout/BlogPost.ss index f3839dc..df0b7db 100644 --- a/templates/SilverStripe/Blog/Model/Layout/BlogPost.ss +++ b/templates/SilverStripe/Blog/Model/Layout/BlogPost.ss @@ -1,20 +1,20 @@ -<% require themedCSS('blog', 'blog') %> - -
-
-

$Title

- - <% if $FeaturedImage %> -

$FeaturedImage.setWidth(795)

- <% end_if %> - -
$Content
- - <% include EntryMeta %> -
- - $Form - $CommentsForm -
- -<% include BlogSideBar %> +<% require themedCSS('blog', 'blog') %> + +
+
+

$Title

+ + <% if $FeaturedImage %> +

$FeaturedImage.ScaleWidth(795)

+ <% end_if %> + +
$Content
+ + <% include EntryMeta %> +
+ + $Form + $CommentsForm +
+ +<% include BlogSideBar %> From 83db670e141714b15d2a10765ed9b54e2cfcc93a Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 12:12:08 +1300 Subject: [PATCH 13/31] FIX Path to author profile when blog is the homepage --- src/Model/Blog.php | 9 ++++- src/Model/BlogPost.php | 2 +- src/Model/Blog_Controller.php | 2 +- templates/Includes/EntryMeta.ss | 70 ++++++++++++++++++--------------- tests/BlogTest.php | 6 +-- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/Model/Blog.php b/src/Model/Blog.php index fde1c84..fa2c936 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -6,6 +6,7 @@ use Page; use Page_Controller; use SilverStripe\Blog\Admin\GridFieldCategorisationConfig; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; +use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\Control\Controller; use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\Core\Convert; @@ -569,7 +570,13 @@ class Blog extends Page implements PermissionProvider */ public function ProfileLink($urlSegment) { - return Controller::join_links($this->Link(), 'profile', $urlSegment); + $baseLink = $this->Link(); + if ($baseLink === '/') { + // Handle homepage blogs + $baseLink = RootURLController::get_homepage_link(); + } + + return Controller::join_links($baseLink, 'profile', $urlSegment); } /** diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 72b5be8..9e70df0 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -637,7 +637,7 @@ class BlogPost extends Page */ public function getCredits() { - $list = new ArrayList(); + $list = ArrayList::create(); $list->merge($this->getDynamicCredits()); $list->merge($this->getStaticCredits()); diff --git a/src/Model/Blog_Controller.php b/src/Model/Blog_Controller.php index 81a5ca4..bd5e9b3 100644 --- a/src/Model/Blog_Controller.php +++ b/src/Model/Blog_Controller.php @@ -69,7 +69,7 @@ class Blog_Controller extends Page_Controller /** * Renders a Blog Member's profile. * - * @return SS_HTTPResponse + * @return HTTPResponse */ public function profile() { diff --git a/templates/Includes/EntryMeta.ss b/templates/Includes/EntryMeta.ss index 197ed74..8100f21 100644 --- a/templates/Includes/EntryMeta.ss +++ b/templates/Includes/EntryMeta.ss @@ -1,31 +1,39 @@ - + diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 1eeaab0..f02e96c 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -1,6 +1,6 @@ objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); - $controller = new BlogController($blog); + $controller = new Blog_Controller($blog); $this->requestURL($controller, 'first-post/archive/'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); } @@ -287,7 +287,7 @@ class BlogTest extends SapphireTest public function testFilteredCategories() { $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); - $controller = new BlogController($blog); + $controller = new Blog_Controller($blog); // Root url $this->requestURL($controller, 'first-post'); From de1b947c97298b42a6d50630717da9cb631c4007 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 13:54:23 +1300 Subject: [PATCH 14/31] Remove file that popped up during rebasing --- code/extensions/URLSegmentExtension.php | 78 ------------------------- 1 file changed, 78 deletions(-) delete mode 100644 code/extensions/URLSegmentExtension.php diff --git a/code/extensions/URLSegmentExtension.php b/code/extensions/URLSegmentExtension.php deleted file mode 100644 index 2daba19..0000000 --- a/code/extensions/URLSegmentExtension.php +++ /dev/null @@ -1,78 +0,0 @@ - 'Varchar(255)', - ); - - /** - * {@inheritdoc} - */ - public function onBeforeWrite() - { - if ($this->owner->BlogID) { - $this->owner->generateURLSegment(); - } - } - - /** - * Generates a unique URLSegment from the title. - * - * @param int $increment - * - * @return string - */ - public function generateURLSegment($increment = null) - { - $filter = new URLSegmentFilter(); - - // Setting this to on. Because of the UI flow, it would be quite a lot of work - // to support turning this off. (ie. the add by title flow would not work). - // If this becomes a problem we can approach it then. - // @see https://github.com/silverstripe/silverstripe-blog/issues/376 - $filter->setAllowMultibyte(true); - - $this->owner->URLSegment = $filter->filter($this->owner->Title); - - if (is_int($increment)) { - $this->owner->URLSegment .= '-' . $increment; - } - - // Postgres use '' instead of 0 as an emtpy blog ID - // Without this all the tests fail - if (!$this->owner->BlogID) { - $this->owner->BlogID = 0; - } - - $duplicate = DataList::create($this->owner->ClassName)->filter(array( - 'URLSegment' => $this->owner->URLSegment, - 'BlogID' => $this->owner->BlogID, - )); - - if ($this->owner->ID) { - $duplicate = $duplicate->exclude('ID', $this->owner->ID); - } - - if ($duplicate->count() > 0) { - if (is_int($increment)) { - $increment += 1; - } else { - $increment = 0; - } - - $this->owner->generateURLSegment((int) $increment); - } - - return $this->owner->URLSegment; - } -} From cc17e81952de63f3fcc7b0aa66687a1d48a37571 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 13:56:53 +1300 Subject: [PATCH 15/31] Remove old PHP $this casting --- src/Model/Blog.php | 14 ++++++-------- src/Model/BlogPost.php | 10 +++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Model/Blog.php b/src/Model/Blog.php index fa2c936..15bae2d 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -142,20 +142,18 @@ class Blog extends Page implements PermissionProvider Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); - $self =& $this; - - $this->beforeUpdateCMSFields(function ($fields) use ($self) { - if (!$self->canEdit()) { + $this->beforeUpdateCMSFields(function ($fields) { + if (!$this->canEdit()) { return; } $categories = GridField::create( 'Categories', _t('Blog.Categories', 'Categories'), - $self->Categories(), + $this->Categories(), GridFieldCategorisationConfig::create( 15, - $self->Categories()->sort('Title'), + $this->Categories()->sort('Title'), BlogCategory::class, 'Categories', 'BlogPosts' @@ -165,10 +163,10 @@ class Blog extends Page implements PermissionProvider $tags = GridField::create( 'Tags', _t('Blog.Tags', 'Tags'), - $self->Tags(), + $this->Tags(), GridFieldCategorisationConfig::create( 15, - $self->Tags()->sort('Title'), + $this->Tags()->sort('Title'), BlogTag::class, 'Tags', 'BlogPosts' diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 9e70df0..043fc55 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -58,14 +58,14 @@ class BlogPost extends Page private static $db = array( 'PublishDate' => 'Datetime', 'AuthorNames' => 'Varchar(1024)', - 'Summary' => 'HTMLText', + 'Summary' => 'HTMLText' ); /** * @var array */ private static $has_one = array( - 'FeaturedImage' => 'SilverStripe\\Assets\\Image', + 'FeaturedImage' => 'SilverStripe\\Assets\\Image' ); /** @@ -74,7 +74,7 @@ class BlogPost extends Page private static $many_many = array( 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', - 'Authors' => 'SilverStripe\\Security\\Member', + 'Authors' => 'SilverStripe\\Security\\Member' ); /** @@ -83,7 +83,7 @@ class BlogPost extends Page private static $defaults = array( 'ShowInMenus' => false, 'InheritSideBar' => true, - 'ProvideComments' => true, + 'ProvideComments' => true ); /** @@ -112,7 +112,7 @@ class BlogPost extends Page */ private static $casting = array( 'Excerpt' => 'HTMLText', - 'Date' => 'SS_Datetime' + 'Date' => 'DBDatetime' ); /** From c927d7e29f1d42b0abc803b62276b6e814e46868 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 14:25:29 +1300 Subject: [PATCH 16/31] FIX Duplicated state in gridfield --- src/Forms/GridField/GridFieldConfig_BlogPost.php | 2 +- src/Model/BlogFilter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Forms/GridField/GridFieldConfig_BlogPost.php b/src/Forms/GridField/GridFieldConfig_BlogPost.php index ccc5de6..74d4a36 100644 --- a/src/Forms/GridField/GridFieldConfig_BlogPost.php +++ b/src/Forms/GridField/GridFieldConfig_BlogPost.php @@ -19,7 +19,7 @@ class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack { parent::__construct($itemsPerPage); - $this->removeComponentsByType('GridFieldSiteTreeState'); + $this->removeComponentsByType('SilverStripe\\Lumberjack\\Forms\\GridFieldSiteTreeState'); $this->addComponent(new GridFieldBlogPostState()); } } diff --git a/src/Model/BlogFilter.php b/src/Model/BlogFilter.php index 8896004..48c1c37 100644 --- a/src/Model/BlogFilter.php +++ b/src/Model/BlogFilter.php @@ -59,7 +59,7 @@ class BlogFilter extends Lumberjack */ protected function subclassForBlog() { - return in_array(get_class($this->owner), ClassInfo::subclassesFor(Blog::class)); + return in_array(get_class($this->owner), ClassInfo::subclassesFor('SilverStripe\\Blog\\Model\\Blog')); } /** From 4e7e1b7975d3ac1fabefba9a94c59432e58b463e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 14:29:05 +1300 Subject: [PATCH 17/31] FIX Base pase constant BLOGGER_DIR --- _config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.php b/_config.php index f45d2d2..aded448 100755 --- a/_config.php +++ b/_config.php @@ -5,4 +5,4 @@ * * @return string **/ -define('BLOGGER_DIR', dirname(__FILE__)); +define('BLOGGER_DIR', basename(dirname(__FILE__))); From df75c6c27588b34f756fe8e67efddb6e7689f1c8 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 14:55:39 +1300 Subject: [PATCH 18/31] Move admin sidebar template to correct location --- .../{ => SilverStripe/Blog/Forms}/BlogAdminSidebar_holder.ss | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename templates/{ => SilverStripe/Blog/Forms}/BlogAdminSidebar_holder.ss (100%) diff --git a/templates/BlogAdminSidebar_holder.ss b/templates/SilverStripe/Blog/Forms/BlogAdminSidebar_holder.ss similarity index 100% rename from templates/BlogAdminSidebar_holder.ss rename to templates/SilverStripe/Blog/Forms/BlogAdminSidebar_holder.ss From 98410c7eae73044a6ff5518c3c813711f0fdfe84 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 19 Dec 2016 15:37:36 +1300 Subject: [PATCH 19/31] TEMPORARY Disable the sidebar. @todo Fix it and put it back. --- src/Model/BlogPost.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 043fc55..03aa95b 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -274,6 +274,11 @@ class BlogPost extends Page ); } + /** + * @todo Fix the sidebar styles for SS4 + Bootstrap + */ + return; + // Get categories and tags $parent = $this->Parent(); $categories = $parent instanceof Blog From e263ba33ec5cb36123169a917ba00e1167888a5c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 20 Dec 2016 16:57:05 +1300 Subject: [PATCH 20/31] Update Travis and Scrutinizer configuration, add note to readme --- .scrutinizer.yml | 2 +- .travis.yml | 33 ++++++++++++++++----------------- README.md | 20 ++++++++++++-------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 61b0c9f..de09355 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -6,4 +6,4 @@ checks: duplication: true filter: - paths: [code/*, tests/*] + paths: [src/*, tests/*] diff --git a/.travis.yml b/.travis.yml index 41abb51..ab21202 100755 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ before_install: env: global: - - DB=MYSQL CORE_RELEASE=3.1 - # Turn coverage off by default, as it's expensive time wise - COVERAGE=0 @@ -21,31 +19,32 @@ env: - MODULE_PATH=blog matrix: - allow_failures: - - php: hhvm-nightly include: - - php: 5.6 - env: DB=MYSQL COVERAGE=1 - php: 5.5 - env: DB=MYSQL + env: DB=MYSQL CORE_RELEASE=4 + - php: 5.6 - env: DB=PGSQL + env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 - php: 5.6 - env: DB=MYSQL CORE_RELEASE=3.2 + env: DB=PGSQL CORE_RELEASE=4 - php: 5.6 - env: DB=PGSQL CORE_RELEASE=3.2 - - php: 5.4 - env: DB=SQLITE - - php: 5.3 - env: DB=MYSQL - - php: hhvm - env: DB=MYSQL + env: DB=SQLITE CORE_RELEASE=4 + + - php: 7.0 + env: DB=MYSQL CORE_RELEASE=4 + + - php: 7.1 + env: DB=MYSQL CORE_RELEASE=4 + - php: 7.1 + env: DB=PGSQL CORE_RELEASE=4 + - php: 7.1 + env: DB=SQLITE CORE_RELEASE=4 before_script: - phpenv rehash - composer self-update || true - - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support + - git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "silverstripe/comments" --require "silverstripe/widgets" - cd ~/builds/ss diff --git a/README.md b/README.md index a612d19..800304f 100755 --- a/README.md +++ b/README.md @@ -10,16 +10,16 @@ ## Documentation -[User guide](docs/en/userguide/index.md) -[Developer documentation](docs/en/index.md) +* [User guide](docs/en/userguide/index.md) +* [Developer documentation](docs/en/index.md) ## Requirements ``` -silverstripe/cms: ^3.1 -silverstripe/lumberjack: ^1.1 -silverstripe/tagfield: ^1.0 +silverstripe/cms: ^4.0 +silverstripe/lumberjack: ^2.0 +silverstripe/tagfield: ^2.0 ``` ### Suggested Modules @@ -35,8 +35,12 @@ silverstripe/comments: * composer require silverstripe/blog ``` -## Upgrading legacy blog to 2.x +## Upgrading + +### Upgrading from 2.x to 3.x + +Aside from the framework and CMS upgrades required the blog module should not require anything extra to be completed. + +### Upgrading legacy blog to 2.x If you're upgrading from blog version 1.0 to 2.x you will need to run the `BlogMigrationTask`. Run the task using `dev/tasks/BlogMigrationTask` either via the browser or sake CLI to migrate your legacy blog to the new version data structure. - - From 5f07a3cc23c685e050feeac2009782c8ce6eda56 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 12 Jan 2017 10:56:08 +1300 Subject: [PATCH 21/31] PSR-2 compat: Change Blog*_Controller to Blog*Controller --- src/Model/{Blog_Controller.php => BlogController.php} | 2 +- .../{BlogPost_Controller.php => BlogPostController.php} | 2 +- tests/BlogTest.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/Model/{Blog_Controller.php => BlogController.php} (99%) rename src/Model/{BlogPost_Controller.php => BlogPostController.php} (71%) diff --git a/src/Model/Blog_Controller.php b/src/Model/BlogController.php similarity index 99% rename from src/Model/Blog_Controller.php rename to src/Model/BlogController.php index bd5e9b3..3dc2d26 100644 --- a/src/Model/Blog_Controller.php +++ b/src/Model/BlogController.php @@ -13,7 +13,7 @@ use SilverStripe\Security\Member; * @package silverstripe * @subpackage blog */ -class Blog_Controller extends Page_Controller +class BlogController extends Page_Controller { /** * @var array diff --git a/src/Model/BlogPost_Controller.php b/src/Model/BlogPostController.php similarity index 71% rename from src/Model/BlogPost_Controller.php rename to src/Model/BlogPostController.php index 139d6ac..9891372 100644 --- a/src/Model/BlogPost_Controller.php +++ b/src/Model/BlogPostController.php @@ -8,7 +8,7 @@ use Page_Controller; * @package silverstripe * @subpackage blog */ -class BlogPost_Controller extends Page_Controller +class BlogPostController extends Page_Controller { } diff --git a/tests/BlogTest.php b/tests/BlogTest.php index f02e96c..9a64673 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -1,6 +1,6 @@ objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); - $controller = new Blog_Controller($blog); + $controller = new BlogController($blog); $this->requestURL($controller, 'first-post/archive/'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); } @@ -287,7 +287,7 @@ class BlogTest extends SapphireTest public function testFilteredCategories() { $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); - $controller = new Blog_Controller($blog); + $controller = new BlogController($blog); // Root url $this->requestURL($controller, 'first-post'); From c1cb8576b3a9713cbfeef2ec2aff3e3bf862cda2 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 13 Jan 2017 15:33:53 +1300 Subject: [PATCH 22/31] FIX Validation of existing tags, duplicated GridField add button, formatting in categorisation, bootstrapify buttons --- css/cms.css | 6 + js/gridfieldaddbydbfield.js | 6 +- lang/en.yml | 2 +- scss/cms.scss | 255 +++++++++--------- src/Admin/GridFieldCategorisationConfig.php | 2 +- src/Forms/GridField/GridFieldAddByDBField.php | 22 +- src/Model/Blog.php | 4 +- src/Model/BlogController.php | 4 +- src/Model/BlogObject.php | 34 +-- src/Model/BlogPost.php | 4 +- src/Model/BlogPostController.php | 4 +- src/Model/BlogTag.php | 2 +- 12 files changed, 179 insertions(+), 166 deletions(-) diff --git a/css/cms.css b/css/cms.css index 2998d91..7aa1caf 100755 --- a/css/cms.css +++ b/css/cms.css @@ -117,6 +117,9 @@ label.right.toggle-description-correct-right { .blog-cms-categorisation .MergeActionReveal { margin-left: 10px; } +.blog-cms-categorisation .toolbar--content { + margin-top: 0; } + .blog-cms-categorisation .MergeActionReveal:after { content: ''; background: url("../images/move-icon.png"); @@ -124,3 +127,6 @@ label.right.toggle-description-correct-right { height: 16px; width: 16px; margin-left: 4px; } + +.blog-cms-categorisation button.action { + margin-left: 5px; } diff --git a/js/gridfieldaddbydbfield.js b/js/gridfieldaddbydbfield.js index f6d31e2..67799f3 100644 --- a/js/gridfieldaddbydbfield.js +++ b/js/gridfieldaddbydbfield.js @@ -1,20 +1,16 @@ (function ($) { - $.entwine('ss', function ($) { - /** * Prevent the CMS hijacking the return key */ $('.add-existing-autocompleter input.text').entwine({ 'onkeydown': function (e) { - if(e.which == 13) { + if (e.which == 13) { $parent = $(this).parents('.add-existing-autocompleter'); $parent.find('button[type="submit"]').click(); return false; } } }); - }); - })(jQuery); diff --git a/lang/en.yml b/lang/en.yml index 9ba7ddd..afffaf8 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -87,7 +87,7 @@ en: PLURALNAME: 'Blog Recent Posts Widgets' SINGULARNAME: 'Blog Recent Posts Widget' BlogTag: - Duplicate: 'A blog tags already exists with that name' + Duplicate: 'A blog tag already exists with that name' PLURALNAME: 'Blog Tags' SINGULARNAME: 'Blog Tag' Title: Title diff --git a/scss/cms.scss b/scss/cms.scss index 670f2d4..c2a813e 100755 --- a/scss/cms.scss +++ b/scss/cms.scss @@ -17,185 +17,192 @@ } #FeaturedImage .middleColumn { - clear: none; - float: left; + clear: none; + float: left; } .has-panel .cms-content-tools.blog-admin-sidebar { - width: 280px; - border-right: none; - border-left: 1px solid #C0C0C2; - position: absolute !important; /* overrides cms !imporant style */ - right: 0px; + width: 280px; + border-right: none; + border-left: 1px solid #C0C0C2; + position: absolute !important; /* overrides cms !imporant style */ + right: 0px; top: 0; - height: 100%; + height: 100%; - .cms-panel-toggle a { - text-align: left; + .cms-panel-toggle a { + text-align: left; margin: 0; - } + } .cms-panel-toggle.south { border-top: 1px solid #aaaaaa; } - ~ .blog-admin-outer { - width: 100%; - padding-right: 280px; - position: absolute; - height: 100%; - overflow-y: hidden; - overflow-x: hidden; - box-sizing: border-box; + ~ .blog-admin-outer { + width: 100%; + padding-right: 280px; + position: absolute; + height: 100%; + overflow-y: hidden; + overflow-x: hidden; + box-sizing: border-box; - > .ss-tabset { - position: relative; - overflow: auto; - height: 100%; - width: 100%; + > .ss-tabset { + position: relative; + overflow: auto; + height: 100%; + width: 100%; - #Title { - label { - float: none; - } - .middleColumn, input { - width: 100%; - max-width: 100%; - margin-left: 0; - } - } - } - } + #Title { + label { + float: none; + } + .middleColumn, input { + width: 100%; + max-width: 100%; + margin-left: 0; + } + } + } + } - .cms-content-view { - > .field { - + .field { - margin-top: 10px; - } + .cms-content-view { + > .field { + + .field { + margin-top: 10px; + } - &.urlsegment { - .preview { - padding-top: 0; - line-height: 25px; - } + &.urlsegment { + .preview { + padding-top: 0; + line-height: 25px; + } - .edit { - float: right; - } - } + .edit { + float: right; + } + } - &.datetime { - > .middleColumn { - > .date { - width: 60%; - } + &.datetime { + > .middleColumn { + > .date { + width: 60%; + } - > .time { - width: 36%; - float: right; - } + > .time { + width: 36%; + float: right; + } - .middleColumn, input { - width: 100%; - } - } - } - } - } + .middleColumn, input { + width: 100%; + } + } + } + } + } - &.collapsed { - ~ .blog-admin-outer { - padding-right: 41px; + &.collapsed { + ~ .blog-admin-outer { + padding-right: 41px; #Root_Main { margin-right: 15px; } - } + } - } + } - &.cms-content-tools { - .cms-panel-content { - width: auto; - } - } + &.cms-content-tools { + .cms-panel-content { + width: auto; + } + } } .toggle-description { - text-indent: -1000000px; - display: inline-block; - background: url("../images/information.png") no-repeat center center; - width: 20px; - height: 20px; - margin-left: 4px; + text-indent: -1000000px; + display: inline-block; + background: url("../images/information.png") no-repeat center center; + width: 20px; + height: 20px; + margin-left: 4px; } .middleColumn.toggle-description-correct-middle { - margin-left: 0; - float: left; - width: 416px; + margin-left: 0; + float: left; + width: 416px; } label.right.toggle-description-correct-right { - display: inline-block; - margin-left: 0; - clear: none; - float: left; + display: inline-block; + margin-left: 0; + clear: none; + float: left; } .description.toggle-description-correct-description { - width: 416px; - padding: 12px 0; + width: 416px; + padding: 12px 0; } .custom-summary { - .ui-accordion-content .field { - margin: 0; - } + .ui-accordion-content .field { + margin: 0; + } - .ui-accordion-content, - .ui-accordion-content .field { - padding: 0; - } + .ui-accordion-content, + .ui-accordion-content .field { + padding: 0; + } - .ui-icon-triangle-1-e { - background-position: -16px -128px; - } + .ui-icon-triangle-1-e { + background-position: -16px -128px; + } } .cms table.ss-gridfield-table { - tr td.MergeAction { - width: 225px; + tr td.MergeAction { + width: 225px; - a { - display: block; - height: 100%; - width: 100%; - } + a { + display: block; + height: 100%; + width: 100%; + } - select { - width: 150px; - } - } + select { + width: 150px; + } + } } .cms-content-actions, .cms-preview-controls { - z-index: 999; + z-index: 999; } .blog-cms-categorisation { + .MergeActionReveal { + margin-left: 10px; + } - .MergeActionReveal { - margin-left: 10px; - } + .toolbar--content { + margin-top: 0; + } - .MergeActionReveal:after { - content: ''; - background: url('../images/move-icon.png'); - display: inline-block; - height: 16px; - width: 16px; - margin-left: 4px; - } + .MergeActionReveal:after { + content: ''; + background: url('../images/move-icon.png'); + display: inline-block; + height: 16px; + width: 16px; + margin-left: 4px; + } + + button.action { + margin-left: 5px; + } } diff --git a/src/Admin/GridFieldCategorisationConfig.php b/src/Admin/GridFieldCategorisationConfig.php index 6455903..697b0f8 100644 --- a/src/Admin/GridFieldCategorisationConfig.php +++ b/src/Admin/GridFieldCategorisationConfig.php @@ -20,7 +20,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor { parent::__construct($itemsPerPage); - $this->removeComponentsByType('GridFieldAddNewButton'); + $this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton'); $this->addComponent( new GridFieldAddByDBField('buttons-before-left') diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 18c5b47..2cd46c8 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -94,7 +94,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP if ($obj->canCreate()) { $id = $gridField->getList()->add($obj); if (!$id) { - $gridField->setError( + $gridField->setCustomValidationMessage( _t( 'GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', @@ -102,8 +102,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP array( 'class' => get_class($obj), ) - ), - 'error' + ) ); } } else { @@ -174,7 +173,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP $obj = singleton($dataClass); if (!$obj->canCreate()) { - return ""; + return ''; } $dbField = $this->getDataObjectField(); @@ -192,16 +191,17 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP $addAction = new GridField_FormAction( $gridField, 'add', - _t('GridFieldAddByDBField.Add', - 'Add {name}', "Add button text", - array( - 'name' => $obj->i18n_singular_name(), - ) + _t( + 'GridFieldAddByDBField.Add', + 'Add {name}', + 'Add button text', + ['name' => $obj->i18n_singular_name()] ), 'add', 'add' ); $addAction->setAttribute('data-icon', 'add'); + $addAction->addExtraClass('btn btn-primary'); $forTemplate = new ArrayData(array()); @@ -210,7 +210,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP $forTemplate->Fields->push($addAction); return array( - $this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField') + $this->targetFragment => $forTemplate->renderWith( + 'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField' + ) ); } } diff --git a/src/Model/Blog.php b/src/Model/Blog.php index 15bae2d..2b12b2d 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -3,7 +3,7 @@ namespace SilverStripe\Blog\Model; use Page; -use Page_Controller; +use PageController; use SilverStripe\Blog\Admin\GridFieldCategorisationConfig; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; use SilverStripe\CMS\Controllers\RootURLController; @@ -272,7 +272,7 @@ class Blog extends Page implements PermissionProvider public function RoleOf($member) { if (is_numeric($member)) { - $member = DataObject::get_by_id(Member::class, $member); + $member = Member::get()->byId($member); } if (!$member) { diff --git a/src/Model/BlogController.php b/src/Model/BlogController.php index 3dc2d26..e9688ab 100644 --- a/src/Model/BlogController.php +++ b/src/Model/BlogController.php @@ -2,7 +2,7 @@ namespace SilverStripe\Blog\Model; -use Page_Controller; +use PageController; use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\FieldType\DBDatetime; @@ -13,7 +13,7 @@ use SilverStripe\Security\Member; * @package silverstripe * @subpackage blog */ -class BlogController extends Page_Controller +class BlogController extends PageController { /** * @var array diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index 419def1..2500084 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -36,8 +36,10 @@ trait BlogObject */ public function getCMSFields() { - $fields = TabSet::create('Root', - Tab::create('Main', + $fields = TabSet::create( + 'Root', + Tab::create( + 'Main', TextField::create('Title', _t(self::class . '.Title', 'Title')) ) ); @@ -65,9 +67,10 @@ trait BlogObject return $validation; } - if ($this->getDuplicatesByUrlSegment()->count() > 0) { + if ($this->getDuplicatesByField('Title')->count() > 0) { $validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION); } + return $validation; } @@ -134,7 +137,7 @@ trait BlogObject return $extended; } - return $this->Blog()->canEdit($member); + return $this->Blog()->canDelete($member); } /** @@ -178,36 +181,37 @@ trait BlogObject $increment = (int) $increment; $filter = URLSegmentFilter::create(); - $this->URLSegment = $filter->filter($this->owner->Title); + $this->URLSegment = $filter->filter($this->Title); if ($increment > 0) { $this->URLSegment .= '-' . $increment; } - if ($this->getDuplicatesByUrlSegment()->count() > 0) { - $this->owner->generateURLSegment($increment + 1); + if ($this->getDuplicatesByField('URLSegment')->count() > 0) { + $this->generateURLSegment($increment + 1); } - return $this->owner->URLSegment; + return $this->URLSegment; } /** - * Looks for objects of the same type by url segment. + * Looks for objects o the same type and the same value by the given Field * + * @param string $field E.g. URLSegment or Title * @return DataList */ - protected function getDuplicatesByUrlSegment() + protected function getDuplicatesByField($field) { $duplicates = DataList::create(self::class) ->filter( - array( - 'URLSegment' => $this->URLSegment, - 'BlogID' => (int) $this->BlogID, - ) + [ + $field => $this->$field, + 'BlogID' => (int) $this->BlogID + ] ); if ($this->ID) { - $duplicates = $duplicates->exclude('ID', $this->ID); + $duplicates->exclude('ID', $this->ID); } return $duplicates; diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 03aa95b..4499502 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -74,7 +74,7 @@ class BlogPost extends Page private static $many_many = array( 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', - 'Authors' => 'SilverStripe\\Security\\Member' + 'Authors' => Member::class ); /** @@ -230,8 +230,6 @@ class BlogPost extends Page $fields->insertAfter($summaryHolder, 'FeaturedImage'); - $fields->push(HiddenField::create('MenuTitle')); - $urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment->setURLPrefix($this->Parent()->RelativeLink()); diff --git a/src/Model/BlogPostController.php b/src/Model/BlogPostController.php index 9891372..2b09699 100644 --- a/src/Model/BlogPostController.php +++ b/src/Model/BlogPostController.php @@ -2,13 +2,13 @@ namespace SilverStripe\Blog\Model; -use Page_Controller; +use PageController; /** * @package silverstripe * @subpackage blog */ -class BlogPostController extends Page_Controller +class BlogPostController extends PageController { } diff --git a/src/Model/BlogTag.php b/src/Model/BlogTag.php index fc96537..9e65e1e 100644 --- a/src/Model/BlogTag.php +++ b/src/Model/BlogTag.php @@ -72,6 +72,6 @@ class BlogTag extends DataObject implements CategorisationObject */ protected function getDuplicateError() { - return _t('BlogTag.Duplicate', 'A blog tags already exists with that name.'); + return _t('BlogTag.Duplicate', 'A blog tag already exists with that name.'); } } From 077929f8bf8020c8c5445813d6615dbe6a86a818 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 13 Jan 2017 15:55:48 +1300 Subject: [PATCH 23/31] Add sidebar back as a separate tab. Fix tag and category routes --- src/Model/BlogCategory.php | 3 +- src/Model/BlogObject.php | 2 +- src/Model/BlogPost.php | 61 +++++++++++++++++++------------------- src/Model/BlogTag.php | 2 +- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/Model/BlogCategory.php b/src/Model/BlogCategory.php index 28b6dd5..b520360 100644 --- a/src/Model/BlogCategory.php +++ b/src/Model/BlogCategory.php @@ -64,7 +64,7 @@ class BlogCategory extends DataObject implements CategorisationObject */ protected function getListUrlSegment() { - return 'categories'; + return 'category'; } /** @@ -74,5 +74,4 @@ class BlogCategory extends DataObject implements CategorisationObject { return _t('BlogCategory.Duplicate', 'A blog category already exists with that name.'); } - } diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index 2500084..3c0eecd 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -211,7 +211,7 @@ trait BlogObject ); if ($this->ID) { - $duplicates->exclude('ID', $this->ID); + $duplicates = $duplicates->exclude('ID', $this->ID); } return $duplicates; diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 4499502..2abae30 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -272,11 +272,6 @@ class BlogPost extends Page ); } - /** - * @todo Fix the sidebar styles for SS4 + Bootstrap - */ - return; - // Get categories and tags $parent = $this->Parent(); $categories = $parent instanceof Blog @@ -286,32 +281,36 @@ class BlogPost extends Page ? $parent->Tags() : BlogTag::get(); - $options = BlogAdminSidebar::create( - $publishDate, - $urlSegment, - TagField::create( - 'Categories', - _t('BlogPost.Categories', 'Categories'), - $categories, - $this->Categories() - ) - ->setCanCreate($this->canCreateCategories()) - ->setShouldLazyLoad(true), - TagField::create( - 'Tags', - _t('BlogPost.Tags', 'Tags'), - $tags, - $this->Tags() - ) - ->setCanCreate($this->canCreateTags()) - ->setShouldLazyLoad(true), - $authorField, - $authorNames - )->setTitle('Post Options'); - - $options->setName('blog-admin-sidebar'); - - $fields->insertBefore($options, 'Root'); + // @todo: Reimplement the sidebar + // $options = BlogAdminSidebar::create( + $fields->addFieldsToTab( + 'Root.PostOptions', + [ + $publishDate, + $urlSegment, + TagField::create( + 'Categories', + _t('BlogPost.Categories', 'Categories'), + $categories, + $this->Categories() + ) + ->setCanCreate($this->canCreateCategories()) + ->setShouldLazyLoad(true), + TagField::create( + 'Tags', + _t('BlogPost.Tags', 'Tags'), + $tags, + $this->Tags() + ) + ->setCanCreate($this->canCreateTags()) + ->setShouldLazyLoad(true), + $authorField, + $authorNames + ] + ); + // )->setTitle('Post Options'); + // $options->setName('blog-admin-sidebar'); + // $fields->insertBefore($options, 'Root'); }); $fields = parent::getCMSFields(); diff --git a/src/Model/BlogTag.php b/src/Model/BlogTag.php index 9e65e1e..fd847c2 100644 --- a/src/Model/BlogTag.php +++ b/src/Model/BlogTag.php @@ -64,7 +64,7 @@ class BlogTag extends DataObject implements CategorisationObject */ protected function getListUrlSegment() { - return 'tags'; + return 'tag'; } /** From 98645af9600af4cc89ffa987f9ef9091a98d0dac Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 17 Jan 2017 08:58:00 +1300 Subject: [PATCH 24/31] Implement Blog namespaces --- _config/comments.yml | 2 +- tests/BlogPostNotificationsTest.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/_config/comments.yml b/_config/comments.yml index ab58e2d..9e7ece3 100644 --- a/_config/comments.yml +++ b/_config/comments.yml @@ -3,7 +3,7 @@ Name: blogcommentsconfig Only: moduleexists: comments --- -Comment: +SilverStripe\Comments\Model\Comment: extensions: - SilverStripe\Blog\Model\BlogCommentExtension diff --git a/tests/BlogPostNotificationsTest.php b/tests/BlogPostNotificationsTest.php index 417502b..2f0bcb6 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -1,5 +1,6 @@ markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); - $comment = new Comment(); + $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); + $comment = new \SilverStripe\Comments\Model\Comment(); $comment->Comment = 'This is a comment'; $comment->write(); $recipients = $blogPost->notificationRecipients( @@ -41,8 +42,8 @@ class BlogPostNotificationsTest extends SapphireTest if (!class_exists('CommentNotifier')) { $this->markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); - $comment = new Comment(); + $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); + $comment = new use SilverStripe\Comments\Model\Comment(); $comment->Comment = 'This is a comment'; $comment->write(); $recipients = $blogPost->notificationRecipients( From 5eb9ec879d67472541f7f5d71dee54547aa04aa3 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 18 Jan 2017 17:12:06 +1300 Subject: [PATCH 25/31] API Update Widget implementations in blog --- src/.upgrade.yml | 5 ++ .../GridField/GridFieldConfig_BlogPost.php | 3 +- src/Widgets/BlogArchiveWidget.php | 28 +++++----- src/Widgets/BlogArchiveWidgetController.php | 14 +++++ src/Widgets/BlogCategoriesWidget.php | 51 ++++++++++++++----- .../BlogCategoriesWidgetController.php | 14 +++++ src/Widgets/BlogRecentPostsWidget.php | 17 +++---- .../BlogRecentPostsWidgetController.php | 14 +++++ src/Widgets/BlogTagsCloudWidget.php | 25 +++++---- src/Widgets/BlogTagsCloudWidgetController.php | 13 +++++ src/Widgets/BlogTagsWidget.php | 51 +++++++++++++------ src/Widgets/BlogTagsWidgetController.php | 14 +++++ 12 files changed, 187 insertions(+), 62 deletions(-) create mode 100644 src/Widgets/BlogArchiveWidgetController.php create mode 100644 src/Widgets/BlogCategoriesWidgetController.php create mode 100644 src/Widgets/BlogRecentPostsWidgetController.php create mode 100644 src/Widgets/BlogTagsCloudWidgetController.php create mode 100644 src/Widgets/BlogTagsWidgetController.php diff --git a/src/.upgrade.yml b/src/.upgrade.yml index cefd607..44f389c 100644 --- a/src/.upgrade.yml +++ b/src/.upgrade.yml @@ -22,7 +22,12 @@ mappings: GridFieldBlogPostState: SilverStripe\Blog\Forms\GridField\GridFieldBlogPostState GridFieldConfig_BlogPost: SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost BlogArchiveWidget: SilverStripe\Blog\Widgets\BlogArchiveWidget + BlogArchiveWidget_Controller: SilverStripe\Blog\Widgets\BlogArchiveWidgetController BlogCategoriesWidget: SilverStripe\Blog\Widgets\BlogCategoriesWidget + BlogCategoriesWidget_Controller: SilverStripe\Blog\Widgets\BlogCategoriesWidgetController BlogRecentPostsWidget: SilverStripe\Blog\Widgets\BlogRecentPostsWidget + BlogRecentPostsWidget_Controller: SilverStripe\Blog\Widgets\BlogRecentPostsWidgetController BlogTagsCloudWidget: SilverStripe\Blog\Widgets\BlogTagsCloudWidget + BlogTagsCloudWidget_Controller: SilverStripe\Blog\Widgets\BlogTagsCloudWidgetController BlogTagsWidget: SilverStripe\Blog\Widgets\BlogTagsWidget + BlogTagsWidget_Controller: SilverStripe\Blog\Widgets\BlogTagsWidgetController diff --git a/src/Forms/GridField/GridFieldConfig_BlogPost.php b/src/Forms/GridField/GridFieldConfig_BlogPost.php index 74d4a36..aae7be3 100644 --- a/src/Forms/GridField/GridFieldConfig_BlogPost.php +++ b/src/Forms/GridField/GridFieldConfig_BlogPost.php @@ -3,6 +3,7 @@ namespace SilverStripe\Blog\Forms\GridField; use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack; +use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState; /** * GridField config necessary for managing a SiteTree object. @@ -19,7 +20,7 @@ class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack { parent::__construct($itemsPerPage); - $this->removeComponentsByType('SilverStripe\\Lumberjack\\Forms\\GridFieldSiteTreeState'); + $this->removeComponentsByType(GridFieldSiteTreeState::class); $this->addComponent(new GridFieldBlogPostState()); } } diff --git a/src/Widgets/BlogArchiveWidget.php b/src/Widgets/BlogArchiveWidget.php index 029e421..5ea67f7 100644 --- a/src/Widgets/BlogArchiveWidget.php +++ b/src/Widgets/BlogArchiveWidget.php @@ -2,12 +2,16 @@ namespace SilverStripe\Blog\Widgets; -use SilverStripe\Blog\Model\Blog; - -if (!class_exists('Widget')) { +if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) { return; } +use SilverStripe\Blog\Model\Blog; +use SilverStripe\Control\Controller; +use SilverStripe\Forms\DropdownField; +use SilverStripe\Forms\NumericField; +use SilverStripe\Widgets\Model\Widget; + /** * @method Blog Blog() * @@ -50,7 +54,7 @@ class BlogArchiveWidget extends Widget * @var array */ private static $has_one = array( - 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class, ); /** @@ -58,13 +62,11 @@ class BlogArchiveWidget extends Widget */ public function getCMSFields() { - $self =& $this; - - $this->beforeUpdateCMSFields(function ($fields) use ($self) { + $this->beforeUpdateCMSFields(function ($fields) { /** * @var Enum $archiveType */ - $archiveType = $self->dbObject('ArchiveType'); + $archiveType = $this->dbObject('ArchiveType'); $type = $archiveType->enumValues(); @@ -76,7 +78,11 @@ class BlogArchiveWidget extends Widget * @var FieldList $fields */ $fields->merge(array( - DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()), + DropdownField::create( + 'BlogID', + _t('BlogArchiveWidget.Blog', 'Blog'), + Blog::get()->map() + ), DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type), NumericField::create('NumberToDisplay', _t('BlogArchiveWidget.NumberToDisplay', 'No. to Display')) )); @@ -136,7 +142,3 @@ class BlogArchiveWidget extends Widget return $archive; } } - -class BlogArchiveWidget_Controller extends Widget_Controller -{ -} diff --git a/src/Widgets/BlogArchiveWidgetController.php b/src/Widgets/BlogArchiveWidgetController.php new file mode 100644 index 0000000..5e01105 --- /dev/null +++ b/src/Widgets/BlogArchiveWidgetController.php @@ -0,0 +1,14 @@ + 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class, ); /** @@ -51,24 +56,44 @@ class BlogCategoriesWidget extends Widget { $this->beforeUpdateCMSFields(function (FieldList $fields) { $fields[] = DropdownField::create( - 'BlogID', _t('BlogCategoriesWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map() + 'BlogID', + _t('BlogCategoriesWidget.Blog', 'Blog'), + Blog::get()->map() ); $fields[] = NumericField::create( - 'Limit', _t('BlogCategoriesWidget.Limit.Label', 'Limit'), 0 + 'Limit', + _t('BlogCategoriesWidget.Limit.Label', 'Limit'), + 0 ) - ->setDescription(_t('BlogCategoriesWidget.Limit.Description', 'Limit the number of categories shown by this widget (set to 0 to show all categories).')) + ->setDescription( + _t( + 'BlogCategoriesWidget.Limit.Description', + 'Limit the number of categories shown by this widget (set to 0 to show all categories).' + ) + ) ->setMaxLength(3); $fields[] = DropdownField::create( - 'Order', _t('BlogCategoriesWidget.Sort.Label', 'Sort'), array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated') + 'Order', + _t('BlogCategoriesWidget.Sort.Label', 'Sort'), + array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated') ) - ->setDescription(_t('BlogCategoriesWidget.Sort.Description', 'Change the order of categories shown by this widget.')); + ->setDescription( + _t('BlogCategoriesWidget.Sort.Description', 'Change the order of categories shown by this widget.') + ); $fields[] = DropdownField::create( - 'Direction', _t('BlogCategoriesWidget.Direction.Label', 'Direction'), array('ASC' => 'Ascending', 'DESC' => 'Descending') + 'Direction', + _t('BlogCategoriesWidget.Direction.Label', 'Direction'), + array('ASC' => 'Ascending', 'DESC' => 'Descending') ) - ->setDescription(_t('BlogCategoriesWidget.Direction.Description', 'Change the direction of ordering of categories shown by this widget.')); + ->setDescription( + _t( + 'BlogCategoriesWidget.Direction.Description', + 'Change the direction of ordering of categories shown by this widget.' + ) + ); }); return parent::getCMSFields(); @@ -99,6 +124,4 @@ class BlogCategoriesWidget extends Widget } } -class BlogCategoriesWidget_Controller extends Widget_Controller -{ -} + diff --git a/src/Widgets/BlogCategoriesWidgetController.php b/src/Widgets/BlogCategoriesWidgetController.php new file mode 100644 index 0000000..b891e3a --- /dev/null +++ b/src/Widgets/BlogCategoriesWidgetController.php @@ -0,0 +1,14 @@ + 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class, ); /** @@ -54,7 +57,7 @@ class BlogRecentPostsWidget extends Widget * @var FieldList $fields */ $fields->merge(array( - DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()), + DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()), NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts')) )); }); @@ -78,7 +81,3 @@ class BlogRecentPostsWidget extends Widget return array(); } } - -class BlogRecentPostsWidget_Controller extends Widget_Controller -{ -} diff --git a/src/Widgets/BlogRecentPostsWidgetController.php b/src/Widgets/BlogRecentPostsWidgetController.php new file mode 100644 index 0000000..5c0cac0 --- /dev/null +++ b/src/Widgets/BlogRecentPostsWidgetController.php @@ -0,0 +1,14 @@ + 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class, ); /** @@ -50,8 +56,11 @@ class BlogTagsCloudWidget extends Widget * @var FieldList $fields */ $fields->push( - DropdownField::create('BlogID', _t('BlogTagsCloudWidget.Blog', - 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()) + DropdownField::create( + 'BlogID', + _t('BlogTagsCloudWidget.Blog', 'Blog'), + Blog::get()->map() + ) ); }); @@ -109,7 +118,3 @@ class BlogTagsCloudWidget extends Widget return array(); } } - -class BlogTagsCloudWidget_Controller extends Widget_Controller -{ -} diff --git a/src/Widgets/BlogTagsCloudWidgetController.php b/src/Widgets/BlogTagsCloudWidgetController.php new file mode 100644 index 0000000..bfe2f24 --- /dev/null +++ b/src/Widgets/BlogTagsCloudWidgetController.php @@ -0,0 +1,13 @@ + 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class ); /** @@ -51,24 +56,44 @@ class BlogTagsWidget extends Widget { $this->beforeUpdateCMSFields(function (Fieldlist $fields) { $fields[] = DropdownField::create( - 'BlogID', _t('BlogTagsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map() + 'BlogID', + _t('BlogTagsWidget.Blog', 'Blog'), + Blog::get()->map() ); $fields[] = NumericField::create( - 'Limit', _t('BlogTagsWidget.Limit.Label', 'Limit'), 0 + 'Limit', + _t('BlogTagsWidget.Limit.Label', 'Limit'), + 0 ) - ->setDescription(_t('BlogTagsWidget.Limit.Description', 'Limit the number of tags shown by this widget (set to 0 to show all tags).')) + ->setDescription( + _t( + 'BlogTagsWidget.Limit.Description', + 'Limit the number of tags shown by this widget (set to 0 to show all tags).' + ) + ) ->setMaxLength(3); $fields[] = DropdownField::create( - 'Order', _t('BlogTagsWidget.Sort.Label', 'Sort'), array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated') + 'Order', + _t('BlogTagsWidget.Sort.Label', 'Sort'), + array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated') ) - ->setDescription(_t('BlogTagsWidget.Sort.Description', 'Change the order of tags shown by this widget.')); + ->setDescription( + _t('BlogTagsWidget.Sort.Description', 'Change the order of tags shown by this widget.') + ); $fields[] = DropdownField::create( - 'Direction', _t('BlogTagsWidget.Direction.Label', 'Direction'), array('ASC' => 'Ascending', 'DESC' => 'Descending') + 'Direction', + _t('BlogTagsWidget.Direction.Label', 'Direction'), + array('ASC' => 'Ascending', 'DESC' => 'Descending') ) - ->setDescription(_t('BlogTagsWidget.Direction.Description', 'Change the direction of ordering of tags shown by this widget.')); + ->setDescription( + _t( + 'BlogTagsWidget.Direction.Description', + 'Change the direction of ordering of tags shown by this widget.' + ) + ); }); return parent::getCMSFields(); @@ -98,7 +123,3 @@ class BlogTagsWidget extends Widget return $query; } } - -class BlogTagsWidget_Controller extends Widget_Controller -{ -} diff --git a/src/Widgets/BlogTagsWidgetController.php b/src/Widgets/BlogTagsWidgetController.php new file mode 100644 index 0000000..07e6f11 --- /dev/null +++ b/src/Widgets/BlogTagsWidgetController.php @@ -0,0 +1,14 @@ + Date: Thu, 19 Jan 2017 17:09:17 +1300 Subject: [PATCH 26/31] FIX Move upgrade mapping to root folder. Fixes blog classes not being resolved by upgrader. --- src/.upgrade.yml => .upgrade.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/.upgrade.yml => .upgrade.yml (100%) diff --git a/src/.upgrade.yml b/.upgrade.yml similarity index 100% rename from src/.upgrade.yml rename to .upgrade.yml From 3da05818affe2602282bdfe4dbea8eb7db457a8b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 24 Jan 2017 13:45:07 +1300 Subject: [PATCH 27/31] Move BlogFilter_GridField to its own class --- .upgrade.yml | 2 +- src/Model/BlogFilter.php | 23 +++----------------- src/Model/BlogFilter/BlogFilterGridField.php | 21 ++++++++++++++++++ 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 src/Model/BlogFilter/BlogFilterGridField.php diff --git a/.upgrade.yml b/.upgrade.yml index 44f389c..813650c 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -4,7 +4,7 @@ mappings: GridFieldMergeAction: SilverStripe\Blog\Admin\GridFieldMergeAction BlogCommentExtension: SilverStripe\Blog\Model\BlogCommentExtension BlogFilter: SilverStripe\Blog\Model\BlogFilter - BlogFilter_GridField: SilverStripe\Blog\Model\BlogFilter_GridField + BlogFilter_GridField: SilverStripe\Blog\Model\BlogFilter\BlogFilterGridField BlogMemberExtension: SilverStripe\Blog\Model\BlogMemberExtension BlogPostFilter: SilverStripe\Blog\Model\BlogPostFilter BlogPostNotifications: SilverStripe\Blog\Model\BlogPostNotifications diff --git a/src/Model/BlogFilter.php b/src/Model/BlogFilter.php index 48c1c37..5594354 100644 --- a/src/Model/BlogFilter.php +++ b/src/Model/BlogFilter.php @@ -3,11 +3,11 @@ namespace SilverStripe\Blog\Model; use SilverStripe\Blog\Model\Blog; +use SilverStripe\Blog\Model\BlogFilter\BlogFilterGridField; use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\FormTransformation; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\Tab; use SilverStripe\Lumberjack\Model\Lumberjack; @@ -59,7 +59,7 @@ class BlogFilter extends Lumberjack */ protected function subclassForBlog() { - return in_array(get_class($this->owner), ClassInfo::subclassesFor('SilverStripe\\Blog\\Model\\Blog')); + return in_array(get_class($this->owner), ClassInfo::subclassesFor(Blog::class)); } /** @@ -104,7 +104,7 @@ class BlogFilter extends Lumberjack 'ClassName' => $excluded )); - $gridField = BlogFilter_GridField::create( + $gridField = BlogFilterGridField::create( 'ChildPages', $this->getLumberjackTitle(), $pages, @@ -117,20 +117,3 @@ class BlogFilter extends Lumberjack } } } - - -/** - * Enables children of non-editable pages to be edited. - */ -class BlogFilter_GridField extends GridField -{ - /** - * @param FormTransformation $transformation - * - * @return $this - */ - public function transform(FormTransformation $transformation) - { - return $this; - } -} diff --git a/src/Model/BlogFilter/BlogFilterGridField.php b/src/Model/BlogFilter/BlogFilterGridField.php new file mode 100644 index 0000000..4ad64d6 --- /dev/null +++ b/src/Model/BlogFilter/BlogFilterGridField.php @@ -0,0 +1,21 @@ + Date: Tue, 24 Jan 2017 14:10:56 +1300 Subject: [PATCH 28/31] FIX Missed GridField import in BlogFilterGridField --- src/Model/BlogFilter.php | 1 - src/Model/BlogFilter/BlogFilterGridField.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/BlogFilter.php b/src/Model/BlogFilter.php index 5594354..da53fc3 100644 --- a/src/Model/BlogFilter.php +++ b/src/Model/BlogFilter.php @@ -8,7 +8,6 @@ use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\Tab; use SilverStripe\Lumberjack\Model\Lumberjack; use SilverStripe\ORM\DataObject; diff --git a/src/Model/BlogFilter/BlogFilterGridField.php b/src/Model/BlogFilter/BlogFilterGridField.php index 4ad64d6..190ee1d 100644 --- a/src/Model/BlogFilter/BlogFilterGridField.php +++ b/src/Model/BlogFilter/BlogFilterGridField.php @@ -3,6 +3,7 @@ namespace SilverStripe\Blog\Model\BlogFilter; use SilverStripe\Forms\FormTransformation; +use SilverStripe\Forms\GridField\GridField; /** * Enables children of non-editable pages to be edited. From c004bad7b8a7e2dde7e559f8f58030e9ab5595fd Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 26 Jan 2017 21:28:42 +1300 Subject: [PATCH 29/31] FIX Update class imports, fix broken test, add missing multibyte logic back, fix condition for generating URLSegment (also missing) --- composer.json | 3 +- src/Forms/BlogAdminSidebar.php | 2 +- src/Forms/GridField/GridFieldAddByDBField.php | 6 +-- src/Model/Blog.php | 18 ++++--- src/Model/BlogCategory.php | 6 ++- src/Model/BlogMemberExtension.php | 6 ++- src/Model/BlogObject.php | 8 ++- src/Model/BlogPost.php | 12 +++-- src/Model/BlogTag.php | 6 ++- tests/BlogCategoryTest.php | 44 ++++++++------- tests/BlogPostFilterTest.php | 7 ++- tests/BlogPostNotificationsTest.php | 6 ++- tests/BlogPostTest.php | 32 +++++------ tests/BlogTagTest.php | 46 ++++++++-------- tests/BlogTagsCloudWidgetTest.php | 13 +++-- tests/BlogTest.php | 54 ++++++++++--------- 16 files changed, 151 insertions(+), 118 deletions(-) diff --git a/composer.json b/composer.json index ae08702..dbaf739 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ }, "autoload": { "psr-4": { - "SilverStripe\\Blog\\": "src/" + "SilverStripe\\Blog\\": "src/", + "SilverStripe\\Blog\\Tests\\": "tests/" } }, "license": "BSD-2-Clause", diff --git a/src/Forms/BlogAdminSidebar.php b/src/Forms/BlogAdminSidebar.php index a3c26eb..59c433a 100644 --- a/src/Forms/BlogAdminSidebar.php +++ b/src/Forms/BlogAdminSidebar.php @@ -2,8 +2,8 @@ namespace SilverStripe\Blog\Forms; -use SilverStripe\Forms\FieldGroup; use SilverStripe\Control\Cookie; +use SilverStripe\Forms\FieldGroup; class BlogAdminSidebar extends FieldGroup { diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 2cd46c8..54dc8db 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -209,10 +209,6 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP $forTemplate->Fields->push($textField); $forTemplate->Fields->push($addAction); - return array( - $this->targetFragment => $forTemplate->renderWith( - 'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField' - ) - ); + return array($this->targetFragment => $forTemplate->renderWith(self::class)); } } diff --git a/src/Model/Blog.php b/src/Model/Blog.php index 2b12b2d..221787f 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -6,6 +6,10 @@ use Page; use PageController; use SilverStripe\Blog\Admin\GridFieldCategorisationConfig; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; +use SilverStripe\Blog\Model\BlogCategory; +use SilverStripe\Blog\Model\BlogFilter; +use SilverStripe\Blog\Model\BlogPost; +use SilverStripe\Blog\Model\BlogTag; use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\Control\Controller; use SilverStripe\Control\RSS\RSSFeed; @@ -92,31 +96,31 @@ class Blog extends Page implements PermissionProvider * @var array */ private static $has_many = array( - 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', - 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', + 'Tags' => BlogTag::class, + 'Categories' => BlogCategory::class, ); /** * @var array */ private static $many_many = array( - 'Editors' => 'SilverStripe\\Security\\Member', - 'Writers' => 'SilverStripe\\Security\\Member', - 'Contributors' => 'SilverStripe\\Security\\Member', + 'Editors' => Member::class, + 'Writers' => Member::class, + 'Contributors' => Member::class, ); /** * @var array */ private static $allowed_children = array( - 'SilverStripe\\Blog\\Model\\BlogPost', + BlogPost::class, ); /** * @var array */ private static $extensions = array( - 'SilverStripe\\Blog\\Model\\BlogFilter', + BlogFilter::class, ); /** diff --git a/src/Model/BlogCategory.php b/src/Model/BlogCategory.php index b520360..e527d71 100644 --- a/src/Model/BlogCategory.php +++ b/src/Model/BlogCategory.php @@ -2,7 +2,9 @@ namespace SilverStripe\Blog\Model; +use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\BlogObject; +use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\CategorisationObject; use SilverStripe\ORM\DataObject; @@ -49,14 +51,14 @@ class BlogCategory extends DataObject implements CategorisationObject * @var array */ private static $has_one = array( - 'Blog' => 'SilverStripe\\Blog\\Model\\Blog', + 'Blog' => Blog::class, ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', + 'BlogPosts' => BlogPost::class, ); /** diff --git a/src/Model/BlogMemberExtension.php b/src/Model/BlogMemberExtension.php index 405145a..3f7d43b 100644 --- a/src/Model/BlogMemberExtension.php +++ b/src/Model/BlogMemberExtension.php @@ -2,7 +2,9 @@ namespace SilverStripe\Blog\Model; +use SilverStripe\Assets\Image; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; +use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\Tab; @@ -31,14 +33,14 @@ class BlogMemberExtension extends DataExtension * @var array */ private static $has_one = array( - 'BlogProfileImage' => 'SilverStripe\\Assets\\Image' + 'BlogProfileImage' => Image::class ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' + 'BlogPosts' => BlogPost::class ); /** diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index 3c0eecd..fd8bded 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -164,7 +164,7 @@ trait BlogObject protected function onBeforeWrite() { parent::onBeforeWrite(); - if (empty($this->URLSegment)) { + if ($this->exists() || empty($this->URLSegment)) { return $this->generateURLSegment(); } } @@ -181,6 +181,12 @@ trait BlogObject $increment = (int) $increment; $filter = URLSegmentFilter::create(); + // Setting this to on. Because of the UI flow, it would be quite a lot of work + // to support turning this off. (ie. the add by title flow would not work). + // If this becomes a problem we can approach it then. + // @see https://github.com/silverstripe/silverstripe-blog/issues/376 + $filter->setAllowMultibyte(true); + $this->URLSegment = $filter->filter($this->Title); if ($increment > 0) { diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 2abae30..ace1085 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -3,7 +3,11 @@ namespace SilverStripe\Blog\Model; use Page; +use SilverStripe\Assets\Image; use SilverStripe\Blog\Forms\BlogAdminSidebar; +use SilverStripe\Blog\Model\BlogCategory; +use SilverStripe\Blog\Model\BlogPostFilter; +use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Control\Controller; use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\HiddenField; @@ -65,15 +69,15 @@ class BlogPost extends Page * @var array */ private static $has_one = array( - 'FeaturedImage' => 'SilverStripe\\Assets\\Image' + 'FeaturedImage' => Image::class ); /** * @var array */ private static $many_many = array( - 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', - 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', + 'Categories' => BlogCategory::class, + 'Tags' => BlogTag::class, 'Authors' => Member::class ); @@ -90,7 +94,7 @@ class BlogPost extends Page * @var array */ private static $extensions = array( - 'SilverStripe\\Blog\\Model\\BlogPostFilter' + BlogPostFilter::class ); /** diff --git a/src/Model/BlogTag.php b/src/Model/BlogTag.php index fd847c2..f8cbb45 100644 --- a/src/Model/BlogTag.php +++ b/src/Model/BlogTag.php @@ -3,7 +3,9 @@ namespace SilverStripe\Blog\Model; use SilverStripe\ORM\DataObject; +use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\BlogObject; +use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\CategorisationObject; /** @@ -49,14 +51,14 @@ class BlogTag extends DataObject implements CategorisationObject * @var array */ private static $has_one = array( - 'Blog' => 'SilverStripe\\Blog\\Model\\Blog' + 'Blog' => Blog::class ); /** * @var array */ private static $belongs_many_many = array( - 'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' + 'BlogPosts' => BlogPost::class ); /** diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index 2c1d0cb..d9de583 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -1,8 +1,12 @@ logout(); } - $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); + $this->objFromFixture(BlogPost::class, 'FirstBlogPost'); /** * @var BlogCategory $category */ - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); } @@ -65,7 +69,7 @@ class BlogCategoryTest extends FunctionalTest */ public function testAllowMultibyteUrlSegment() { - $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $cat = new BlogCategory(); $cat->BlogID = $blog->ID; $cat->Title = 'تست'; @@ -80,10 +84,10 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); + $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); + $editor = $this->objFromFixture(Member::class, 'Editor'); + $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); } @@ -95,20 +99,20 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); @@ -118,10 +122,10 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $category = singleton('SilverStripe\\Blog\\Model\\BlogCategory'); + $category = singleton(BlogCategory::class); $this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.'); $this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); @@ -131,19 +135,19 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); - $category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); + $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); } diff --git a/tests/BlogPostFilterTest.php b/tests/BlogPostFilterTest.php index 04aa271..c78fbc9 100755 --- a/tests/BlogPostFilterTest.php +++ b/tests/BlogPostFilterTest.php @@ -1,5 +1,8 @@ objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts'); diff --git a/tests/BlogPostNotificationsTest.php b/tests/BlogPostNotificationsTest.php index 2f0bcb6..4129388 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -1,5 +1,7 @@ markTestSkipped('Comments Notification module is not installed'); } $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); - $comment = new use SilverStripe\Comments\Model\Comment(); + $comment = new SilverStripe\Comments\Model\Comment(); $comment->Comment = 'This is a comment'; $comment->write(); $recipients = $blogPost->notificationRecipients( diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index a5c5a69..09bacba 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -1,8 +1,12 @@ objFromFixture('SilverStripe\\Security\\Member', $user); - $pageRecord = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', $page); + $userRecord = $this->objFromFixture(Member::class, $user); + $pageRecord = $this->objFromFixture(BlogPost::class, $page); DBDatetime::set_mock_now($date); $this->assertEquals($canView, $pageRecord->canView($userRecord)); } @@ -78,12 +74,12 @@ class BlogPostTest extends SapphireTest public function testCandidateAuthors() { - $blogpost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); + $blogpost = $this->objFromFixture(BlogPost::class, 'PostC'); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); //Set the group to draw Members from - Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'restrict_authors_to_group', 'blogusers'); + Config::inst()->update(BlogPost::class, 'restrict_authors_to_group', 'blogusers'); $this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); @@ -94,12 +90,12 @@ class BlogPostTest extends SapphireTest public function testCanViewFuturePost() { - $blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'NullPublishDate'); + $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); + $editor = $this->objFromFixture(Member::class, 'BlogEditor'); $this->assertTrue($blogPost->canView($editor)); - $visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); + $visitor = $this->objFromFixture(Member::class, 'Visitor'); $this->assertFalse($blogPost->canView($visitor)); } @@ -109,10 +105,10 @@ class BlogPostTest extends SapphireTest */ public function testGetDate() { - $blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate'); + $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate'); $this->assertNull($blogPost->getDate()); - $blogPost = $this->objFromFixture('BlogPost', 'PostA'); + $blogPost = $this->objFromFixture(BlogPost::class, 'PostA'); $this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate()); } } diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index c27a46c..464a918 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -1,7 +1,11 @@ logout(); } - $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); + $this->objFromFixture(BlogPost::class, 'FirstBlogPost'); /** * @var BlogTag $tag */ - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); + $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); } @@ -65,7 +69,7 @@ class BlogTagTest extends FunctionalTest */ public function testAllowMultibyteUrlSegment() { - $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $tag = new BlogTag(); $tag->BlogID = $blog->ID; $tag->Title = 'تست'; @@ -83,15 +87,15 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); + $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); + $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); @@ -101,20 +105,20 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); + $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); + $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); + $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); @@ -124,10 +128,10 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $tag = singleton('SilverStripe\\Blog\\Model\\BlogTag'); + $tag = singleton(BlogTag::class); $this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.'); $this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); @@ -137,20 +141,20 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); + $admin = $this->objFromFixture(Member::class, 'Admin'); + $editor = $this->objFromFixture(Member::class, 'Editor'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); + $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); + $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); - $tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); + $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); diff --git a/tests/BlogTagsCloudWidgetTest.php b/tests/BlogTagsCloudWidgetTest.php index f2564cc..315706e 100644 --- a/tests/BlogTagsCloudWidgetTest.php +++ b/tests/BlogTagsCloudWidgetTest.php @@ -1,6 +1,9 @@ markTestSkipped('Widgets module not installed'); } @@ -31,11 +34,11 @@ class BlogTagsCloudWidgetTest extends SapphireTest public function testGetTags() { - if (!class_exists('Widget')) { + if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) { $this->markTestSkipped('Widgets module not installed'); } $widget = new BlogTagsCloudWidget(); - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); + $blog = $this->objFromFixture(Blog::class, 'FourthBlog'); $widget->BlogID = $blog->ID; $widget->write(); $tags = $widget->getTags()->toArray(); diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 9a64673..386769b 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -1,6 +1,10 @@ objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $blog->publish('Stage', 'Live'); } @@ -62,17 +66,17 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); - Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', true); + Config::inst()->update(BlogPost::class, 'show_in_sitetree', true); $classes = $blog->getExcludedSiteTreeClassNames(); - $this->assertNotContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); + $this->assertNotContains(BlogPost::class, $classes, 'BlogPost class should be hidden.'); - Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', false); + Config::inst()->update(BlogPost::class, 'show_in_sitetree', false); $classes = $blog->getExcludedSiteTreeClassNames(); - $this->assertContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); + $this->assertContains(BlogPost::class, $classes, 'BlogPost class should be hidden.'); } public function testGetArchivedBlogPosts() @@ -86,7 +90,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $archive = $blog->getArchivedBlogPosts(2013); @@ -108,7 +112,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '01'); @@ -147,7 +151,7 @@ class BlogTest extends SapphireTest */ public function testArchiveYear() { - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $controller = new BlogController($blog); $this->requestURL($controller, 'first-post/archive/'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); @@ -168,47 +172,47 @@ class BlogTest extends SapphireTest /** * @var Blog $firstBlog */ - $firstBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog'); /** * @var Blog $fourthBlog */ - $fourthBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); + $fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog'); /** * @var BlogPost $postA */ - $postA = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostA'); + $postA = $this->objFromFixture(BlogPost::class, 'PostA'); /** * @var BlogPost $postB */ - $postB = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostB'); + $postB = $this->objFromFixture(BlogPost::class, 'PostB'); /** * @var BlogPost $postC */ - $postC = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); + $postC = $this->objFromFixture(BlogPost::class, 'PostC'); /** * @var Member $editor */ - $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); + $editor = $this->objFromFixture(Member::class, 'BlogEditor'); /** * @var Member $writer */ - $writer = $this->objFromFixture('SilverStripe\\Security\\Member', 'Writer'); + $writer = $this->objFromFixture(Member::class, 'Writer'); /** * @var Member $contributor */ - $contributor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Contributor'); + $contributor = $this->objFromFixture(Member::class, 'Contributor'); /** * @var Member $visitor */ - $visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); + $visitor = $this->objFromFixture(Member::class, 'Visitor'); $this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); @@ -286,7 +290,7 @@ class BlogTest extends SapphireTest public function testFilteredCategories() { - $blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); + $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $controller = new BlogController($blog); // Root url @@ -305,10 +309,10 @@ class BlogTest extends SapphireTest ); // Posts - $firstPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); - $secondPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondBlogPost'); - $firstFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstFutureBlogPost'); - $secondFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondFutureBlogPost'); + $firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost'); + $secondPostID = $this->idFromFixture(BlogPost::class, 'SecondBlogPost'); + $firstFuturePostID = $this->idFromFixture(BlogPost::class, 'FirstFutureBlogPost'); + $secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost'); // Request first tag $this->requestURL($controller, 'first-post/tag/first-tag'); @@ -336,7 +340,7 @@ class BlogTest extends SapphireTest $request = new HTTPRequest('get', $url); $request->match('$URLSegment//$Action/$ID/$OtherID'); $request->shift(); - $controller->init(); + $controller->doInit(); $controller->handleRequest($request, new DataModel()); } From 2bb61dcfcced97a32eff208ae80f5d5bf7584840 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 26 Jan 2017 22:42:05 +1300 Subject: [PATCH 30/31] TEST Move coverage run to PHP 7.1 (for speed). Remove ocular in favour of codecov. Add default phpunit.xml with coverage whitelist. --- .travis.yml | 12 ++++-------- phpunit.xml.dist | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 phpunit.xml.dist diff --git a/.travis.yml b/.travis.yml index ab21202..fe69f58 100755 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ matrix: env: DB=MYSQL CORE_RELEASE=4 - php: 5.6 - env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 + env: DB=MYSQL CORE_RELEASE=4 - php: 5.6 env: DB=PGSQL CORE_RELEASE=4 - php: 5.6 @@ -34,11 +34,7 @@ matrix: env: DB=MYSQL CORE_RELEASE=4 - php: 7.1 - env: DB=MYSQL CORE_RELEASE=4 - - php: 7.1 - env: DB=PGSQL CORE_RELEASE=4 - - php: 7.1 - env: DB=SQLITE CORE_RELEASE=4 + env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 before_script: @@ -47,6 +43,7 @@ before_script: - git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "silverstripe/comments" --require "silverstripe/widgets" - cd ~/builds/ss + - mv "$MODULE_PATH/phpunit.xml.dist" . #Execute tests with or without coverage script: @@ -60,5 +57,4 @@ script: after_script: - "if [ \"$COVERAGE\" = \"1\" ]; then mv coverage.clover ~/build/$TRAVIS_REPO_SLUG/; fi" - cd ~/build/$TRAVIS_REPO_SLUG - - wget https://scrutinizer-ci.com/ocular.phar - - "if [ \"$COVERAGE\" = \"1\" ]; then travis_retry codecov && travis_retry php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi" + - "if [ \"$COVERAGE\" = \"1\" ]; then travis_retry codecov; fi" diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..f7339cb --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + blog/tests + + + + + + + + + blog/src/ + + blog/tests/ + + + + From 8fa9207693ddd41c7d49dbfcbc55ad69f6b0a750 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 27 Jan 2017 00:20:25 +1300 Subject: [PATCH 31/31] TEST Move coverage build to the start of the matrix, and only post coverage on success --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe69f58..f64e3c1 100755 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,9 @@ env: matrix: include: + - php: 7.1 + env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 + - php: 5.5 env: DB=MYSQL CORE_RELEASE=4 @@ -33,10 +36,6 @@ matrix: - php: 7.0 env: DB=MYSQL CORE_RELEASE=4 - - php: 7.1 - env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 - - before_script: - phpenv rehash - composer self-update || true @@ -53,8 +52,8 @@ script: # Execute tests with coverage. Do this for a small - "if [ \"$COVERAGE\" = \"1\" ]; then vendor/bin/phpunit --coverage-clover=coverage.clover $MODULE_PATH/tests/; fi" -#Upload coverage even if there is a failure -after_script: +# Upload code coverage when tests pass +after_success: - "if [ \"$COVERAGE\" = \"1\" ]; then mv coverage.clover ~/build/$TRAVIS_REPO_SLUG/; fi" - cd ~/build/$TRAVIS_REPO_SLUG - "if [ \"$COVERAGE\" = \"1\" ]; then travis_retry codecov; fi"