@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | public function rules() |
95 | 95 | { |
96 | 96 | return [ |
97 | - ['id', 'integer'], |
|
98 | - ['siteId', 'integer'], |
|
99 | - ['siteId', 'default', 'value' => null], |
|
97 | + [ 'id', 'integer' ], |
|
98 | + [ 'siteId', 'integer' ], |
|
99 | + [ 'siteId', 'default', 'value' => null ], |
|
100 | 100 | [ |
101 | 101 | [ |
102 | 102 | 'redirectSrcUrl', |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | 'default', |
127 | 127 | 'value' => '' |
128 | 128 | ], |
129 | - ['exceptionFileLine', 'integer'], |
|
130 | - ['exceptionFileLine', 'default', 'value' => 0], |
|
131 | - ['referrerUrl', DbStringValidator::class, 'max' => 2000], |
|
132 | - ['referrerUrl', 'string'], |
|
133 | - ['referrerUrl', 'default', 'value' => ''], |
|
134 | - ['remoteIp', DbStringValidator::class, 'max' => 45], |
|
135 | - ['remoteIp', 'string'], |
|
136 | - ['remoteIp', 'default', 'value' => ''], |
|
137 | - ['hitCount', 'integer'], |
|
138 | - ['hitCount', 'default', 'value' => 0], |
|
139 | - ['hitLastTime', 'safe'], |
|
140 | - ['handledByRetour', 'integer', 'min' => 0, 'max' => 1], |
|
141 | - ['handledByRetour', 'default', 'value' => 0], |
|
129 | + [ 'exceptionFileLine', 'integer' ], |
|
130 | + [ 'exceptionFileLine', 'default', 'value' => 0 ], |
|
131 | + [ 'referrerUrl', DbStringValidator::class, 'max' => 2000 ], |
|
132 | + [ 'referrerUrl', 'string' ], |
|
133 | + [ 'referrerUrl', 'default', 'value' => '' ], |
|
134 | + [ 'remoteIp', DbStringValidator::class, 'max' => 45 ], |
|
135 | + [ 'remoteIp', 'string' ], |
|
136 | + [ 'remoteIp', 'default', 'value' => '' ], |
|
137 | + [ 'hitCount', 'integer' ], |
|
138 | + [ 'hitCount', 'default', 'value' => 0 ], |
|
139 | + [ 'hitLastTime', 'safe' ], |
|
140 | + [ 'handledByRetour', 'integer', 'min' => 0, 'max' => 1 ], |
|
141 | + [ 'handledByRetour', 'default', 'value' => 0 ], |
|
142 | 142 | ]; |
143 | 143 | } |
144 | 144 |
@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | public function rules() |
97 | 97 | { |
98 | 98 | return [ |
99 | - ['id', 'integer'], |
|
100 | - ['siteId', 'integer'], |
|
101 | - ['siteId', 'default', 'value' => null], |
|
102 | - ['associatedElementId', 'default', 'value' => 0], |
|
103 | - ['associatedElementId', 'integer'], |
|
104 | - ['enabled', 'boolean'], |
|
105 | - ['redirectSrcMatch', 'default', 'value' => 'pathonly'], |
|
106 | - ['redirectSrcMatch', DbStringValidator::class, 'max' => 32], |
|
107 | - ['redirectSrcMatch', 'string'], |
|
108 | - ['redirectMatchType', 'default', 'value' => 'exactmatch'], |
|
109 | - ['redirectMatchType', DbStringValidator::class, 'max' => 32], |
|
110 | - ['redirectMatchType', 'string'], |
|
99 | + [ 'id', 'integer' ], |
|
100 | + [ 'siteId', 'integer' ], |
|
101 | + [ 'siteId', 'default', 'value' => null ], |
|
102 | + [ 'associatedElementId', 'default', 'value' => 0 ], |
|
103 | + [ 'associatedElementId', 'integer' ], |
|
104 | + [ 'enabled', 'boolean' ], |
|
105 | + [ 'redirectSrcMatch', 'default', 'value' => 'pathonly' ], |
|
106 | + [ 'redirectSrcMatch', DbStringValidator::class, 'max' => 32 ], |
|
107 | + [ 'redirectSrcMatch', 'string' ], |
|
108 | + [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ], |
|
109 | + [ 'redirectMatchType', DbStringValidator::class, 'max' => 32 ], |
|
110 | + [ 'redirectMatchType', 'string' ], |
|
111 | 111 | [ |
112 | 112 | [ |
113 | 113 | 'redirectSrcUrl', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'default', |
118 | 118 | 'value' => '' |
119 | 119 | ], |
120 | - ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'], |
|
120 | + [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ], |
|
121 | 121 | [ |
122 | 122 | [ |
123 | 123 | 'redirectSrcUrl', |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | ], |
145 | 145 | 'string' |
146 | 146 | ], |
147 | - ['redirectHttpCode', 'integer'], |
|
148 | - ['redirectHttpCode', 'default', 'value' => 301], |
|
149 | - ['hitCount', 'default', 'value' => 0], |
|
150 | - ['hitCount', 'integer'], |
|
151 | - ['hitLastTime', 'safe'], |
|
147 | + [ 'redirectHttpCode', 'integer' ], |
|
148 | + [ 'redirectHttpCode', 'default', 'value' => 301 ], |
|
149 | + [ 'hitCount', 'default', 'value' => 0 ], |
|
150 | + [ 'hitCount', 'integer' ], |
|
151 | + [ 'hitLastTime', 'safe' ], |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function actionDashboard(string $range = 'day', int $siteId = 0): Response |
56 | 56 | { |
57 | 57 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
58 | - $data = []; |
|
58 | + $data = [ ]; |
|
59 | 59 | $days = 1; |
60 | 60 | switch ($range) { |
61 | 61 | case 'day': |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'COUNT(handledByRetour = 1 or null) as handled_cnt', |
82 | 82 | ]) |
83 | 83 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )"); |
84 | - if ((int)$siteId !== 0) { |
|
85 | - $query->andWhere(['siteId' => $siteId]); |
|
84 | + if ((int) $siteId !== 0) { |
|
85 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
86 | 86 | } |
87 | 87 | $query |
88 | 88 | ->orderBy('date_formatted ASC') |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt", |
100 | 100 | ]) |
101 | 101 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )"); |
102 | - if ((int)$siteId !== 0) { |
|
103 | - $query->andWhere(['siteId' => $siteId]); |
|
102 | + if ((int) $siteId !== 0) { |
|
103 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
104 | 104 | } |
105 | 105 | $query |
106 | 106 | ->orderBy('date_formatted ASC') |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | $stats = $query->all(); |
109 | 109 | } |
110 | 110 | if ($stats) { |
111 | - $data[] = [ |
|
111 | + $data[ ] = [ |
|
112 | 112 | 'name' => '404 hits', |
113 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'cnt')), |
|
114 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
113 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'cnt')), |
|
114 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
115 | 115 | ]; |
116 | - $data[] = [ |
|
116 | + $data[ ] = [ |
|
117 | 117 | 'name' => 'Handled 404 hits', |
118 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
119 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
118 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
119 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
120 | 120 | ]; |
121 | 121 | } |
122 | 122 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function actionWidget($days = 1): Response |
134 | 134 | { |
135 | - $data = []; |
|
135 | + $data = [ ]; |
|
136 | 136 | // Different dbs do it different ways |
137 | 137 | $stats = null; |
138 | 138 | $handledStats = null; |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | } |
164 | 164 | if ($stats) { |
165 | 165 | $data = [ |
166 | - (int)$stats, |
|
167 | - (int)$handledStats, |
|
166 | + (int) $stats, |
|
167 | + (int) $handledStats, |
|
168 | 168 | ]; |
169 | 169 | } |
170 | 170 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | // Protected Properties |
41 | 41 | // ========================================================================= |
42 | 42 | |
43 | - protected $allowAnonymous = []; |
|
43 | + protected $allowAnonymous = [ ]; |
|
44 | 44 | |
45 | 45 | // Public Methods |
46 | 46 | // ========================================================================= |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function actionDashboard(string $siteHandle = null, bool $showWelcome = false): Response |
58 | 58 | { |
59 | - $variables = []; |
|
59 | + $variables = [ ]; |
|
60 | 60 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
61 | 61 | // Trim the statistics |
62 | 62 | Retour::$plugin->statistics->trimStatistics(); |
@@ -71,33 +71,33 @@ discard block |
||
71 | 71 | } catch (InvalidConfigException $e) { |
72 | 72 | Craft::error($e->getMessage(), __METHOD__); |
73 | 73 | } |
74 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
74 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
75 | 75 | '@nystudio107/retour/assetbundles/retour/dist', |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | // Enabled sites |
79 | 79 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
80 | - $variables['controllerHandle'] = 'dashboard'; |
|
80 | + $variables[ 'controllerHandle' ] = 'dashboard'; |
|
81 | 81 | |
82 | 82 | // Basic variables |
83 | - $variables['fullPageForm'] = false; |
|
84 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
85 | - $variables['pluginName'] = $pluginName; |
|
86 | - $variables['title'] = $templateTitle; |
|
87 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
88 | - $variables['crumbs'] = [ |
|
83 | + $variables[ 'fullPageForm' ] = false; |
|
84 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
85 | + $variables[ 'pluginName' ] = $pluginName; |
|
86 | + $variables[ 'title' ] = $templateTitle; |
|
87 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
88 | + $variables[ 'crumbs' ] = [ |
|
89 | 89 | [ |
90 | 90 | 'label' => $pluginName, |
91 | 91 | 'url' => UrlHelper::cpUrl('retour'), |
92 | 92 | ], |
93 | 93 | [ |
94 | 94 | 'label' => $templateTitle, |
95 | - 'url' => UrlHelper::cpUrl('retour/dashboard'.$siteHandleUri), |
|
95 | + 'url' => UrlHelper::cpUrl('retour/dashboard' . $siteHandleUri), |
|
96 | 96 | ], |
97 | 97 | ]; |
98 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
99 | - $variables['selectedSubnavItem'] = 'dashboard'; |
|
100 | - $variables['showWelcome'] = $showWelcome; |
|
98 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
99 | + $variables[ 'selectedSubnavItem' ] = 'dashboard'; |
|
100 | + $variables[ 'showWelcome' ] = $showWelcome; |
|
101 | 101 | |
102 | 102 | // Render the template |
103 | 103 | return $this->renderTemplate('retour/dashboard/index', $variables); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | Craft::t( |
116 | 116 | 'retour', |
117 | 117 | 'Retour statistics cleared: {error}', |
118 | - ['error' => $error] |
|
118 | + [ 'error' => $error ] |
|
119 | 119 | ), |
120 | 120 | __METHOD__ |
121 | 121 | ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | // Protected Properties |
74 | 74 | // ========================================================================= |
75 | 75 | |
76 | - protected $allowAnonymous = []; |
|
76 | + protected $allowAnonymous = [ ]; |
|
77 | 77 | |
78 | 78 | // Public Methods |
79 | 79 | // ========================================================================= |
@@ -98,20 +98,20 @@ discard block |
||
98 | 98 | $headers = array_flip($csv->fetchOne(0)); |
99 | 99 | $csv->setOffset(1); |
100 | 100 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
101 | - $csv->each(function ($row) use ($headers, $columns) { |
|
101 | + $csv->each(function($row) use ($headers, $columns) { |
|
102 | 102 | $redirectConfig = [ |
103 | 103 | 'id' => 0, |
104 | 104 | ]; |
105 | 105 | $index = 0; |
106 | 106 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
107 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
108 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
107 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
108 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
109 | 109 | ? null |
110 | - : $row[$headers[$columns[$index]]]; |
|
110 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
111 | 111 | } |
112 | 112 | $index++; |
113 | 113 | } |
114 | - Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__); |
|
114 | + Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__); |
|
115 | 115 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
116 | 116 | |
117 | 117 | return true; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function actionImportCsv(string $siteHandle = null): Response |
135 | 135 | { |
136 | - $variables = []; |
|
136 | + $variables = [ ]; |
|
137 | 137 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
138 | 138 | // If your CSV document was created or is read on a Macintosh computer, |
139 | 139 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -151,43 +151,43 @@ discard block |
||
151 | 151 | } catch (InvalidConfigException $e) { |
152 | 152 | Craft::error($e->getMessage(), __METHOD__); |
153 | 153 | } |
154 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
154 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
155 | 155 | '@nystudio107/retour/assetbundles/retour/dist', |
156 | 156 | true |
157 | 157 | ); |
158 | 158 | // Enabled sites |
159 | 159 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
160 | - $variables['controllerHandle'] = 'file'; |
|
160 | + $variables[ 'controllerHandle' ] = 'file'; |
|
161 | 161 | |
162 | 162 | // Basic variables |
163 | - $variables['fullPageForm'] = true; |
|
164 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
165 | - $variables['pluginName'] = $pluginName; |
|
166 | - $variables['title'] = $templateTitle; |
|
167 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
168 | - $variables['crumbs'] = [ |
|
163 | + $variables[ 'fullPageForm' ] = true; |
|
164 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
165 | + $variables[ 'pluginName' ] = $pluginName; |
|
166 | + $variables[ 'title' ] = $templateTitle; |
|
167 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
168 | + $variables[ 'crumbs' ] = [ |
|
169 | 169 | [ |
170 | 170 | 'label' => $pluginName, |
171 | 171 | 'url' => UrlHelper::cpUrl('retour'), |
172 | 172 | ], |
173 | 173 | [ |
174 | 174 | 'label' => 'Redirects', |
175 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
175 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
176 | 176 | ], |
177 | 177 | ]; |
178 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
179 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
178 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
179 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
180 | 180 | |
181 | 181 | // The CSV file |
182 | 182 | $file = UploadedFile::getInstanceByName('file'); |
183 | 183 | if ($file !== null) { |
184 | - $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true); |
|
184 | + $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true); |
|
185 | 185 | $file->saveAs($filename, false); |
186 | 186 | $csv = Reader::createFromPath($file->tempName); |
187 | 187 | $headers = $csv->fetchOne(0); |
188 | 188 | Craft::info(print_r($headers, true), __METHOD__); |
189 | - $variables['headers'] = $headers; |
|
190 | - $variables['filename'] = $filename; |
|
189 | + $variables[ 'headers' ] = $headers; |
|
190 | + $variables[ 'filename' ] = $filename; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Render the template |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | } |
234 | 234 | // Query the db table |
235 | 235 | $data = (new Query()) |
236 | - ->from([$table]) |
|
236 | + ->from([ $table ]) |
|
237 | 237 | ->select(array_keys($columns)) |
238 | 238 | ->orderBy('hitCount DESC') |
239 | 239 | ->all(); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $csv = Writer::createFromFileObject(new \SplTempFileObject()); |
242 | 242 | $csv->insertOne(array_values($columns)); |
243 | 243 | $csv->insertAll($data); |
244 | - $csv->output($filename.'.csv'); |
|
244 | + $csv->output($filename . '.csv'); |
|
245 | 245 | exit(0); |
246 | 246 | } |
247 | 247 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @var array The URIs for the element before it was saved |
101 | 101 | */ |
102 | - public $oldElementUris = []; |
|
102 | + public $oldElementUris = [ ]; |
|
103 | 103 | |
104 | 104 | // Public Methods |
105 | 105 | // ========================================================================= |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | Craft::t( |
131 | 131 | 'retour', |
132 | 132 | '{name} plugin loaded', |
133 | - ['name' => $this->name] |
|
133 | + [ 'name' => $this->name ] |
|
134 | 134 | ), |
135 | 135 | __METHOD__ |
136 | 136 | ); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getCpNavItem() |
152 | 152 | { |
153 | - $subNavs = []; |
|
153 | + $subNavs = [ ]; |
|
154 | 154 | $navItem = parent::getCpNavItem(); |
155 | 155 | $currentUser = Craft::$app->getUser()->getIdentity(); |
156 | 156 | // Only show sub-navs the user has permission to view |
157 | 157 | if ($currentUser->can('retour:dashboard')) { |
158 | - $subNavs['dashboard'] = [ |
|
158 | + $subNavs[ 'dashboard' ] = [ |
|
159 | 159 | 'label' => 'Dashboard', |
160 | 160 | 'url' => 'retour/dashboard', |
161 | 161 | ]; |
162 | 162 | } |
163 | 163 | if ($currentUser->can('retour:redirects')) { |
164 | - $subNavs['redirects'] = [ |
|
164 | + $subNavs[ 'redirects' ] = [ |
|
165 | 165 | 'label' => 'Redirects', |
166 | 166 | 'url' => 'retour/redirects', |
167 | 167 | ]; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $editableSettings = false; |
173 | 173 | } |
174 | 174 | if ($currentUser->can('retour:settings') && $editableSettings) { |
175 | - $subNavs['settings'] = [ |
|
175 | + $subNavs[ 'settings' ] = [ |
|
176 | 176 | 'label' => 'Settings', |
177 | 177 | 'url' => 'retour/settings', |
178 | 178 | ]; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | Event::on( |
232 | 232 | ClearCaches::class, |
233 | 233 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
234 | - function (RegisterCacheOptionsEvent $event) { |
|
234 | + function(RegisterCacheOptionsEvent $event) { |
|
235 | 235 | Craft::debug( |
236 | 236 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
237 | 237 | __METHOD__ |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | Event::on( |
248 | 248 | Plugins::class, |
249 | 249 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
250 | - function (PluginEvent $event) { |
|
250 | + function(PluginEvent $event) { |
|
251 | 251 | if ($event->plugin === $this) { |
252 | 252 | // Invalidate our caches after we've been installed |
253 | 253 | $this->clearAllCaches(); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | Event::on( |
275 | 275 | CraftVariable::class, |
276 | 276 | CraftVariable::EVENT_INIT, |
277 | - function (Event $event) { |
|
277 | + function(Event $event) { |
|
278 | 278 | /** @var CraftVariable $variable */ |
279 | 279 | $variable = $event->sender; |
280 | 280 | $variable->set('retour', RetourVariable::class); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | Event::on( |
285 | 285 | Elements::class, |
286 | 286 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
287 | - function (ElementEvent $event) { |
|
287 | + function(ElementEvent $event) { |
|
288 | 288 | Craft::debug( |
289 | 289 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
290 | 290 | __METHOD__ |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | if ($oldElement !== null) { |
300 | 300 | // Stash the old URLs by element id, and do so only once, |
301 | 301 | // in case we are called more than once per request |
302 | - if (empty($this->oldElementUris[$oldElement->id])) { |
|
303 | - $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement); |
|
302 | + if (empty($this->oldElementUris[ $oldElement->id ])) { |
|
303 | + $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | Event::on( |
312 | 312 | Elements::class, |
313 | 313 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
314 | - function (ElementEvent $event) { |
|
314 | + function(ElementEvent $event) { |
|
315 | 315 | Craft::debug( |
316 | 316 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
317 | 317 | __METHOD__ |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | Event::on( |
328 | 328 | Plugins::class, |
329 | 329 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
330 | - function () { |
|
330 | + function() { |
|
331 | 331 | // Install these only after all other plugins have loaded |
332 | 332 | $request = Craft::$app->getRequest(); |
333 | 333 | // Only respond to non-console site requests |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | Event::on( |
352 | 352 | UrlManager::class, |
353 | 353 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
354 | - function (RegisterUrlRulesEvent $event) { |
|
354 | + function(RegisterUrlRulesEvent $event) { |
|
355 | 355 | Craft::debug( |
356 | 356 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
357 | 357 | __METHOD__ |
@@ -374,15 +374,15 @@ discard block |
||
374 | 374 | Event::on( |
375 | 375 | Dashboard::class, |
376 | 376 | Dashboard::EVENT_REGISTER_WIDGET_TYPES, |
377 | - function (RegisterComponentTypesEvent $event) { |
|
378 | - $event->types[] = RetourWidget::class; |
|
377 | + function(RegisterComponentTypesEvent $event) { |
|
378 | + $event->types[ ] = RetourWidget::class; |
|
379 | 379 | } |
380 | 380 | ); |
381 | 381 | // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES |
382 | 382 | Event::on( |
383 | 383 | UrlManager::class, |
384 | 384 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
385 | - function (RegisterUrlRulesEvent $event) { |
|
385 | + function(RegisterUrlRulesEvent $event) { |
|
386 | 386 | Craft::debug( |
387 | 387 | 'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
388 | 388 | __METHOD__ |
@@ -398,13 +398,13 @@ discard block |
||
398 | 398 | Event::on( |
399 | 399 | UserPermissions::class, |
400 | 400 | UserPermissions::EVENT_REGISTER_PERMISSIONS, |
401 | - function (RegisterUserPermissionsEvent $event) { |
|
401 | + function(RegisterUserPermissionsEvent $event) { |
|
402 | 402 | Craft::debug( |
403 | 403 | 'UserPermissions::EVENT_REGISTER_PERMISSIONS', |
404 | 404 | __METHOD__ |
405 | 405 | ); |
406 | 406 | // Register our custom permissions |
407 | - $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions(); |
|
407 | + $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions(); |
|
408 | 408 | } |
409 | 409 | ); |
410 | 410 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | Event::on( |
421 | 421 | ErrorHandler::class, |
422 | 422 | ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION, |
423 | - function (ExceptionEvent $event) { |
|
423 | + function(ExceptionEvent $event) { |
|
424 | 424 | Craft::debug( |
425 | 425 | 'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION', |
426 | 426 | __METHOD__ |
@@ -463,16 +463,16 @@ discard block |
||
463 | 463 | protected function handleElementUriChange(Element $element) |
464 | 464 | { |
465 | 465 | $uris = $this->getAllElementUris($element); |
466 | - if (!empty($this->oldElementUris[$element->id])) { |
|
467 | - $oldElementUris = $this->oldElementUris[$element->id]; |
|
466 | + if (!empty($this->oldElementUris[ $element->id ])) { |
|
467 | + $oldElementUris = $this->oldElementUris[ $element->id ]; |
|
468 | 468 | foreach ($uris as $siteId => $newUri) { |
469 | - if (!empty($oldElementUris[$siteId])) { |
|
470 | - $oldUri = $oldElementUris[$siteId]; |
|
469 | + if (!empty($oldElementUris[ $siteId ])) { |
|
470 | + $oldUri = $oldElementUris[ $siteId ]; |
|
471 | 471 | Craft::debug( |
472 | 472 | Craft::t( |
473 | 473 | 'retour', |
474 | 474 | 'Comparing old: {oldUri} to new: {newUri}', |
475 | - ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)] |
|
475 | + [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ] |
|
476 | 476 | ), |
477 | 477 | __METHOD__ |
478 | 478 | ); |
@@ -507,12 +507,12 @@ discard block |
||
507 | 507 | */ |
508 | 508 | protected function getAllElementUris(Element $element): array |
509 | 509 | { |
510 | - $uris = []; |
|
510 | + $uris = [ ]; |
|
511 | 511 | $sites = Craft::$app->getSites()->getAllSites(); |
512 | 512 | foreach ($sites as $site) { |
513 | 513 | $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id); |
514 | 514 | if ($uri !== null) { |
515 | - $uris[$site->id] = $uri; |
|
515 | + $uris[ $site->id ] = $uri; |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | Craft::t( |
521 | 521 | 'retour', |
522 | 522 | 'Getting Element URIs: {uris}', |
523 | - ['uris' => print_r($uris, true)] |
|
523 | + [ 'uris' => print_r($uris, true) ] |
|
524 | 524 | ), |
525 | 525 | __METHOD__ |
526 | 526 | ); |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | [ |
585 | 585 | 'key' => 'retour-redirect-caches', |
586 | 586 | 'label' => Craft::t('retour', 'Retour redirect caches'), |
587 | - 'action' => [self::$plugin->redirects, 'invalidateCaches'], |
|
587 | + 'action' => [ self::$plugin->redirects, 'invalidateCaches' ], |
|
588 | 588 | ], |
589 | 589 | ]; |
590 | 590 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $siteId = 0 |
63 | 63 | ): Response { |
64 | 64 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
65 | - $data = []; |
|
65 | + $data = [ ]; |
|
66 | 66 | $sortField = 'hitCount'; |
67 | 67 | $sortType = 'DESC'; |
68 | 68 | // Figure out the sorting type |
@@ -76,42 +76,42 @@ discard block |
||
76 | 76 | // Query the db table |
77 | 77 | $offset = ($page - 1) * $per_page; |
78 | 78 | $query = (new Query()) |
79 | - ->from(['{{%retour_stats}}']) |
|
79 | + ->from([ '{{%retour_stats}}' ]) |
|
80 | 80 | ->offset($offset) |
81 | 81 | ->limit($per_page) |
82 | 82 | ->orderBy("{$sortField} {$sortType}"); |
83 | - if ((int)$siteId !== 0) { |
|
84 | - $query->where(['siteId' => $siteId]); |
|
83 | + if ((int) $siteId !== 0) { |
|
84 | + $query->where([ 'siteId' => $siteId ]); |
|
85 | 85 | } |
86 | 86 | if ($filter !== '') { |
87 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
88 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
87 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
88 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
89 | 89 | } |
90 | 90 | $stats = $query->all(); |
91 | 91 | if ($stats) { |
92 | 92 | // Add in the `addLink` field |
93 | 93 | foreach ($stats as &$stat) { |
94 | - $stat['addLink'] = ''; |
|
95 | - if (!$stat['handledByRetour']) { |
|
96 | - $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/')); |
|
97 | - $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
94 | + $stat[ 'addLink' ] = ''; |
|
95 | + if (!$stat[ 'handledByRetour' ]) { |
|
96 | + $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/')); |
|
97 | + $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
98 | 98 | 'defaultUrl' => $encodedUrl |
99 | 99 | ]); |
100 | 100 | } |
101 | 101 | } |
102 | 102 | // Format the data for the API |
103 | - $data['data'] = $stats; |
|
103 | + $data[ 'data' ] = $stats; |
|
104 | 104 | $query = (new Query()) |
105 | - ->from(['{{%retour_stats}}']); |
|
106 | - if ((int)$siteId !== 0) { |
|
107 | - $query->where(['siteId' => $siteId]); |
|
105 | + ->from([ '{{%retour_stats}}' ]); |
|
106 | + if ((int) $siteId !== 0) { |
|
107 | + $query->where([ 'siteId' => $siteId ]); |
|
108 | 108 | } |
109 | 109 | if ($filter !== '') { |
110 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
111 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
110 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
111 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
112 | 112 | } |
113 | 113 | $count = $query->count(); |
114 | - $data['links']['pagination'] = [ |
|
114 | + $data[ 'links' ][ 'pagination' ] = [ |
|
115 | 115 | 'total' => $count, |
116 | 116 | 'per_page' => $per_page, |
117 | 117 | 'current_page' => $page, |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $siteId = 0 |
147 | 147 | ): Response { |
148 | 148 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
149 | - $data = []; |
|
149 | + $data = [ ]; |
|
150 | 150 | $sortField = 'hitCount'; |
151 | 151 | $sortType = 'DESC'; |
152 | 152 | // Figure out the sorting type |
@@ -160,43 +160,43 @@ discard block |
||
160 | 160 | // Query the db table |
161 | 161 | $offset = ($page - 1) * $per_page; |
162 | 162 | $query = (new Query()) |
163 | - ->from(['{{%retour_static_redirects}}']) |
|
163 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
164 | 164 | ->offset($offset) |
165 | 165 | ->limit($per_page) |
166 | 166 | ->orderBy("{$sortField} {$sortType}"); |
167 | - if ((int)$siteId !== 0) { |
|
168 | - $query->where(['siteId' => $siteId]); |
|
167 | + if ((int) $siteId !== 0) { |
|
168 | + $query->where([ 'siteId' => $siteId ]); |
|
169 | 169 | } |
170 | 170 | if ($filter !== '') { |
171 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
172 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
171 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
172 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
173 | 173 | } |
174 | 174 | $redirects = $query->all(); |
175 | 175 | // Add in the `deleteLink` field and clean up the redirects |
176 | 176 | foreach ($redirects as &$redirect) { |
177 | 177 | // Make sure the destination URL is not a regex |
178 | - if ($redirect['redirectMatchType'] !== 'exactmatch') { |
|
179 | - if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) { |
|
180 | - $redirect['redirectDestUrl'] = ''; |
|
178 | + if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') { |
|
179 | + if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) { |
|
180 | + $redirect[ 'redirectDestUrl' ] = ''; |
|
181 | 181 | } |
182 | 182 | } |
183 | - $redirect['deleteLink'] = UrlHelper::cpUrl('retour/delete-redirect/'.$redirect['id']); |
|
184 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
183 | + $redirect[ 'deleteLink' ] = UrlHelper::cpUrl('retour/delete-redirect/' . $redirect[ 'id' ]); |
|
184 | + $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]); |
|
185 | 185 | } |
186 | 186 | // Format the data for the API |
187 | 187 | if ($redirects) { |
188 | - $data['data'] = $redirects; |
|
188 | + $data[ 'data' ] = $redirects; |
|
189 | 189 | $query = (new Query()) |
190 | - ->from(['{{%retour_static_redirects}}']); |
|
191 | - if ((int)$siteId !== 0) { |
|
192 | - $query->where(['siteId' => $siteId]); |
|
190 | + ->from([ '{{%retour_static_redirects}}' ]); |
|
191 | + if ((int) $siteId !== 0) { |
|
192 | + $query->where([ 'siteId' => $siteId ]); |
|
193 | 193 | } |
194 | 194 | if ($filter !== '') { |
195 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
196 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
195 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
196 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
197 | 197 | } |
198 | 198 | $count = $query->count(); |
199 | - $data['links']['pagination'] = [ |
|
199 | + $data[ 'links' ][ 'pagination' ] = [ |
|
200 | 200 | 'total' => $count, |
201 | 201 | 'per_page' => $per_page, |
202 | 202 | 'current_page' => $page, |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | // Protected Properties |
42 | 42 | // ========================================================================= |
43 | 43 | |
44 | - protected $allowAnonymous = []; |
|
44 | + protected $allowAnonymous = [ ]; |
|
45 | 45 | |
46 | 46 | // Public Methods |
47 | 47 | // ========================================================================= |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function actionRedirects(string $siteHandle = null): Response |
59 | 59 | { |
60 | - $variables = []; |
|
60 | + $variables = [ ]; |
|
61 | 61 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
62 | 62 | // Get the site to edit |
63 | 63 | $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle); |
@@ -70,32 +70,32 @@ discard block |
||
70 | 70 | } catch (InvalidConfigException $e) { |
71 | 71 | Craft::error($e->getMessage(), __METHOD__); |
72 | 72 | } |
73 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
73 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
74 | 74 | '@nystudio107/retour/assetbundles/retour/dist', |
75 | 75 | true |
76 | 76 | ); |
77 | 77 | // Enabled sites |
78 | 78 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
79 | - $variables['controllerHandle'] = 'redirects'; |
|
79 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
80 | 80 | |
81 | 81 | // Basic variables |
82 | - $variables['fullPageForm'] = false; |
|
83 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
84 | - $variables['pluginName'] = $pluginName; |
|
85 | - $variables['title'] = $templateTitle; |
|
86 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
87 | - $variables['crumbs'] = [ |
|
82 | + $variables[ 'fullPageForm' ] = false; |
|
83 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
84 | + $variables[ 'pluginName' ] = $pluginName; |
|
85 | + $variables[ 'title' ] = $templateTitle; |
|
86 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
87 | + $variables[ 'crumbs' ] = [ |
|
88 | 88 | [ |
89 | 89 | 'label' => $pluginName, |
90 | 90 | 'url' => UrlHelper::cpUrl('retour'), |
91 | 91 | ], |
92 | 92 | [ |
93 | 93 | 'label' => $templateTitle, |
94 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
94 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
95 | 95 | ], |
96 | 96 | ]; |
97 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
98 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
97 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
98 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
99 | 99 | |
100 | 100 | // Render the template |
101 | 101 | return $this->renderTemplate('retour/redirects/index', $variables); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | int $siteId = 0, |
120 | 120 | StaticRedirectsModel $redirect = null |
121 | 121 | ): Response { |
122 | - $variables = []; |
|
122 | + $variables = [ ]; |
|
123 | 123 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
124 | 124 | // Load in the redirect |
125 | 125 | if ($redirectId === 0) { |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | if ($redirect === null) { |
133 | 133 | $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId); |
134 | 134 | if ($redirectConfig === null) { |
135 | - $redirectConfig = []; |
|
135 | + $redirectConfig = [ ]; |
|
136 | 136 | Craft::error( |
137 | 137 | Craft::t( |
138 | 138 | 'retour', |
139 | 139 | "Couldn't load redirect id {id}", |
140 | - ['id' => $redirectId] |
|
140 | + [ 'id' => $redirectId ] |
|
141 | 141 | ), |
142 | 142 | __METHOD__ |
143 | 143 | ); |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | } catch (InvalidConfigException $e) { |
155 | 155 | Craft::error($e->getMessage(), __METHOD__); |
156 | 156 | } |
157 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
157 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
158 | 158 | '@nystudio107/retour/assetbundles/retour/dist', |
159 | 159 | true |
160 | 160 | ); |
161 | 161 | // Sites menu |
162 | 162 | MultiSiteHelper::setSitesMenuVariables($variables); |
163 | - $variables['controllerHandle'] = 'redirects'; |
|
163 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
164 | 164 | |
165 | 165 | // Basic variables |
166 | - $variables['fullPageForm'] = true; |
|
167 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
168 | - $variables['pluginName'] = $pluginName; |
|
169 | - $variables['title'] = $templateTitle; |
|
170 | - $variables['crumbs'] = [ |
|
166 | + $variables[ 'fullPageForm' ] = true; |
|
167 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
168 | + $variables[ 'pluginName' ] = $pluginName; |
|
169 | + $variables[ 'title' ] = $templateTitle; |
|
170 | + $variables[ 'crumbs' ] = [ |
|
171 | 171 | [ |
172 | 172 | 'label' => $pluginName, |
173 | 173 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | ], |
179 | 179 | [ |
180 | 180 | 'label' => $templateTitle, |
181 | - 'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId), |
|
181 | + 'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId), |
|
182 | 182 | ], |
183 | 183 | ]; |
184 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
185 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
186 | - $variables['redirect'] = $redirect; |
|
184 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
185 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
186 | + $variables[ 'redirect' ] = $redirect; |
|
187 | 187 | |
188 | 188 | // Render the template |
189 | 189 | return $this->renderTemplate('retour/redirects/_edit', $variables); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | if ($redirectConfig === null) { |
230 | 230 | throw new NotFoundHttpException('Redirect not found'); |
231 | 231 | } |
232 | - $redirectConfig['id'] = (int)$redirectConfig['id']; |
|
232 | + $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ]; |
|
233 | 233 | $redirect = new StaticRedirectsModel($redirectConfig); |
234 | 234 | // Make sure the redirect validates |
235 | 235 | if (!$redirect->validate()) { |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
247 | 247 | // Handle the case where the redirect wasn't saved because it'd create a redirect loop |
248 | 248 | $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl( |
249 | - $redirectConfig['redirectSrcUrl'], |
|
250 | - $redirectConfig['siteId'] |
|
249 | + $redirectConfig[ 'redirectSrcUrl' ], |
|
250 | + $redirectConfig[ 'siteId' ] |
|
251 | 251 | ); |
252 | 252 | if ($testRedirectConfig === null) { |
253 | 253 | Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop.")); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | Craft::t( |
129 | 129 | 'retour', |
130 | 130 | '404 full URL: {fullUrl}, 404 path only: {pathOnly}', |
131 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
131 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
132 | 132 | ), |
133 | 133 | __METHOD__ |
134 | 134 | ); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $response = Craft::$app->getResponse(); |
161 | 161 | if ($redirect !== null) { |
162 | 162 | // Figure out what type of source matching was done |
163 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
163 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
164 | 164 | switch ($redirectSrcMatch) { |
165 | 165 | case 'pathonly': |
166 | 166 | $url = $pathOnly; |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | $url = $pathOnly; |
173 | 173 | break; |
174 | 174 | } |
175 | - $dest = $redirect['redirectDestUrl']; |
|
175 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
176 | 176 | if (Retour::$settings->preserveQueryString) { |
177 | 177 | $request = Craft::$app->getRequest(); |
178 | 178 | if (!empty($request->getQueryStringWithoutPath())) { |
179 | 179 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
180 | 180 | } |
181 | 181 | } |
182 | - $status = $redirect['redirectHttpCode']; |
|
182 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
183 | 183 | Craft::info( |
184 | 184 | Craft::t( |
185 | 185 | 'retour', |
186 | 186 | 'Redirecting {url} to {dest} with status {status}', |
187 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
187 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
188 | 188 | ), |
189 | 189 | __METHOD__ |
190 | 190 | ); |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | public function getRedirectFromCache($url, int $siteId = 0) |
265 | 265 | { |
266 | 266 | $cache = Craft::$app->getCache(); |
267 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
267 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
268 | 268 | $redirect = $cache->get($cacheKey); |
269 | 269 | Craft::info( |
270 | 270 | Craft::t( |
271 | 271 | 'retour', |
272 | 272 | 'Cached redirect hit for {url}', |
273 | - ['url' => $url] |
|
273 | + [ 'url' => $url ] |
|
274 | 274 | ), |
275 | 275 | __METHOD__ |
276 | 276 | ); |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | } catch (SiteNotFoundException $e) { |
293 | 293 | $siteId = 1; |
294 | 294 | } |
295 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
295 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
296 | 296 | // Create the dependency tags |
297 | 297 | $dependency = new TagDependency([ |
298 | 298 | 'tags' => [ |
299 | 299 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
300 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
300 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
301 | 301 | ], |
302 | 302 | ]); |
303 | 303 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | Craft::t( |
306 | 306 | 'retour', |
307 | 307 | 'Cached redirect saved for {url}', |
308 | - ['url' => $url] |
|
308 | + [ 'url' => $url ] |
|
309 | 309 | ), |
310 | 310 | __METHOD__ |
311 | 311 | ); |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | $result = null; |
324 | 324 | foreach ($redirects as $redirect) { |
325 | 325 | // Figure out what type of source matching to do |
326 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
327 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
326 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
327 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
328 | 328 | if ($redirectEnabled === true) { |
329 | 329 | switch ($redirectSrcMatch) { |
330 | 330 | case 'pathonly': |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | $url = $pathOnly; |
338 | 338 | break; |
339 | 339 | } |
340 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
340 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
341 | 341 | switch ($redirectMatchType) { |
342 | 342 | // Do a straight up match |
343 | 343 | case 'exactmatch': |
344 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
344 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
345 | 345 | $this->incrementRedirectHitCount($redirect); |
346 | 346 | $this->saveRedirectToCache($url, $redirect); |
347 | 347 | |
@@ -351,14 +351,14 @@ discard block |
||
351 | 351 | |
352 | 352 | // Do a regex match |
353 | 353 | case 'regexmatch': |
354 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
354 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
355 | 355 | if (preg_match($matchRegEx, $url) === 1) { |
356 | 356 | $this->incrementRedirectHitCount($redirect); |
357 | 357 | // If we're not associated with an EntryID, handle capture group replacement |
358 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
359 | - $redirect['redirectDestUrl'] = preg_replace( |
|
358 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
359 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
360 | 360 | $matchRegEx, |
361 | - $redirect['redirectDestUrl'], |
|
361 | + $redirect[ 'redirectDestUrl' ], |
|
362 | 362 | $url |
363 | 363 | ); |
364 | 364 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | 'redirect' => &$redirect, |
378 | 378 | ], |
379 | 379 | ]; |
380 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
380 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
381 | 381 | if ($result) { |
382 | 382 | $this->incrementRedirectHitCount($redirect); |
383 | 383 | $this->saveRedirectToCache($url, $redirect); |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | Craft::t( |
394 | 394 | 'retour', |
395 | 395 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
396 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
396 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
397 | 397 | ), |
398 | 398 | __METHOD__ |
399 | 399 | ); |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
418 | 418 | /** @var Plugin $plugin */ |
419 | 419 | if (method_exists($plugin, 'retourMatch')) { |
420 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
420 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
@@ -438,12 +438,12 @@ discard block |
||
438 | 438 | } |
439 | 439 | // Query the db table |
440 | 440 | $query = (new Query()) |
441 | - ->from(['{{%retour_static_redirects}}']) |
|
441 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
442 | 442 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
443 | 443 | if ($siteId) { |
444 | 444 | $query |
445 | - ->where(['siteId' => $siteId]) |
|
446 | - ->orWhere(['siteId' => null]); |
|
445 | + ->where([ 'siteId' => $siteId ]) |
|
446 | + ->orWhere([ 'siteId' => null ]); |
|
447 | 447 | } |
448 | 448 | if ($limit) { |
449 | 449 | $query->limit($limit); |
@@ -466,8 +466,8 @@ discard block |
||
466 | 466 | { |
467 | 467 | // Query the db table |
468 | 468 | $redirect = (new Query()) |
469 | - ->from(['{{%retour_static_redirects}}']) |
|
470 | - ->where(['id' => $id]) |
|
469 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
470 | + ->where([ 'id' => $id ]) |
|
471 | 471 | ->one(); |
472 | 472 | |
473 | 473 | return $redirect; |
@@ -485,13 +485,13 @@ discard block |
||
485 | 485 | { |
486 | 486 | // Query the db table |
487 | 487 | $query = (new Query()) |
488 | - ->from(['{{%retour_static_redirects}}']) |
|
489 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
488 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
489 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
490 | 490 | ; |
491 | 491 | if ($siteId) { |
492 | 492 | $query |
493 | - ->andWhere(['siteId' => $siteId]) |
|
494 | - ->orWhere(['siteId' => null]); |
|
493 | + ->andWhere([ 'siteId' => $siteId ]) |
|
494 | + ->orWhere([ 'siteId' => null ]); |
|
495 | 495 | } |
496 | 496 | $redirect = $query->one(); |
497 | 497 | |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | { |
534 | 534 | if ($redirectConfig !== null) { |
535 | 535 | $db = Craft::$app->getDb(); |
536 | - $redirectConfig['hitCount']++; |
|
537 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
536 | + $redirectConfig[ 'hitCount' ]++; |
|
537 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
538 | 538 | Craft::debug( |
539 | 539 | Craft::t( |
540 | 540 | 'retour', |
541 | 541 | 'Incrementing statistics for: {redirect}', |
542 | - ['redirect' => print_r($redirectConfig, true)] |
|
542 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
543 | 543 | ), |
544 | 544 | __METHOD__ |
545 | 545 | ); |
@@ -548,14 +548,14 @@ discard block |
||
548 | 548 | $rowsAffected = $db->createCommand()->update( |
549 | 549 | '{{%retour_static_redirects}}', |
550 | 550 | [ |
551 | - 'hitCount' => $redirectConfig['hitCount'], |
|
552 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
551 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
552 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
553 | 553 | ], |
554 | 554 | [ |
555 | - 'id' => $redirectConfig['id'], |
|
555 | + 'id' => $redirectConfig[ 'id' ], |
|
556 | 556 | ] |
557 | 557 | )->execute(); |
558 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
558 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
559 | 559 | } catch (Exception $e) { |
560 | 560 | Craft::error($e->getMessage(), __METHOD__); |
561 | 561 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | Craft::t( |
575 | 575 | 'retour', |
576 | 576 | 'Error validating redirect {id}: {errors}', |
577 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
577 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
578 | 578 | ), |
579 | 579 | __METHOD__ |
580 | 580 | ); |
@@ -584,32 +584,32 @@ discard block |
||
584 | 584 | // Get the validated model attributes and save them to the db |
585 | 585 | $redirectConfig = $redirect->getAttributes(); |
586 | 586 | // 0 for a siteId needs to be converted to null |
587 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
588 | - $redirectConfig['siteId'] = null; |
|
587 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
588 | + $redirectConfig[ 'siteId' ] = null; |
|
589 | 589 | } |
590 | 590 | // Throw an event to before saving the redirect |
591 | 591 | $db = Craft::$app->getDb(); |
592 | 592 | // See if a redirect exists with this source URL already |
593 | - if ((int)$redirectConfig['id'] === 0) { |
|
593 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
594 | 594 | // Query the db table |
595 | 595 | $redirect = (new Query()) |
596 | - ->from(['{{%retour_static_redirects}}']) |
|
597 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
598 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
596 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
597 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
598 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
599 | 599 | ->one(); |
600 | 600 | // If it exists, update it rather than having duplicates |
601 | 601 | if (!empty($redirect)) { |
602 | - $redirectConfig['id'] = $redirect['id']; |
|
602 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | // Trigger a 'beforeSaveRedirect' event |
606 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
606 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
607 | 607 | $event = new RedirectEvent([ |
608 | 608 | 'isNew' => $isNew, |
609 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
610 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
611 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
612 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
609 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
610 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
611 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
612 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
613 | 613 | ]); |
614 | 614 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
615 | 615 | if (!$event->isValid) { |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | Craft::t( |
622 | 622 | 'retour', |
623 | 623 | 'Updating existing redirect: {redirect}', |
624 | - ['redirect' => print_r($redirectConfig, true)] |
|
624 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
625 | 625 | ), |
626 | 626 | __METHOD__ |
627 | 627 | ); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | '{{%retour_static_redirects}}', |
632 | 632 | $redirectConfig, |
633 | 633 | [ |
634 | - 'id' => $redirectConfig['id'], |
|
634 | + 'id' => $redirectConfig[ 'id' ], |
|
635 | 635 | ] |
636 | 636 | )->execute(); |
637 | 637 | } catch (Exception $e) { |
@@ -642,11 +642,11 @@ discard block |
||
642 | 642 | Craft::t( |
643 | 643 | 'retour', |
644 | 644 | 'Creating new redirect: {redirect}', |
645 | - ['redirect' => print_r($redirectConfig, true)] |
|
645 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
646 | 646 | ), |
647 | 647 | __METHOD__ |
648 | 648 | ); |
649 | - unset($redirectConfig['id']); |
|
649 | + unset($redirectConfig[ 'id' ]); |
|
650 | 650 | // Create a new record |
651 | 651 | try { |
652 | 652 | $db->createCommand()->insert( |
@@ -659,15 +659,15 @@ discard block |
||
659 | 659 | } |
660 | 660 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
661 | 661 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
662 | - $redirectConfig['redirectDestUrl'], |
|
663 | - $redirectConfig['siteId'] |
|
662 | + $redirectConfig[ 'redirectDestUrl' ], |
|
663 | + $redirectConfig[ 'siteId' ] |
|
664 | 664 | ); |
665 | 665 | if ($testRedirectConfig !== null) { |
666 | 666 | Craft::debug( |
667 | 667 | Craft::t( |
668 | 668 | 'retour', |
669 | 669 | 'Deleting redirect to prevent a loop: {redirect}', |
670 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
670 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
671 | 671 | ), |
672 | 672 | __METHOD__ |
673 | 673 | ); |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | try { |
676 | 676 | $db->createCommand()->delete( |
677 | 677 | '{{%retour_static_redirects}}', |
678 | - ['id' => $testRedirectConfig['id']] |
|
678 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
679 | 679 | )->execute(); |
680 | 680 | } catch (Exception $e) { |
681 | 681 | Craft::error($e->getMessage(), __METHOD__); |