Skip to content

Commit

Permalink
Merge pull request #311 from Lenkaaa/feature/AddDoubleRedirectFinder
Browse files Browse the repository at this point in the history
add double redirect finder
  • Loading branch information
bethrezen authored Feb 16, 2020
2 parents 87728f0 + ee1a12a commit 01becc8
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
2 changes: 2 additions & 0 deletions application/messages/ru/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
'Don\'t use in filtration' => 'Не использовать в фильтрации',
'Done ({n})' => 'Завершено ({n})',
'DotPlant2 translated languages:' => 'Переведенные языки DotPlant2:',
'Doubles Redirects' => 'Дубли перенапралений',
'Download' => 'Скачать',
'Duration' => 'Продолжтельность',
'Dynamic Content' => 'Динамический контент',
Expand Down Expand Up @@ -442,6 +443,7 @@
'Filter widget' => 'Виджет фильтров',
'Filters' => '',
'Find broken images' => 'Найти битые изображения',
'Find doubles' => 'Поиск дублей',
'First Name' => 'Имя',
'Floating panel' => 'Плавающая панель',
'Flush cache' => 'Очистить кэш',
Expand Down
12 changes: 12 additions & 0 deletions application/modules/seo/controllers/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,18 @@ public function actionDeleteRedirectFile()
echo (int)Redirect::deleteRedirectFile();
}

public function actionRedirectDoublesFinder()
{
$redirectDoublesFinder = new Redirect();
$dataProvider = $redirectDoublesFinder->findDoubles();
return $this->render(
'redirect-doubles-finder',
[
'dataProvider' => $dataProvider,
]
);
}

public function actionEcommerce()
{
$yaCounter = $gaCounter = ['id' => '', 'active' => 0];
Expand Down
20 changes: 19 additions & 1 deletion application/modules/seo/models/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use yii\data\ActiveDataProvider;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use Yii;

/**
Expand Down Expand Up @@ -140,4 +139,23 @@ public static function deleteRedirectFile()
{
return unlink(self::getFilename());
}

public function findDoubles()
{

$query = self::find()
->select(['type', 'from', 'COUNT(*) as count'])
->groupBy('from')
->having('COUNT(*) > 1');

$dataProvider = new ActiveDataProvider(
[
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]
);
return $dataProvider;
}
}
63 changes: 63 additions & 0 deletions application/modules/seo/views/manage/redirect-doubles-finder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

use yii\grid\GridView;
use yii\helpers\Url;
use yii\widgets\Pjax;
use yii\helpers\Html;

/**
* @var $id
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
*/

$this->title = Yii::t('app', 'Doubles Redirects');

?>

<h1><?= Html::encode($this->title) ?></h1>

<?php Pjax::begin() ?>

<?= GridView::widget([
'id' => 'redirects',
'dataProvider' => $dataProvider,
'layout' => "{items}\n{summary}\n{pager}",
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'options' => [
'width' => '10px',
],
],
[
'class' => 'yii\grid\DataColumn',
'attribute' => 'type',
'filter' => \app\modules\seo\models\Redirect::getTypes(),
],
'from',
[
'class' => 'app\backend\components\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
$params = ['Redirect[from]' => $model->from];
$params[0] = '/seo/manage/redirect';
return Url::toRoute($params);
},
'buttons' => [
[
'url' => 'all',
'icon' => 'list',
'class' => 'btn-primary',
'label' => Yii::t('app', 'Show all'),
],
],
],

],
'tableOptions' => [
'class' => 'table table-striped table-condensed table-hover',
]
]); ?>

<?php Pjax::end();

1 change: 1 addition & 0 deletions application/modules/seo/views/manage/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<?= Html::a(Yii::t('app', 'Create Redirect'), ['create-redirect', 'returnUrl' => \app\backend\components\Helper::getReturnUrl()], ['class' => 'btn btn-success']) ?>
<?= Html::a(Yii::t('app', 'Create Redirects'), ['create-redirects', 'returnUrl' => \app\backend\components\Helper::getReturnUrl()], ['class' => 'btn btn-warning']) ?>
<?= Html::button(Yii::t('app', 'Delete selected'), ['class'=> 'btn btn-danger', 'id' => 'deleteRedirects']); ?>
<?= Html::a(Yii::t('app', 'Find doubles'), ['redirect-doubles-finder'], ['class' => 'btn btn-warning']) ?>
</p>

<?= $this->render('_redirectGrid', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'id' => 'redirects']); ?>
Expand Down

0 comments on commit 01becc8

Please # to comment.