Remove deprecated@2.0. Update Migrate task to check table name. Minor tweaks to class names. Use Director::absoluteURL.

This commit is contained in:
Robbie Averill 2017-01-17 17:33:39 +13:00
parent 6aeab9f823
commit 7a92b0915d
13 changed files with 30 additions and 508 deletions

View File

@ -18,7 +18,7 @@ before_install:
env:
global:
- DB=MYSQL CORE_RELEASE=4
- DB=MYSQL CORE_RELEASE=master
- MODULE_PATH=comments
# Set to 1 in the matrix to enable code coverage
@ -28,15 +28,15 @@ matrix:
include:
- php: 5.6
#CommentsListTest breaks with this env: DB=MYSQL CORE_RELEASE=3.2 COVERAGE=1
env: DB=SQLITE CORE_RELEASE=4 COVERAGE=1
env: DB=SQLITE CORE_RELEASE=master COVERAGE=1
- php: 5.6
env: DB=MYSQL CORE_RELEASE=4
env: DB=MYSQL CORE_RELEASE=master
- php: 7.0
env: DB=MYSQL CORE_RELEASE=4
env: DB=MYSQL CORE_RELEASE=master
- php: 7.1
env: DB=MYSQL CORE_RELEASE=4
env: DB=MYSQL CORE_RELEASE=master
- php: 5.6
env: DB=PGSQL CORE_RELEASE=4
env: DB=PGSQL CORE_RELEASE=master
before_script:
- phpenv rehash

View File

@ -1,9 +1,7 @@
mappings:
Commenting: SilverStripe\Comments\Commenting
CommentAdmin: SilverStripe\Comments\Admin\CommentAdmin
CommentsGridField: SilverStripe\Comments\Admin\CommentsGridField
CommentsGridFieldAction: SilverStripe\Comments\Admin\CommentsGridFieldAction
CommentsGridFieldBulkAction: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction
CommentsGridFieldBulkAction_Handlers: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handlers
CommentsGridFieldConfig: SilverStripe\Comments\Admin\CommentsGridFieldConfig
CommentingController: SilverStripe\Comments\Controllers\CommentingController

View File

@ -1,6 +1,6 @@
<?php
\SilverStripe\Dev\Deprecation::notification_version('2.0', 'comments');
\SilverStripe\Dev\Deprecation::notification_version('3.0', 'comments');
define('COMMENTS_DIR', basename(__DIR__));
define('COMMENTS_THIRDPARTY', COMMENTS_DIR . DIRECTORY_SEPARATOR . 'thirdparty');

View File

@ -5,7 +5,3 @@ After: framework/routes#coreroutes
SilverStripe\Control\Director:
rules:
comments: SilverStripe\Comments\Controllers\CommentingController
# handle old 2.4 style urls
CommentingController//$Action/$ID/$OtherID: SilverStripe\Comments\Controllers\CommentingController
PageComments/$Action/$ID/$OtherID: SilverStripe\Comments\Controllers\CommentingController
PageCommentsController/$Action/$ID/$OtherID: SilverStripe\Comments\Controllers\CommentingController

View File

@ -1,13 +0,0 @@
<?php
namespace SilverStripe\Comments\Admin;
use Colymba\BulkManager\GridFieldBulkActionHandler;
/**
* @package comments
*/
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler
{
}

View File

@ -2,8 +2,8 @@
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
use Colymba\BulkManager\GridFieldBulkActionHandler;
use SilverStripe\Core\Convert;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
@ -12,19 +12,13 @@ use SilverStripe\Control\HTTPResponse;
*
* @package comments
*/
class Handlers extends CommentsGridFieldBulkAction
class Handler extends GridFieldBulkActionHandler
{
/**
* {@inheritDoc}
*/
private static $allowed_actions = array(
'spam',
'approve',
);
/**
* {@inheritDoc}
*/
private static $url_handlers = array(
'spam' => 'spam',
'approve' => 'approve',

View File

@ -3,14 +3,11 @@
namespace SilverStripe\Comments\Admin;
use Colymba\BulkManager\GridFieldBulkManager;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handlers;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
/**
* @package comments
*/
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
{
public function __construct($itemsPerPage = 25)
@ -39,7 +36,7 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
$manager->addBulkAction(
'spam',
_t('CommentsGridFieldConfig.SPAM', 'Spam'),
Handlers::class,
Handler::class,
array(
'isAjax' => true,
'icon' => 'cross',
@ -50,7 +47,7 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
$manager->addBulkAction(
'approve',
_t('CommentsGridFieldConfig.APPROVE', 'Approve'),
Handlers::class,
Handler::class,
array(
'isAjax' => true,
'icon' => 'cross',

View File

@ -1,170 +0,0 @@
<?php
namespace SilverStripe\Comments;
use InvalidArgumentException;
use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
/**
* Helper Class for storing the configuration options. Retains the mapping between
* objects which have comments attached and the related configuration options.
*
* Also handles adding the Commenting extension to the {@link DataObject} on behalf
* of the user.
*
* For documentation on how to use this class see docs/en/Configuration.md
*
* @deprecated since version 2.0
*
* @package comments
*/
class Commenting
{
/**
* Adds commenting to a {@link DataObject}
*
* @deprecated since version 2.0
*
* @param string classname to add commenting to
* @param array $settings Settings. See {@link self::$default_config} for
* available settings
*
* @throws InvalidArgumentException
*/
public static function add($class, $settings = false)
{
Deprecation::notice('2.0', 'Using Commenting::add is deprecated. Please use the config API instead');
Config::inst()->update($class, 'extensions', array(CommentsExtension::class));
// Check if settings must be customised
if ($settings === false) {
return;
}
if (!is_array($settings)) {
throw new InvalidArgumentException('$settings needs to be an array or null');
}
Config::inst()->update($class, 'comments', $settings);
}
/**
* Removes commenting from a {@link DataObject}. Does not remove existing comments
* but does remove the extension.
*
* @deprecated since version 2.0
*
* @param string $class Class to remove {@link CommentsExtension} from
*/
public static function remove($class)
{
Deprecation::notice('2.0', 'Using Commenting::remove is deprecated. Please use the config API instead');
$class::remove_extension(CommentsExtension::class);
}
/**
* Returns whether a given class name has commenting enabled
*
* @deprecated since version 2.0
*
* @return bool
*/
public static function has_commenting($class)
{
Deprecation::notice('2.0', 'Using Commenting::has_commenting is deprecated. Please use the config API instead');
return $class::has_extension(CommentsExtension::class);
}
/**
* Sets a value for a class of a given config setting. Passing 'all' as the class
* sets it for everything
*
* @deprecated since version 2.0
*
* @param string $class Class to set the value on. Passing 'all' will set it to all
* active mappings
* @param string $key setting to change
* @param mixed $value value of the setting
*/
public static function set_config_value($class, $key, $value = false)
{
Deprecation::notice('2.0', 'Commenting::set_config_value is deprecated. Use the config api instead');
if ($class === 'all') {
$class = CommentsExtension::class;
}
Config::inst()->update($class, 'comments', array($key => $value));
}
/**
* Returns a given config value for a commenting class
*
* @deprecated since version 2.0
*
* @param string $class
* @param string $key config value to return
*
* @throws Exception
* @return mixed
*/
public static function get_config_value($class, $key)
{
Deprecation::notice(
'2.0',
'Using Commenting::get_config_value is deprecated. Please use $parent->getCommentsOption() or '
. 'CommentingController::getOption() instead'
);
// Get settings
if (!$class) {
$class = CommentsExtension::class;
} elseif (!$class::has_extension(CommentsExtension::class)) {
throw new InvalidArgumentException("$class does not have commenting enabled");
}
return singleton($class)->getCommentsOption($key);
}
/**
* Determines whether a config value on the commenting extension
* matches a given value.
*
* @deprecated since version 2.0
*
* @param string $class
* @param string $key
* @param string $value Expected value
* @return boolean
*/
public static function config_value_equals($class, $key, $value)
{
$check = self::get_config_value($class, $key);
if ($check && ($check == $value)) {
return true;
}
}
/**
* Return whether a user can post on a given commenting instance
*
* @deprecated since version 2.0
*
* @param string $class
* @return boolean true
*/
public static function can_member_post($class)
{
Deprecation::notice('2.0', 'Use $instance->canPostComment() directly instead');
$member = Member::currentUser();
// Check permission
$permission = self::get_config_value($class, 'required_permission');
if ($permission && !Permission::check($permission)) {
return false;
}
// Check login required
$requireLogin = self::get_config_value($class, 'require_login');
return !$requireLogin || $member;
}
}

View File

@ -309,20 +309,6 @@ class CommentsExtension extends DataExtension
return $list;
}
/**
* Check if comments are configured for this page even if they are currently disabled.
* Do not include the comments on pages which don't have id's such as security pages
*
* @deprecated since version 2.0
*
* @return boolean
*/
public function getCommentsConfigured()
{
Deprecation::notice('2.0', 'getCommentsConfigured is deprecated. Use getCommentsEnabled instead');
return true; // by virtue of all classes with this extension being 'configured'
}
/**
* Determine if comments are enabled for this instance
*
@ -353,15 +339,6 @@ class CommentsExtension extends DataExtension
return $this->owner->getCommentsOption('comments_holder_id');
}
/**
* @deprecated since version 2.0
*/
public function getPostingRequiresPermission()
{
Deprecation::notice('2.0', 'Use getPostingRequiredPermission instead');
return $this->getPostingRequiredPermission();
}
/**
* Permission codes required in order to post (or empty if none required)
*
@ -372,12 +349,6 @@ class CommentsExtension extends DataExtension
return $this->owner->getCommentsOption('required_permission');
}
public function canPost()
{
Deprecation::notice('2.0', 'Use canPostComment instead');
return $this->canPostComment();
}
/**
* Determine if a user can post comments on this item
*
@ -431,12 +402,6 @@ class CommentsExtension extends DataExtension
return $this->owner->canEdit($member);
}
public function getRssLink()
{
Deprecation::notice('2.0', 'Use getCommentRSSLink instead');
return $this->getCommentRSSLink();
}
/**
* Gets the RSS link to all comments
*
@ -444,13 +409,7 @@ class CommentsExtension extends DataExtension
*/
public function getCommentRSSLink()
{
return Controller::join_links(Director::baseURL(), 'comments/rss');
}
public function getRssLinkPage()
{
Deprecation::notice('2.0', 'Use getCommentRSSLinkPage instead');
return $this->getCommentRSSLinkPage();
return Director::absoluteURL('comments/rss');
}
/**
@ -524,16 +483,6 @@ class CommentsExtension extends DataExtension
return (is_subclass_of($class, SiteTree::class)) || ($class == SiteTree::class);
}
/**
* @deprecated 1.0 Please use {@link CommentsExtension->CommentsForm()}
*/
public function PageComments()
{
// This method is very commonly used, don't throw a warning just yet
Deprecation::notice('1.0', '$PageComments is deprecated. Please use $CommentsForm');
return $this->CommentsForm();
}
/**
* Get the commenting option for this object
*

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Comments\Tasks;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DB;
@ -13,26 +14,24 @@ use SilverStripe\ORM\DB;
*/
class MigrateCommentParentsTask extends BuildTask
{
/**
* {@inheritDoc}
*/
private static $segment = 'MigrateCommentParentsTask';
/**
* {@inheritDoc}
*/
protected $title = 'Migrate Comment Parent classes from 3.x';
/**
* {@inheritDoc}
*/
protected $description = 'Migrates all 3.x Comment BaseClass fields to the new ParentClass fields in 4.0';
/**
* {@inheritDoc}
* @param HTTPRequest $request
*/
public function run($request)
{
// Check if anything needs to be done
$tableName = Comment::getSchema()->tableName(Comment::class);
if (!DB::get_schema()->hasField($tableName, 'BaseClass')) {
DB::alteration_message('"BaseClass" does not exist on "' . $tableName . '", nothing to upgrade.', 'notice');
return;
}
// Set the class names to fully qualified class names first
$remapping = Config::inst()->get('SilverStripe\\ORM\\DatabaseAdmin', 'classname_value_remapping');
$updateQuery = "UPDATE \"Comment\" SET \"BaseClass\" = ? WHERE \"BaseClass\" = ?";

View File

@ -1,200 +0,0 @@
<?php
namespace SilverStripe\Comments\Tests;
use PHPUnit_Framework_Error_Deprecated;
use SilverStripe\Comments\Commenting;
use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Comments\Tests\Stubs\CommentableItem;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
class CommentingTest extends SapphireTest
{
public function setUpOnce()
{
parent::setUpOnce();
}
public function testDeprecatedMethods()
{
$methods = array('add', 'remove', 'has_commenting');
foreach ($methods as $methodName) {
try {
Commenting::$methodName(Member::class);
} catch (PHPUnit_Framework_Error_Deprecated $e) {
$expected = 'Using Commenting:' . $methodName .' is deprecated.'
. ' Please use the config API instead';
$this->assertEquals($expected, $e->getMessage());
}
}
}
public function testSetConfigValue()
{
// public static function set_config_value($class, $key, $value = false) {
Commenting::set_config_value(
CommentableItem::class,
'comments_holder_id',
'commentable_item'
);
$config = Config::inst()->get(
CommentableItem::class,
'comments'
);
$actual = $config['comments_holder_id'];
$this->assertEquals(
'commentable_item',
$actual
);
Commenting::set_config_value(
'all',
'comments_holder_id',
'all_items_actually_commentsextension'
);
$config = Config::inst()->get(
CommentsExtension::class,
'comments'
);
$actual = $config['comments_holder_id'];
$this->assertEquals(
'all_items_actually_commentsextension',
$actual
);
}
public function testGetConfigValue()
{
Config::inst()->update(
CommentableItem::class,
'comments',
array(
'comments_holder_id' => 'commentable_item'
)
);
$this->assertEquals(
'commentable_item',
Commenting::get_config_value(CommentableItem::class, 'comments_holder_id')
);
Config::inst()->update(
CommentsExtension::class,
'comments',
array(
'comments_holder_id' => 'comments_extension'
)
);
// if class is null, method uses the CommentsExtension property
$this->assertEquals(
'comments_extension',
Commenting::get_config_value(null, 'comments_holder_id')
);
$this->setExpectedException(
'InvalidArgumentException',
'Member does not have commenting enabled'
);
Commenting::get_config_value(Member::class, 'comments_holder_id');
}
public function testConfigValueEquals()
{
Config::inst()->update(
CommentableItem::class,
'comments',
array(
'comments_holder_id' => 'some_value'
)
);
$this->assertTrue(
Commenting::config_value_equals(
CommentableItem::class,
'comments_holder_id',
'some_value'
)
);
$this->assertNull(
Commenting::config_value_equals(
CommentableItem::class,
'comments_holder_id',
'not_some_value'
)
);
}
public function testAdd()
{
Commenting::add(Member::class, array('comments_holder_id' => 'test_add_value'));
$config = Config::inst()->get(
Member::class,
'comments'
);
$actual = $config['comments_holder_id'];
$this->assertEquals(
'test_add_value',
$actual
);
Commenting::add(Member::class);
$config = Config::inst()->get(
Member::class,
'comments'
);
$actual = $config['comments_holder_id'];
// no settings updated
$this->assertEquals(
'test_add_value',
$actual
);
$this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
Commenting::add(Member::class, 'illegal format, not an array');
}
public function testCanMemberPost()
{
// logout
if ($member = Member::currentUser()) {
$member->logOut();
}
Config::inst()->update(
CommentableItem::class,
'comments',
array(
'require_login' => false
)
);
$this->assertTrue(Commenting::can_member_post(CommentableItem::class));
Config::inst()->update(
CommentableItem::class,
'comments',
array(
'require_login' => true
)
);
$this->assertFalse(Commenting::can_member_post(CommentableItem::class));
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
$this->assertTrue(Commenting::can_member_post(CommentableItem::class));
Config::inst()->update(
CommentableItem::class,
'comments',
array(
'require_login' => false
)
);
$this->assertTrue(Commenting::can_member_post(CommentableItem::class));
}
}

View File

@ -2,7 +2,6 @@
namespace SilverStripe\Comments\Tests;
use PHPUnit_Framework_Error_Deprecated;
use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Comments\Tests\CommentTestHelper;
@ -199,18 +198,21 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentRSSLink()
{
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
$item = $this->objFromFixture(CommentableItem::class, 'first');
$link = $item->getCommentRSSLink();
$this->assertEquals('/comments/rss', $link);
$this->assertEquals('http://unittesting.local/comments/rss', $link);
}
public function testGetCommentRSSLinkPage()
{
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
$item = $this->objFromFixture(CommentableItem::class, 'first');
$page = $item->getCommentRSSLinkPage();
$this->assertEquals(
'/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID,
'http://unittesting.local/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID,
$page
);
}
@ -447,30 +449,4 @@ class CommentsExtensionTest extends SapphireTest
$fields
);
}
public function testDeprecatedMethods()
{
$item = $this->objFromFixture(CommentableItem::class, 'first');
$methodNames = array(
'getRssLinkPage',
'getRssLink',
'PageComments',
'getPostingRequiresPermission',
'canPost',
'getCommentsConfigured'
);
foreach ($methodNames as $methodName) {
try {
$item->$methodName();
$this->fail('Method ' . $methodName .' should be depracated');
} catch (PHPUnit_Framework_Error_Deprecated $e) {
$expected = 'SilverStripe\\Comments\\Extensions\\CommentsExtension->' . $methodName . ' is '
. 'deprecated.';
$this->assertStringStartsWith($expected, $e->getMessage());
}
}
// ooh, $this->setExpectedException('ExpectedException', 'Expected Message');
}
}

View File

@ -24,14 +24,10 @@ use SilverStripe\Security\Permission;
*/
class CommentsTest extends FunctionalTest
{
/**
* {@inheritDoc}
*/
public static $fixture_file = 'comments/tests/CommentsTest.yml';
/**
* {@inheritDoc}
*/
protected $extraDataObjects = array(
CommentableItem::class,
CommentableItemEnabled::class,