From 7a92b0915de670a36185afc0fe8fb5babdcf1b92 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 17 Jan 2017 17:33:39 +1300 Subject: [PATCH] Remove deprecated@2.0. Update Migrate task to check table name. Minor tweaks to class names. Use Director::absoluteURL. --- .travis.yml | 12 +- .upgrade.yml | 2 - _config.php | 2 +- _config/routes.yml | 4 - src/Admin/CommentsGridFieldBulkAction.php | 13 -- .../CommentsGridFieldBulkAction/Handler.php | 10 +- src/Admin/CommentsGridFieldConfig.php | 9 +- src/Commenting.php | 170 --------------- src/Extensions/CommentsExtension.php | 53 +---- src/Tasks/MigrateCommentParentsTask.php | 19 +- tests/CommentingTest.php | 200 ------------------ tests/CommentsExtensionTest.php | 36 +--- tests/CommentsTest.php | 8 +- 13 files changed, 30 insertions(+), 508 deletions(-) delete mode 100644 src/Admin/CommentsGridFieldBulkAction.php delete mode 100644 src/Commenting.php delete mode 100644 tests/CommentingTest.php diff --git a/.travis.yml b/.travis.yml index 86bfbb6..3aeb37e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.upgrade.yml b/.upgrade.yml index 948f795..b426b9b 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -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 diff --git a/_config.php b/_config.php index 48f849c..83966ab 100644 --- a/_config.php +++ b/_config.php @@ -1,6 +1,6 @@ 'spam', 'approve' => 'approve', diff --git a/src/Admin/CommentsGridFieldConfig.php b/src/Admin/CommentsGridFieldConfig.php index c739925..18ff3eb 100644 --- a/src/Admin/CommentsGridFieldConfig.php +++ b/src/Admin/CommentsGridFieldConfig.php @@ -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', diff --git a/src/Commenting.php b/src/Commenting.php deleted file mode 100644 index 5d3f80e..0000000 --- a/src/Commenting.php +++ /dev/null @@ -1,170 +0,0 @@ -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; - } -} diff --git a/src/Extensions/CommentsExtension.php b/src/Extensions/CommentsExtension.php index 3edf887..827a754 100644 --- a/src/Extensions/CommentsExtension.php +++ b/src/Extensions/CommentsExtension.php @@ -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 * diff --git a/src/Tasks/MigrateCommentParentsTask.php b/src/Tasks/MigrateCommentParentsTask.php index 98fbf28..aa18aba 100644 --- a/src/Tasks/MigrateCommentParentsTask.php +++ b/src/Tasks/MigrateCommentParentsTask.php @@ -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\" = ?"; diff --git a/tests/CommentingTest.php b/tests/CommentingTest.php deleted file mode 100644 index a773132..0000000 --- a/tests/CommentingTest.php +++ /dev/null @@ -1,200 +0,0 @@ -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)); - } -} diff --git a/tests/CommentsExtensionTest.php b/tests/CommentsExtensionTest.php index e950aa3..bee4b55 100644 --- a/tests/CommentsExtensionTest.php +++ b/tests/CommentsExtensionTest.php @@ -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'); - } } diff --git a/tests/CommentsTest.php b/tests/CommentsTest.php index 4dbb8f3..9be355a 100644 --- a/tests/CommentsTest.php +++ b/tests/CommentsTest.php @@ -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,