DefaultController.php
5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
class DefaultController extends AdminController
{
public function filters()
{
return array(
'accessControl',
);
}
public function accessRules()
{
return array(
array('allow',
'actions' => array('error', 'login'),
'users' => array('*'),
),
array('allow',
'actions' => array('index', 'logout', 'changePassword', 'doIt'),
'users' => array('@'),
),
array('deny',
'users' => array('*'),
),
);
}
public $defaultAction = 'index';
public function actionIndex()
{
// $this->layout = 'base';
// $this->render('index');
// $this->redirect(array('/admin/sitePages/index'));
$this->redirect(array('/admin/node/index'));
}
public function actionChangePassword()
{
$model = new ChangePasswordForm();
if (isset($_POST['ChangePasswordForm'])) {
$model->setAttributes($_POST['ChangePasswordForm']);
if ($model->validate() && $model->changePassword()) {
$this->redirect(array('default/index'));
}
}
$this->layout = 'base';
$this->render('changePassword', array('model' => $model));
}
public function actionError()
{
$this->layout = 'error';
if ($error = Yii::app()->errorHandler->error) {
if (Yii::app()->request->isAjaxRequest) {
echo $error['message'];
} else {
$this->render('error', $error);
}
}
}
public function actionLogin()
{
/**
* @var LoginForm $model
*/
$model = new LoginForm();
// collect user input data
if (isset($_POST['LoginForm'])) {
$model->setAttributes($_POST['LoginForm']);
if ($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
$this->layout = 'main';
$this->render('login', array('model' => $model));
}
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect($this->createUrl('default/index'));
}
/** @param $data StaticData|StaticDataI18n|StaticPage|StaticPageI18n */
private function fixData(&$data)
{
$t = $data->getDataAttributes();
foreach ($t as $k => $v) {
if (is_string($v)) {
$t[$k] = strtr($v, array(
'tuning@auto-life.ua' => 'bosch@auto-life.com.ua',
'feedback@auto-life.ua' => 'bosch@auto-life.com.ua',
'work@auto-life.ua' => 'bosch@auto-life.com.ua',
//'work@auto-life.ua'=>'bosch@auto-life.com.ua',
//'http://auto-life.claret-art.com.ua/'=>'/',
));
}
}
$data->setDataAttributes($t);
}
public function fixEmails()
{
/** @var $datas StaticData[] */
$datas = StaticData::model()->with('i18n')->findAll();
foreach ($datas as $data) {
$this->fixData($data);
foreach ($data->i18ns as $q) {
$this->fixData($q);
$q->save();
}
$data->save();
}
/** @var $pages StaticPage */
$pages = StaticPage::model()->with('i18n')->findAll();
foreach ($pages as $data) {
$this->fixData($data);
foreach ($data->i18ns as $q) {
$this->fixData($q);
$q->save();
}
$data->save();
}
}
public function DoIt1()
{
$clss = array('Action', 'ActionCategory', 'Job', 'News', 'NewsCategory', 'Partner', 'Publication', 'QuestionCategory', 'Service', 'ServiceCenter', 'TuningBrand', 'TuningModel', 'TuningService', 'TuningSet', 'Vehicle', 'Work', 'WorkBrand', 'WorkModel');
foreach ($clss as $cls) {
/** @var $items News[] */
$items = CActiveRecord::model($cls)->findAll();
foreach ($items as $item) {
$link = $item->link;
$cnt = 1;
foreach ($items as $q) {
if ($item->id != $q->id && $q->link == $link) {
$q->link = $link . '-' . $cnt;
echo "{$cls}, {$q->id}, {$link}, {$link}-{$cnt}\n";
$q->save();
$cnt++;
}
}
}
}
}
public function actionDoIt()
{
// foreach (array('Work', 'TuningSet', 'News', 'Partner', 'Vehicle',) as $cls) {
// /** @var $work Work */
// foreach (CActiveRecord::model($cls)->findAll() as $work) {
// $work->galleryBehavior->changeConfig(false, true);
//
// }
// }
// set_time_limit(12345678);
// $links = array(
// '20',
// '19',
// '18',
// '17',
// '16',
// '15',
// );
// $criteria = new CDbCriteria();
// $criteria->addInCondition('link', $links);
// /** @var $albums Album[] */
// $albums = Album::model()->findAll($criteria);
// foreach ($albums as $album) {
// $album->save();
// $album->photoGalleryBehavior->changeConfig(true);
//
// }
// /** @var $n News */
// $n = News::model()->find('link = :link',array(':link'=>'VtoroyEtapFoto'));
// $n->save();
// $n->galleryBehavior->changeConfig(true);
}
}