Skip to content

Commit

Permalink
Added log activity
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-wdmg committed Jun 5, 2020
1 parent 13a472f commit 1db265a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Changelog
=========

## 1.*
## 1.0.11 (2020-06-06)
* Added log activity
* Fixed check for redirection (only frontend)
* Update check() method of component

Expand Down
4 changes: 2 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Yii2 Redirects
*
* @category Module
* @version 1.0.10
* @version 1.0.11
* @author Alexsander Vyshnyvetskyy <[email protected]>
* @link https://github.com/wdmg/yii2-redirects
* @copyright Copyright (c) 2019 - 2020 W.D.M.Group, Ukraine
Expand Down Expand Up @@ -57,7 +57,7 @@ class Module extends BaseModule
/**
* @var string the module version
*/
private $version = "1.0.10";
private $version = "1.0.11";

/**
* @var integer, priority of initialization
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Yii2](https://img.shields.io/badge/required-Yii2_v2.0.33-blue.svg)](https://packagist.org/packages/yiisoft/yii2)
[![Yii2](https://img.shields.io/badge/required-Yii2_v2.0.35-blue.svg)](https://packagist.org/packages/yiisoft/yii2)
[![Downloads](https://img.shields.io/packagist/dt/wdmg/yii2-redirects.svg)](https://packagist.org/packages/wdmg/yii2-redirects)
[![Packagist Version](https://img.shields.io/packagist/v/wdmg/yii2-redirects.svg)](https://packagist.org/packages/wdmg/yii2-redirects)
![Progress](https://img.shields.io/badge/progress-ready_to_use-green.svg)
Expand All @@ -9,7 +9,7 @@ Redirects module for Yii2

# Requirements
* PHP 5.6 or higher
* Yii2 v.2.0.33 and newest
* Yii2 v.2.0.35 and newest
* [Yii2 Base](https://github.com/wdmg/yii2-base) module (required)
* [Yii2 SelectInput](https://github.com/wdmg/yii2-selectinput) widget

Expand Down Expand Up @@ -70,6 +70,7 @@ Use the `Module::dashboardNavItems()` method of the module to generate a navigat
?>

# Status and version [ready to use]
* v.1.0.11 - Added log activity, fixed check for redirection
* v.1.0.10 - Update dependencies, fixed migrations
* v.1.0.9 - Added pagination, up to date dependencies
* v.1.0.8 - Migrations bugfix
Expand Down
2 changes: 1 addition & 1 deletion components/Redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Yii2 Redirects
*
* @category Component
* @version 1.0.9
* @version 1.0.11
* @author Alexsander Vyshnyvetskyy <[email protected]>
* @link https://github.com/wdmg/yii2-redirects
* @copyright Copyright (c) 2019 - 2020 W.D.M.Group, Ukraine
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["yii2", "yii2-redirects", "redirects", "redirect", "wdmg"],
"type": "yii2-extension",
"license": "MIT",
"version": "1.0.10",
"version": "1.0.11",
"homepage": "https://github.com/wdmg/yii2-redirects",
"support": {
"source": "https://github.com/wdmg/yii2-redirects",
Expand All @@ -21,8 +21,8 @@
}
],
"require": {
"yiisoft/yii2": "^2.0.33",
"wdmg/yii2-base": "^1.2.0",
"yiisoft/yii2": "^2.0.35",
"wdmg/yii2-base": "^1.2.3",
"wdmg/yii2-selectinput": "^1.0.9"
},
"minimum-stability": "dev",
Expand Down
86 changes: 83 additions & 3 deletions controllers/RedirectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public function actionCreate()
$model = new RedirectsImport();
if (count($data) > 0) {
if ($model->import($data)) {
// Log activity
$this->module->logActivity(
'List of redirects has been successfully added.',
$this->uniqueId . ":" . $this->action->id,
'success',
1
);

Yii::$app->getSession()->setFlash(
'success',
Yii::t(
Expand All @@ -167,6 +175,14 @@ public function actionCreate()
);
}
} else {
// Log activity
$this->module->logActivity(
'An error occurred while add list of redirects.',
$this->uniqueId . ":" . $this->action->id,
'danger',
1
);

Yii::$app->getSession()->setFlash(
'danger',
Yii::t(
Expand All @@ -178,7 +194,15 @@ public function actionCreate()

} else {
if ($model->load($post)) {
if($model->save()) {
if ($model->save()) {
// Log activity
$this->module->logActivity(
'Redirect (' . $model->code . ') for `' . $model->request_url . '` to `' . $model->redirect_url . '` successfully added.',
$this->uniqueId . ":" . $this->action->id,
'success',
1
);

Yii::$app->getSession()->setFlash(
'success',
Yii::t(
Expand All @@ -193,6 +217,14 @@ public function actionCreate()
);
return $this->redirect(['index']);
} else {
// Log activity
$this->module->logActivity(
'An error occurred while adding a ' . $model->code . '-redirect for `' . $model->request_url . '` to `' . $model->redirect_url . '`.',
$this->uniqueId . ":" . $this->action->id,
'danger',
1
);

Yii::$app->getSession()->setFlash(
'danger',
Yii::t(
Expand Down Expand Up @@ -233,7 +265,15 @@ public function actionUpdate($id)
}

if ($model->load(Yii::$app->request->post())) {
if($model->save()) {
if ($model->save()) {
// Log activity
$this->module->logActivity(
'Redirect (' . $model->code . ') for `' . $model->request_url . '` to `' . $model->redirect_url . '` successfully updated.',
$this->uniqueId . ":" . $this->action->id,
'success',
1
);

Yii::$app->getSession()->setFlash(
'success',
Yii::t(
Expand All @@ -247,6 +287,14 @@ public function actionUpdate($id)
)
);
} else {
// Log activity
$this->module->logActivity(
'An error occurred while updating a ' . $model->code . '-redirect for `' . $model->request_url . '` to `' . $model->redirect_url . '`.',
$this->uniqueId . ":" . $this->action->id,
'danger',
1
);

Yii::$app->getSession()->setFlash(
'danger',
Yii::t(
Expand Down Expand Up @@ -281,7 +329,15 @@ public function actionDelete($id)
{

$model = $this->findModel($id);
if($model->delete()) {
if ($model->delete()) {
// Log activity
$this->module->logActivity(
'Redirect (' . $model->code . ') for `' . $model->request_url . '` to `' . $model->redirect_url . '` successfully deleted.',
$this->uniqueId . ":" . $this->action->id,
'success',
1
);

Yii::$app->getSession()->setFlash(
'success',
Yii::t(
Expand All @@ -295,6 +351,14 @@ public function actionDelete($id)
)
);
} else {
// Log activity
$this->module->logActivity(
'An error occurred while deleting a ' . $model->code . '-redirect for `' . $model->request_url . '` to `' . $model->redirect_url . '`.',
$this->uniqueId . ":" . $this->action->id,
'danger',
1
);

Yii::$app->getSession()->setFlash(
'danger',
Yii::t(
Expand Down Expand Up @@ -328,6 +392,14 @@ public function actionImport() {
$redirects = file_get_contents($import->tempName);
if ($data = Json::decode($redirects)) {
if ($model->import($data)) {
// Log activity
$this->module->logActivity(
'Redirects successfully imported/updated.',
$this->uniqueId . ":" . $this->action->id,
'success',
1
);

Yii::$app->getSession()->setFlash(
'success',
Yii::t(
Expand All @@ -337,6 +409,14 @@ public function actionImport() {
);
}
} else {
// Log activity
$this->module->logActivity(
'An error occurred while importing/updating redirects.',
$this->uniqueId . ":" . $this->action->id,
'danger',
1
);

Yii::$app->getSession()->setFlash(
'danger',
Yii::t(
Expand Down

0 comments on commit 1db265a

Please sign in to comment.