mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Fix some incorrect table/model namespace issues
This commit is contained in:
parent
13a5badff5
commit
72a9f041c2
@ -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()
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user