From 105b3fbde16d6087c8da999af63844e2e1b5eed8 Mon Sep 17 00:00:00 2001
From: Igor Chepurnoy
Date: Sun, 13 Aug 2017 22:27:12 +0300
Subject: [PATCH 01/11] Update README.md
---
README.md | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 8d296c5..c1523cf 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,10 @@
-Comments module for Yii2
-========================
+
+
+
+
+
Yii2 Comments Extension
+
+
This module provide a comments managing system for Yii2 application.
From 9600e84d9beebd2df9d46e10f969caface52c7ad Mon Sep 17 00:00:00 2001
From: Igor Chepurnoy
Date: Sun, 13 Aug 2017 22:29:02 +0300
Subject: [PATCH 02/11] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c1523cf..619bf27 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-This module provide a comments managing system for Yii2 application.
+This module provides a comments managing system.
[](https://packagist.org/packages/yii2mod/yii2-comments)
[](https://packagist.org/packages/yii2mod/yii2-comments)
From b91abd31b3490318b358a90722fa98e2bdc3057c Mon Sep 17 00:00:00 2001
From: igor-chepurnoi
Date: Mon, 14 Aug 2017 09:43:58 +0300
Subject: [PATCH 03/11] update tests configuration
---
.travis.yml | 4 +---
composer.json | 8 +++++++-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index f0db8b8..eeca0b5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,14 +10,12 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache
- - vendor
install:
- travis_retry composer self-update && composer --version
- - travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0"
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install --prefer-dist --no-interaction
script:
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
- - phpunit --verbose $PHPUNIT_FLAGS
+ - phpunit --verbose
diff --git a/composer.json b/composer.json
index 6e6b432..6cef27a 100644
--- a/composer.json
+++ b/composer.json
@@ -32,5 +32,11 @@
"psr-4": {
"yii2mod\\comments\\": ""
}
- }
+ },
+ "repositories": [
+ {
+ "type": "composer",
+ "url": "https://asset-packagist.org/"
+ }
+ ]
}
From ee7e92ebe8d79c66f5ef225ca8e9bcd9986fd6ed Mon Sep 17 00:00:00 2001
From: Igor Chepurnoy
Date: Sun, 27 Aug 2017 11:44:31 +0300
Subject: [PATCH 04/11] Added scrutinizer badge
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 619bf27..5a8a459 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ This module provides a comments managing system.
[](https://packagist.org/packages/yii2mod/yii2-comments)
[](https://packagist.org/packages/yii2mod/yii2-comments)
[](https://travis-ci.org/yii2mod/yii2-comments)
+[](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/?branch=master)
Installation
------------
From 2083417bfeab2661d62a924b92ec374ab083f1af Mon Sep 17 00:00:00 2001
From: igor-chepurnoi
Date: Fri, 8 Sep 2017 15:57:10 +0300
Subject: [PATCH 05/11] fix #75
---
.travis.yml | 2 +-
composer.json | 3 ++-
models/CommentModel.php | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index eeca0b5..7d61992 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,4 +18,4 @@ install:
script:
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
- - phpunit --verbose
+ - vendor/bin/phpunit --verbose
diff --git a/composer.json b/composer.json
index 6cef27a..e12b108 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,8 @@
"paulzi/yii2-adjacency-list": "^2.0"
},
"require-dev": {
- "friendsofphp/php-cs-fixer": "~2.0"
+ "friendsofphp/php-cs-fixer": "~2.0",
+ "phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {
diff --git a/models/CommentModel.php b/models/CommentModel.php
index 2ec6081..1378205 100644
--- a/models/CommentModel.php
+++ b/models/CommentModel.php
@@ -168,7 +168,7 @@ public static function find()
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
- if ($this->parentId > 0) {
+ if ($this->parentId > 0 && $this->isNewRecord) {
$parentNodeLevel = static::find()->select('level')->where(['id' => $this->parentId])->scalar();
$this->level += $parentNodeLevel;
}
From 36b012b88c9f81cfc84a80eb3f5b2af6d49a72f1 Mon Sep 17 00:00:00 2001
From: Robert Natkay
Date: Wed, 27 Sep 2017 14:04:50 +0200
Subject: [PATCH 06/11] skip the validation of parentId on deletion
---
controllers/DefaultController.php | 1 +
models/CommentModel.php | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php
index fe15098..9404a4e 100644
--- a/controllers/DefaultController.php
+++ b/controllers/DefaultController.php
@@ -131,6 +131,7 @@ public function actionCreate($entity)
public function actionDelete($id)
{
$commentModel = $this->findModel($id);
+ $commentModel->setScenario(CommentModel::SCENARIO_MODERATION);
$event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]);
$this->trigger(self::EVENT_BEFORE_DELETE, $event);
diff --git a/models/CommentModel.php b/models/CommentModel.php
index 1378205..2e0f246 100644
--- a/models/CommentModel.php
+++ b/models/CommentModel.php
@@ -42,6 +42,8 @@ class CommentModel extends ActiveRecord
{
use ModuleTrait;
+ const SCENARIO_MODERATION = 'moderation';
+
/**
* @var null|array|ActiveRecord[] comment children
*/
@@ -67,7 +69,7 @@ public function rules()
['status', 'default', 'value' => Status::APPROVED],
['status', 'in', 'range' => Status::getConstantsByName()],
['level', 'default', 'value' => 1],
- ['parentId', 'validateParentID'],
+ ['parentId', 'validateParentID', 'except'=>static::SCENARIO_MODERATION],
[['entityId', 'parentId', 'status', 'level'], 'integer'],
];
}
From 238c3ca7cee5d4bc67d15f14f1920eb5659c0d4f Mon Sep 17 00:00:00 2001
From: Robert Natkay
Date: Wed, 27 Sep 2017 14:04:50 +0200
Subject: [PATCH 07/11] skip the validation of parentId on deletion
---
controllers/DefaultController.php | 5 +++--
controllers/ManageController.php | 2 +-
models/CommentModel.php | 6 ++++--
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php
index fe15098..4dd673a 100644
--- a/controllers/DefaultController.php
+++ b/controllers/DefaultController.php
@@ -131,6 +131,7 @@ public function actionCreate($entity)
public function actionDelete($id)
{
$commentModel = $this->findModel($id);
+ $commentModel->setScenario(CommentModel::SCENARIO_MODERATION);
$event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]);
$this->trigger(self::EVENT_BEFORE_DELETE, $event);
@@ -157,7 +158,7 @@ public function actionDelete($id)
protected function findModel($id)
{
$commentModel = $this->getModule()->commentModelClass;
- if (($model = $commentModel::findOne($id)) !== null) {
+ if (null !== ($model = $commentModel::findOne($id))) {
return $model;
} else {
throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.'));
@@ -176,7 +177,7 @@ protected function findModel($id)
protected function getCommentAttributesFromEntity($entity)
{
$decryptEntity = Yii::$app->getSecurity()->decryptByKey(utf8_decode($entity), $this->getModule()->id);
- if ($decryptEntity !== false) {
+ if (false !== $decryptEntity) {
return Json::decode($decryptEntity);
}
diff --git a/controllers/ManageController.php b/controllers/ManageController.php
index 0d980c2..d803cda 100644
--- a/controllers/ManageController.php
+++ b/controllers/ManageController.php
@@ -142,7 +142,7 @@ protected function findModel($id)
{
$commentModel = $this->getModule()->commentModelClass;
- if (($model = $commentModel::findOne($id)) !== null) {
+ if (null !== ($model = $commentModel::findOne($id))) {
return $model;
} else {
throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.'));
diff --git a/models/CommentModel.php b/models/CommentModel.php
index 1378205..4f7efc7 100644
--- a/models/CommentModel.php
+++ b/models/CommentModel.php
@@ -42,6 +42,8 @@ class CommentModel extends ActiveRecord
{
use ModuleTrait;
+ const SCENARIO_MODERATION = 'moderation';
+
/**
* @var null|array|ActiveRecord[] comment children
*/
@@ -67,7 +69,7 @@ public function rules()
['status', 'default', 'value' => Status::APPROVED],
['status', 'in', 'range' => Status::getConstantsByName()],
['level', 'default', 'value' => 1],
- ['parentId', 'validateParentID'],
+ ['parentId', 'validateParentID', 'except' => static::SCENARIO_MODERATION],
[['entityId', 'parentId', 'status', 'level'], 'integer'],
];
}
@@ -77,7 +79,7 @@ public function rules()
*/
public function validateParentID($attribute)
{
- if ($this->{$attribute} !== null) {
+ if (null !== $this->{$attribute}) {
$parentCommentExist = static::find()
->approved()
->andWhere([
From 057c958340707fd71e878203b6dc96d37d763877 Mon Sep 17 00:00:00 2001
From: Robert Natkay
Date: Sat, 7 Oct 2017 19:05:09 +0200
Subject: [PATCH 08/11] skip the validation of parentId on deletion
---
Module.php | 2 +-
migrations/m010101_100001_init_comment.php | 2 +-
migrations/m161109_092304_rename_comment_table.php | 4 ++--
views/manage/index.php | 2 +-
views/manage/update.php | 4 ++--
widgets/views/_form.php | 2 +-
widgets/views/_list.php | 2 +-
7 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Module.php b/Module.php
index 2cb579d..3c497ac 100644
--- a/Module.php
+++ b/Module.php
@@ -38,7 +38,7 @@ public function init()
{
parent::init();
- if ($this->userIdentityClass === null) {
+ if (null === $this->userIdentityClass) {
$this->userIdentityClass = Yii::$app->getUser()->identityClass;
}
}
diff --git a/migrations/m010101_100001_init_comment.php b/migrations/m010101_100001_init_comment.php
index e1290a6..cf4126e 100644
--- a/migrations/m010101_100001_init_comment.php
+++ b/migrations/m010101_100001_init_comment.php
@@ -14,7 +14,7 @@ public function up()
{
$tableOptions = null;
- if ($this->db->driverName === 'mysql') {
+ if ('mysql' === $this->db->driverName) {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
diff --git a/migrations/m161109_092304_rename_comment_table.php b/migrations/m161109_092304_rename_comment_table.php
index 914d0d3..cbd6740 100644
--- a/migrations/m161109_092304_rename_comment_table.php
+++ b/migrations/m161109_092304_rename_comment_table.php
@@ -6,14 +6,14 @@ class m161109_092304_rename_comment_table extends Migration
{
public function up()
{
- if (Yii::$app->db->schema->getTableSchema('{{%comment}}') === null) {
+ if (null === Yii::$app->db->schema->getTableSchema('{{%comment}}')) {
$this->renameTable('{{%Comment}}', '{{%comment}}');
}
}
public function down()
{
- if (Yii::$app->db->schema->getTableSchema('{{%Comment}}') === null) {
+ if (null === Yii::$app->db->schema->getTableSchema('{{%Comment}}')) {
$this->renameTable('{{%comment}}', '{{%Comment}}');
}
}
diff --git a/views/manage/index.php b/views/manage/index.php
index f6f7c6c..245f232 100644
--- a/views/manage/index.php
+++ b/views/manage/index.php
@@ -16,7 +16,7 @@
?>
title) ?>
+title); ?>
10000]); ?> $dataProvider, diff --git a/views/manage/update.php b/views/manage/update.php index a426837..acc1a0e 100644 --- a/views/manage/update.php +++ b/views/manage/update.php @@ -15,7 +15,7 @@ ?>title) ?>
+title); ?>