@@ -20,10 +20,10 @@ |
||
| 20 | 20 | $schemaVersion = $projectConfig->get('plugins.retour.schemaVersion', true); |
| 21 | 21 | |
| 22 | 22 | if (version_compare($schemaVersion, '3.0.10', '<')) { |
| 23 | - foreach ($projectConfig->get('graphql.schemas') ?? [] as $schemaUid => $schemaComponents) { |
|
| 24 | - if (isset($schemaComponents['scope'])) { |
|
| 25 | - $scope = $schemaComponents['scope']; |
|
| 26 | - $scope[] = 'retour.all:read'; |
|
| 23 | + foreach ($projectConfig->get('graphql.schemas') ?? [ ] as $schemaUid => $schemaComponents) { |
|
| 24 | + if (isset($schemaComponents[ 'scope' ])) { |
|
| 25 | + $scope = $schemaComponents[ 'scope' ]; |
|
| 26 | + $scope[ ] = 'retour.all:read'; |
|
| 27 | 27 | |
| 28 | 28 | $projectConfig->set("graphql.schemas.$schemaUid.scope", $scope); |
| 29 | 29 | } |
@@ -17,6 +17,6 @@ |
||
| 17 | 17 | { |
| 18 | 18 | $allowedEntities = self::extractAllowedEntitiesFromSchema(); |
| 19 | 19 | |
| 20 | - return isset($allowedEntities['retour']); |
|
| 20 | + return isset($allowedEntities[ 'retour' ]); |
|
| 21 | 21 | } |
| 22 | 22 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | public static function getQueries($checkToken = true): array |
| 35 | 35 | { |
| 36 | 36 | if ($checkToken && !GqlHelper::canQueryRetour()) { |
| 37 | - return []; |
|
| 37 | + return [ ]; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | return [ |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $handled = 'all' |
| 98 | 98 | ): Response { |
| 99 | 99 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
| 100 | - $data = []; |
|
| 100 | + $data = [ ]; |
|
| 101 | 101 | $sortField = 'hitCount'; |
| 102 | 102 | $sortType = 'DESC'; |
| 103 | 103 | // Figure out the sorting type |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | $sortType = strtoupper($sortType); |
| 112 | - $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC']; |
|
| 112 | + $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ]; |
|
| 113 | 113 | // Validate untrusted data |
| 114 | 114 | if (!in_array($sortField, self::ALLOWED_STATS_SORT_FIELDS, true)) { |
| 115 | 115 | throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.')); |
@@ -117,46 +117,46 @@ discard block |
||
| 117 | 117 | // Query the db table |
| 118 | 118 | $offset = ($page - 1) * $per_page; |
| 119 | 119 | $query = (new Query()) |
| 120 | - ->from(['{{%retour_stats}}']) |
|
| 120 | + ->from([ '{{%retour_stats}}' ]) |
|
| 121 | 121 | ->offset($offset) |
| 122 | 122 | ->limit($per_page) |
| 123 | - ->orderBy([$sortField => $sortType]) |
|
| 124 | - ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
|
| 125 | - ->orFilterWhere(['like', 'referrerUrl', $filter]) |
|
| 123 | + ->orderBy([ $sortField => $sortType ]) |
|
| 124 | + ->filterWhere([ 'like', 'redirectSrcUrl', $filter ]) |
|
| 125 | + ->orFilterWhere([ 'like', 'referrerUrl', $filter ]) |
|
| 126 | 126 | ; |
| 127 | - if ((int)$siteId !== 0) { |
|
| 128 | - $query->andWhere(['siteId' => $siteId]); |
|
| 127 | + if ((int) $siteId !== 0) { |
|
| 128 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 129 | 129 | } |
| 130 | 130 | if ($handled !== 'all') { |
| 131 | - $query->andWhere(['handledByRetour' => self::HANDLED_MAP[$handled]]); |
|
| 131 | + $query->andWhere([ 'handledByRetour' => self::HANDLED_MAP[ $handled ] ]); |
|
| 132 | 132 | } |
| 133 | 133 | $stats = $query->all(); |
| 134 | 134 | if ($stats) { |
| 135 | 135 | // Add in the `addLink` field |
| 136 | 136 | foreach ($stats as &$stat) { |
| 137 | - $stat['addLink'] = ''; |
|
| 138 | - if (!$stat['handledByRetour']) { |
|
| 139 | - $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/')); |
|
| 137 | + $stat[ 'addLink' ] = ''; |
|
| 138 | + if (!$stat[ 'handledByRetour' ]) { |
|
| 139 | + $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/')); |
|
| 140 | 140 | // Add the siteId to the URL, but keep the current behavior of passing in siteId=0 for "all" |
| 141 | - $statSiteId = $stat['siteId'] ?? 0; |
|
| 141 | + $statSiteId = $stat[ 'siteId' ] ?? 0; |
|
| 142 | 142 | try { |
| 143 | 143 | $primarySite = Craft::$app->getSites()->getPrimarySite(); |
| 144 | 144 | } catch (SiteNotFoundException $e) { |
| 145 | 145 | $primarySite = null; |
| 146 | 146 | } |
| 147 | - if ($primarySite !== null && $statSiteId == (int)$primarySite->id) { |
|
| 147 | + if ($primarySite !== null && $statSiteId == (int) $primarySite->id) { |
|
| 148 | 148 | $statSiteId = 0; |
| 149 | 149 | } |
| 150 | - $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
| 150 | + $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
| 151 | 151 | 'defaultUrl' => $encodedUrl, |
| 152 | 152 | 'siteId' => $statSiteId |
| 153 | 153 | ]); |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | // Format the data for the API |
| 157 | - $data['data'] = $stats; |
|
| 157 | + $data[ 'data' ] = $stats; |
|
| 158 | 158 | $count = $query->count(); |
| 159 | - $data['links']['pagination'] = [ |
|
| 159 | + $data[ 'links' ][ 'pagination' ] = [ |
|
| 160 | 160 | 'total' => $count, |
| 161 | 161 | 'per_page' => $per_page, |
| 162 | 162 | 'current_page' => $page, |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $siteId = 0 |
| 193 | 193 | ): Response { |
| 194 | 194 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 195 | - $data = []; |
|
| 195 | + $data = [ ]; |
|
| 196 | 196 | $sortField = 'hitCount'; |
| 197 | 197 | $sortType = 'DESC'; |
| 198 | 198 | // Figure out the sorting type |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | $sortType = strtoupper($sortType); |
| 207 | - $sortType = self::SORT_MAP[$sortType] ?? self::SORT_MAP['DESC']; |
|
| 207 | + $sortType = self::SORT_MAP[ $sortType ] ?? self::SORT_MAP[ 'DESC' ]; |
|
| 208 | 208 | // Validate untrusted data |
| 209 | 209 | if (!in_array($sortField, self::ALLOWED_REDIRECTS_SORT_FIELDS, true)) { |
| 210 | 210 | throw new BadRequestHttpException(Craft::t('retour', 'Invalid sort field specified.')); |
@@ -212,42 +212,42 @@ discard block |
||
| 212 | 212 | // Query the db table |
| 213 | 213 | $offset = ($page - 1) * $per_page; |
| 214 | 214 | $query = (new Query()) |
| 215 | - ->from(['{{%retour_static_redirects}}']) |
|
| 215 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 216 | 216 | ->offset($offset) |
| 217 | 217 | ->limit($per_page) |
| 218 | - ->orderBy([$sortField => $sortType]) |
|
| 219 | - ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
|
| 220 | - ->orFilterWhere(['like', 'redirectDestUrl', $filter]) |
|
| 218 | + ->orderBy([ $sortField => $sortType ]) |
|
| 219 | + ->filterWhere([ 'like', 'redirectSrcUrl', $filter ]) |
|
| 220 | + ->orFilterWhere([ 'like', 'redirectDestUrl', $filter ]) |
|
| 221 | 221 | ; |
| 222 | - if ((int)$siteId !== 0) { |
|
| 223 | - $query->andWhere(['siteId' => $siteId]); |
|
| 222 | + if ((int) $siteId !== 0) { |
|
| 223 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 224 | 224 | } |
| 225 | 225 | $redirects = $query->all(); |
| 226 | 226 | // Add in the `deleteLink` field and clean up the redirects |
| 227 | 227 | foreach ($redirects as &$redirect) { |
| 228 | 228 | // Make sure the destination URL is not a regex |
| 229 | - if ($redirect['redirectMatchType'] !== 'exactmatch') { |
|
| 230 | - if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) { |
|
| 231 | - $redirect['redirectDestUrl'] = ''; |
|
| 229 | + if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') { |
|
| 230 | + if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) { |
|
| 231 | + $redirect[ 'redirectDestUrl' ] = ''; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | // Handle extracting the site name |
| 235 | - $redirect['siteName'] = Craft::t('retour', 'All Sites'); |
|
| 236 | - if ($redirect['siteId']) { |
|
| 235 | + $redirect[ 'siteName' ] = Craft::t('retour', 'All Sites'); |
|
| 236 | + if ($redirect[ 'siteId' ]) { |
|
| 237 | 237 | $sites = Craft::$app->getSites(); |
| 238 | - $site = $sites->getSiteById($redirect['siteId']); |
|
| 238 | + $site = $sites->getSiteById($redirect[ 'siteId' ]); |
|
| 239 | 239 | if ($site) { |
| 240 | - $redirect['siteName'] = $site->name; |
|
| 240 | + $redirect[ 'siteName' ] = $site->name; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
| 244 | + $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]); |
|
| 245 | 245 | } |
| 246 | 246 | // Format the data for the API |
| 247 | 247 | if ($redirects) { |
| 248 | - $data['data'] = $redirects; |
|
| 248 | + $data[ 'data' ] = $redirects; |
|
| 249 | 249 | $count = $query->count(); |
| 250 | - $data['links']['pagination'] = [ |
|
| 250 | + $data[ 'links' ][ 'pagination' ] = [ |
|
| 251 | 251 | 'total' => $count, |
| 252 | 252 | 'per_page' => $per_page, |
| 253 | 253 | 'current_page' => $page, |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | Craft::t( |
| 193 | 193 | 'retour', |
| 194 | 194 | '404 full URL: {fullUrl}, 404 path only: {pathOnly}', |
| 195 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
| 195 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
| 196 | 196 | ), |
| 197 | 197 | __METHOD__ |
| 198 | 198 | ); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $response = Craft::$app->getResponse(); |
| 227 | 227 | if ($redirect !== null) { |
| 228 | 228 | // Figure out what type of source matching was done |
| 229 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
| 229 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
| 230 | 230 | switch ($redirectSrcMatch) { |
| 231 | 231 | case 'pathonly': |
| 232 | 232 | $url = $pathOnly; |
@@ -238,13 +238,13 @@ discard block |
||
| 238 | 238 | $url = $pathOnly; |
| 239 | 239 | break; |
| 240 | 240 | } |
| 241 | - $dest = $redirect['redirectDestUrl']; |
|
| 241 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
| 242 | 242 | // If this isn't a full URL, make it one based on the appropriate site |
| 243 | 243 | if (!UrlHelper::isFullUrl($dest)) { |
| 244 | 244 | try { |
| 245 | - $siteId = $redirect['siteId'] ?? null; |
|
| 245 | + $siteId = $redirect[ 'siteId' ] ?? null; |
|
| 246 | 246 | if ($siteId !== null) { |
| 247 | - $siteId = (int)$siteId; |
|
| 247 | + $siteId = (int) $siteId; |
|
| 248 | 248 | } |
| 249 | 249 | $dest = UrlHelper::siteUrl($dest, null, null, $siteId); |
| 250 | 250 | } catch (\yii\base\Exception $e) { |
@@ -256,17 +256,17 @@ discard block |
||
| 256 | 256 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
| 259 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
| 260 | 260 | // Parse reference tags for exact matches |
| 261 | 261 | if ($redirectMatchType === 'exactmatch') { |
| 262 | - $dest = Craft::$app->elements->parseRefs($dest, $redirect['siteId'] ?? null); |
|
| 262 | + $dest = Craft::$app->elements->parseRefs($dest, $redirect[ 'siteId' ] ?? null); |
|
| 263 | 263 | } |
| 264 | - $status = $redirect['redirectHttpCode']; |
|
| 264 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
| 265 | 265 | Craft::info( |
| 266 | 266 | Craft::t( |
| 267 | 267 | 'retour', |
| 268 | 268 | 'Redirecting {url} to {dest} with status {status}', |
| 269 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
| 269 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
| 270 | 270 | ), |
| 271 | 271 | __METHOD__ |
| 272 | 272 | ); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // Add any additional headers (existing ones will be replaced) |
| 291 | 291 | if (!empty(Retour::$settings->additionalHeaders)) { |
| 292 | 292 | foreach (Retour::$settings->additionalHeaders as $additionalHeader) { |
| 293 | - $response->headers->set($additionalHeader['name'], $additionalHeader['value']); |
|
| 293 | + $response->headers->set($additionalHeader[ 'name' ], $additionalHeader[ 'value' ]); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | // Redirect the request away; |
@@ -361,13 +361,13 @@ discard block |
||
| 361 | 361 | public function getRedirectFromCache($url, int $siteId = 0) |
| 362 | 362 | { |
| 363 | 363 | $cache = Craft::$app->getCache(); |
| 364 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 364 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 365 | 365 | $redirect = $cache->get($cacheKey); |
| 366 | 366 | Craft::info( |
| 367 | 367 | Craft::t( |
| 368 | 368 | 'retour', |
| 369 | 369 | 'Cached redirect hit for {url}', |
| 370 | - ['url' => $url] |
|
| 370 | + [ 'url' => $url ] |
|
| 371 | 371 | ), |
| 372 | 372 | __METHOD__ |
| 373 | 373 | ); |
@@ -389,12 +389,12 @@ discard block |
||
| 389 | 389 | } catch (SiteNotFoundException $e) { |
| 390 | 390 | $siteId = 1; |
| 391 | 391 | } |
| 392 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 392 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 393 | 393 | // Create the dependency tags |
| 394 | 394 | $dependency = new TagDependency([ |
| 395 | 395 | 'tags' => [ |
| 396 | 396 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
| 397 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
| 397 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
| 398 | 398 | ], |
| 399 | 399 | ]); |
| 400 | 400 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | Craft::t( |
| 403 | 403 | 'retour', |
| 404 | 404 | 'Cached redirect saved for {url}', |
| 405 | - ['url' => $url] |
|
| 405 | + [ 'url' => $url ] |
|
| 406 | 406 | ), |
| 407 | 407 | __METHOD__ |
| 408 | 408 | ); |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | // Iterate through the redirects |
| 434 | 434 | foreach ($redirects as $redirect) { |
| 435 | 435 | // Figure out what type of source matching to do |
| 436 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
| 437 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
| 436 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
| 437 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
| 438 | 438 | if ($redirectEnabled === true) { |
| 439 | 439 | switch ($redirectSrcMatch) { |
| 440 | 440 | case 'pathonly': |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | $url = $pathOnly; |
| 448 | 448 | break; |
| 449 | 449 | } |
| 450 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
| 450 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
| 451 | 451 | switch ($redirectMatchType) { |
| 452 | 452 | // Do a straight up match |
| 453 | 453 | case 'exactmatch': |
| 454 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
| 454 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
| 455 | 455 | $this->incrementRedirectHitCount($redirect); |
| 456 | 456 | $this->saveRedirectToCache($url, $redirect); |
| 457 | 457 | |
@@ -475,15 +475,15 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | // Do a regex match |
| 477 | 477 | case 'regexmatch': |
| 478 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
| 478 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
| 479 | 479 | try { |
| 480 | 480 | if (preg_match($matchRegEx, $url) === 1) { |
| 481 | 481 | $this->incrementRedirectHitCount($redirect); |
| 482 | 482 | // If we're not associated with an EntryID, handle capture group replacement |
| 483 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
| 484 | - $redirect['redirectDestUrl'] = preg_replace( |
|
| 483 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
| 484 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
| 485 | 485 | $matchRegEx, |
| 486 | - $redirect['redirectDestUrl'], |
|
| 486 | + $redirect[ 'redirectDestUrl' ], |
|
| 487 | 487 | $url |
| 488 | 488 | ); |
| 489 | 489 | } |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | } |
| 509 | 509 | } catch (\Exception $e) { |
| 510 | 510 | // That's fine |
| 511 | - Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__); |
|
| 511 | + Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | break; |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | 'redirect' => &$redirect, |
| 523 | 523 | ], |
| 524 | 524 | ]; |
| 525 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
| 525 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
| 526 | 526 | if ($result) { |
| 527 | 527 | $this->incrementRedirectHitCount($redirect); |
| 528 | 528 | $this->saveRedirectToCache($url, $redirect); |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | Craft::t( |
| 565 | 565 | 'retour', |
| 566 | 566 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
| 567 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
| 567 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
| 568 | 568 | ), |
| 569 | 569 | __METHOD__ |
| 570 | 570 | ); |
@@ -591,8 +591,8 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | if ($url !== null && $redirect !== null) { |
| 593 | 593 | // Save the modified redirect to the cache |
| 594 | - $redirect['redirectDestUrl'] = $event->redirectDestUrl; |
|
| 595 | - $redirect['redirectHttpCode'] = $event->redirectHttpCode; |
|
| 594 | + $redirect[ 'redirectDestUrl' ] = $event->redirectDestUrl; |
|
| 595 | + $redirect[ 'redirectHttpCode' ] = $event->redirectHttpCode; |
|
| 596 | 596 | $this->saveRedirectToCache($url, $redirect); |
| 597 | 597 | } |
| 598 | 598 | } |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
| 617 | 617 | /** @var Plugin $plugin */ |
| 618 | 618 | if (method_exists($plugin, 'retourMatch')) { |
| 619 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
| 619 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
@@ -637,12 +637,12 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | // Query the db table |
| 639 | 639 | $query = (new Query()) |
| 640 | - ->from(['{{%retour_static_redirects}}']) |
|
| 640 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 641 | 641 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
| 642 | 642 | if ($siteId) { |
| 643 | 643 | $query |
| 644 | - ->where(['siteId' => $siteId]) |
|
| 645 | - ->orWhere(['siteId' => null]); |
|
| 644 | + ->where([ 'siteId' => $siteId ]) |
|
| 645 | + ->orWhere([ 'siteId' => null ]); |
|
| 646 | 646 | } |
| 647 | 647 | if ($limit) { |
| 648 | 648 | $query->limit($limit); |
@@ -665,8 +665,8 @@ discard block |
||
| 665 | 665 | { |
| 666 | 666 | // Query the db table |
| 667 | 667 | $redirect = (new Query()) |
| 668 | - ->from(['{{%retour_static_redirects}}']) |
|
| 669 | - ->where(['id' => $id]) |
|
| 668 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 669 | + ->where([ 'id' => $id ]) |
|
| 670 | 670 | ->one(); |
| 671 | 671 | |
| 672 | 672 | return $redirect; |
@@ -684,16 +684,16 @@ discard block |
||
| 684 | 684 | { |
| 685 | 685 | // Query the db table |
| 686 | 686 | $query = (new Query()) |
| 687 | - ->from(['{{%retour_static_redirects}}']) |
|
| 688 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
| 687 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 688 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
| 689 | 689 | ; |
| 690 | 690 | if ($siteId) { |
| 691 | 691 | $query |
| 692 | - ->andWhere(['or', [ |
|
| 692 | + ->andWhere([ 'or', [ |
|
| 693 | 693 | 'siteId' => $siteId, |
| 694 | 694 | ], [ |
| 695 | 695 | 'siteId' => null, |
| 696 | - ]]); |
|
| 696 | + ] ]); |
|
| 697 | 697 | } |
| 698 | 698 | $redirect = $query->one(); |
| 699 | 699 | |
@@ -735,13 +735,13 @@ discard block |
||
| 735 | 735 | { |
| 736 | 736 | if ($redirectConfig !== null) { |
| 737 | 737 | $db = Craft::$app->getDb(); |
| 738 | - $redirectConfig['hitCount']++; |
|
| 739 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
| 738 | + $redirectConfig[ 'hitCount' ]++; |
|
| 739 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
| 740 | 740 | Craft::debug( |
| 741 | 741 | Craft::t( |
| 742 | 742 | 'retour', |
| 743 | 743 | 'Incrementing statistics for: {redirect}', |
| 744 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 744 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 745 | 745 | ), |
| 746 | 746 | __METHOD__ |
| 747 | 747 | ); |
@@ -750,14 +750,14 @@ discard block |
||
| 750 | 750 | $rowsAffected = $db->createCommand()->update( |
| 751 | 751 | '{{%retour_static_redirects}}', |
| 752 | 752 | [ |
| 753 | - 'hitCount' => $redirectConfig['hitCount'], |
|
| 754 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
| 753 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
| 754 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
| 755 | 755 | ], |
| 756 | 756 | [ |
| 757 | - 'id' => $redirectConfig['id'], |
|
| 757 | + 'id' => $redirectConfig[ 'id' ], |
|
| 758 | 758 | ] |
| 759 | 759 | )->execute(); |
| 760 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
| 760 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
| 761 | 761 | } catch (\Exception $e) { |
| 762 | 762 | Craft::error($e->getMessage(), __METHOD__); |
| 763 | 763 | } |
@@ -770,9 +770,9 @@ discard block |
||
| 770 | 770 | public function saveRedirect(array $redirectConfig) |
| 771 | 771 | { |
| 772 | 772 | // Handle URL encoded URLs by decoding them before saving them |
| 773 | - if (isset($redirectConfig['redirectMatchType']) && $redirectConfig['redirectMatchType'] === 'exactmatch') { |
|
| 774 | - $redirectConfig['redirectSrcUrl'] = urldecode($redirectConfig['redirectSrcUrl'] ?? ''); |
|
| 775 | - $redirectConfig['redirectSrcUrlParsed'] = urldecode($redirectConfig['redirectSrcUrlParsed'] ?? ''); |
|
| 773 | + if (isset($redirectConfig[ 'redirectMatchType' ]) && $redirectConfig[ 'redirectMatchType' ] === 'exactmatch') { |
|
| 774 | + $redirectConfig[ 'redirectSrcUrl' ] = urldecode($redirectConfig[ 'redirectSrcUrl' ] ?? ''); |
|
| 775 | + $redirectConfig[ 'redirectSrcUrlParsed' ] = urldecode($redirectConfig[ 'redirectSrcUrlParsed' ] ?? ''); |
|
| 776 | 776 | } |
| 777 | 777 | // Validate the model before saving it to the db |
| 778 | 778 | $redirect = new StaticRedirectsModel($redirectConfig); |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | Craft::t( |
| 782 | 782 | 'retour', |
| 783 | 783 | 'Error validating redirect {id}: {errors}', |
| 784 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
| 784 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
| 785 | 785 | ), |
| 786 | 786 | __METHOD__ |
| 787 | 787 | ); |
@@ -791,33 +791,33 @@ discard block |
||
| 791 | 791 | // Get the validated model attributes and save them to the db |
| 792 | 792 | $redirectConfig = $redirect->getAttributes(); |
| 793 | 793 | // 0 for a siteId needs to be converted to null |
| 794 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
| 795 | - $redirectConfig['siteId'] = null; |
|
| 794 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
| 795 | + $redirectConfig[ 'siteId' ] = null; |
|
| 796 | 796 | } |
| 797 | 797 | // Throw an event to before saving the redirect |
| 798 | 798 | $db = Craft::$app->getDb(); |
| 799 | 799 | // See if a redirect exists with this source URL already |
| 800 | - if ((int)$redirectConfig['id'] === 0) { |
|
| 800 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
| 801 | 801 | // Query the db table |
| 802 | 802 | $redirect = (new Query()) |
| 803 | - ->from(['{{%retour_static_redirects}}']) |
|
| 804 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
| 805 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
| 803 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 804 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
| 805 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
| 806 | 806 | ->one(); |
| 807 | 807 | // If it exists, update it rather than having duplicates |
| 808 | 808 | if (!empty($redirect)) { |
| 809 | - $redirectConfig['id'] = $redirect['id']; |
|
| 809 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | // Trigger a 'beforeSaveRedirect' event |
| 813 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
| 813 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
| 814 | 814 | $event = new RedirectEvent([ |
| 815 | 815 | 'isNew' => $isNew, |
| 816 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
| 817 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
| 818 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
| 819 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
| 820 | - 'siteId' => $redirectConfig['siteId'], |
|
| 816 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
| 817 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
| 818 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
| 819 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
| 820 | + 'siteId' => $redirectConfig[ 'siteId' ], |
|
| 821 | 821 | ]); |
| 822 | 822 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
| 823 | 823 | if (!$event->isValid) { |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | Craft::t( |
| 830 | 830 | 'retour', |
| 831 | 831 | 'Updating existing redirect: {redirect}', |
| 832 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 832 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 833 | 833 | ), |
| 834 | 834 | __METHOD__ |
| 835 | 835 | ); |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | '{{%retour_static_redirects}}', |
| 840 | 840 | $redirectConfig, |
| 841 | 841 | [ |
| 842 | - 'id' => $redirectConfig['id'], |
|
| 842 | + 'id' => $redirectConfig[ 'id' ], |
|
| 843 | 843 | ] |
| 844 | 844 | )->execute(); |
| 845 | 845 | } catch (Exception $e) { |
@@ -850,11 +850,11 @@ discard block |
||
| 850 | 850 | Craft::t( |
| 851 | 851 | 'retour', |
| 852 | 852 | 'Creating new redirect: {redirect}', |
| 853 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 853 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 854 | 854 | ), |
| 855 | 855 | __METHOD__ |
| 856 | 856 | ); |
| 857 | - unset($redirectConfig['id']); |
|
| 857 | + unset($redirectConfig[ 'id' ]); |
|
| 858 | 858 | // Create a new record |
| 859 | 859 | try { |
| 860 | 860 | $db->createCommand()->insert( |
@@ -867,15 +867,15 @@ discard block |
||
| 867 | 867 | } |
| 868 | 868 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
| 869 | 869 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
| 870 | - $redirectConfig['redirectDestUrl'], |
|
| 871 | - $redirectConfig['siteId'] |
|
| 870 | + $redirectConfig[ 'redirectDestUrl' ], |
|
| 871 | + $redirectConfig[ 'siteId' ] |
|
| 872 | 872 | ); |
| 873 | 873 | if ($testRedirectConfig !== null) { |
| 874 | 874 | Craft::debug( |
| 875 | 875 | Craft::t( |
| 876 | 876 | 'retour', |
| 877 | 877 | 'Deleting redirect to prevent a loop: {redirect}', |
| 878 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
| 878 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
| 879 | 879 | ), |
| 880 | 880 | __METHOD__ |
| 881 | 881 | ); |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | try { |
| 884 | 884 | $db->createCommand()->delete( |
| 885 | 885 | '{{%retour_static_redirects}}', |
| 886 | - ['id' => $testRedirectConfig['id']] |
|
| 886 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
| 887 | 887 | )->execute(); |
| 888 | 888 | } catch (Exception $e) { |
| 889 | 889 | Craft::error($e->getMessage(), __METHOD__); |
@@ -926,17 +926,17 @@ discard block |
||
| 926 | 926 | */ |
| 927 | 927 | public function excludeUri($uri): bool |
| 928 | 928 | { |
| 929 | - $uri = '/'.ltrim($uri, '/'); |
|
| 929 | + $uri = '/' . ltrim($uri, '/'); |
|
| 930 | 930 | if (!empty(Retour::$settings->excludePatterns)) { |
| 931 | 931 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
| 932 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
| 932 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
| 933 | 933 | try { |
| 934 | 934 | if (preg_match($pattern, $uri) === 1) { |
| 935 | 935 | return true; |
| 936 | 936 | } |
| 937 | 937 | } catch (\Exception $e) { |
| 938 | 938 | // That's fine |
| 939 | - Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__); |
|
| 939 | + Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__); |
|
| 940 | 940 | } |
| 941 | 941 | } |
| 942 | 942 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * @inheritdoc |
| 128 | 128 | */ |
| 129 | - public function __construct($id, $parent = null, array $config = []) |
|
| 129 | + public function __construct($id, $parent = null, array $config = [ ]) |
|
| 130 | 130 | { |
| 131 | - $config['components'] = [ |
|
| 131 | + $config[ 'components' ] = [ |
|
| 132 | 132 | 'events' => Events::class, |
| 133 | 133 | 'redirects' => Redirects::class, |
| 134 | 134 | 'statistics' => Statistics::class, |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | Craft::t( |
| 195 | 195 | 'retour', |
| 196 | 196 | '{name} plugin loaded', |
| 197 | - ['name' => $this->name] |
|
| 197 | + [ 'name' => $this->name ] |
|
| 198 | 198 | ), |
| 199 | 199 | __METHOD__ |
| 200 | 200 | ); |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function getCpNavItem() |
| 216 | 216 | { |
| 217 | - $subNavs = []; |
|
| 217 | + $subNavs = [ ]; |
|
| 218 | 218 | $navItem = parent::getCpNavItem(); |
| 219 | 219 | $currentUser = Craft::$app->getUser()->getIdentity(); |
| 220 | 220 | // Only show sub-navs the user has permission to view |
| 221 | 221 | if ($currentUser->can('retour:dashboard')) { |
| 222 | - $subNavs['dashboard'] = [ |
|
| 222 | + $subNavs[ 'dashboard' ] = [ |
|
| 223 | 223 | 'label' => 'Dashboard', |
| 224 | 224 | 'url' => 'retour/dashboard', |
| 225 | 225 | ]; |
| 226 | 226 | } |
| 227 | 227 | if ($currentUser->can('retour:redirects')) { |
| 228 | - $subNavs['redirects'] = [ |
|
| 228 | + $subNavs[ 'redirects' ] = [ |
|
| 229 | 229 | 'label' => 'Redirects', |
| 230 | 230 | 'url' => 'retour/redirects', |
| 231 | 231 | ]; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $editableSettings = false; |
| 237 | 237 | } |
| 238 | 238 | if ($currentUser->can('retour:settings') && $editableSettings) { |
| 239 | - $subNavs['settings'] = [ |
|
| 239 | + $subNavs[ 'settings' ] = [ |
|
| 240 | 240 | 'label' => 'Settings', |
| 241 | 241 | 'url' => 'retour/settings', |
| 242 | 242 | ]; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | // A single sub nav item is redundant |
| 249 | 249 | if (count($subNavs) === 1) { |
| 250 | - $subNavs = []; |
|
| 250 | + $subNavs = [ ]; |
|
| 251 | 251 | } |
| 252 | 252 | $navItem = array_merge($navItem, [ |
| 253 | 253 | 'subnav' => $subNavs, |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | Event::on( |
| 304 | 304 | ClearCaches::class, |
| 305 | 305 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
| 306 | - function (RegisterCacheOptionsEvent $event) { |
|
| 306 | + function(RegisterCacheOptionsEvent $event) { |
|
| 307 | 307 | Craft::debug( |
| 308 | 308 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
| 309 | 309 | __METHOD__ |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | Event::on( |
| 320 | 320 | Plugins::class, |
| 321 | 321 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
| 322 | - function (PluginEvent $event) { |
|
| 322 | + function(PluginEvent $event) { |
|
| 323 | 323 | if ($event->plugin === $this) { |
| 324 | 324 | // Invalidate our caches after we've been installed |
| 325 | 325 | $this->clearAllCaches(); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | Event::on( |
| 347 | 347 | CraftVariable::class, |
| 348 | 348 | CraftVariable::EVENT_INIT, |
| 349 | - function (Event $event) { |
|
| 349 | + function(Event $event) { |
|
| 350 | 350 | /** @var CraftVariable $variable */ |
| 351 | 351 | $variable = $event->sender; |
| 352 | 352 | $variable->set('retour', [ |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | Event::on( |
| 360 | 360 | Elements::class, |
| 361 | 361 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
| 362 | - function (ElementEvent $event) { |
|
| 362 | + function(ElementEvent $event) { |
|
| 363 | 363 | Craft::debug( |
| 364 | 364 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
| 365 | 365 | __METHOD__ |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | Event::on( |
| 391 | 391 | Elements::class, |
| 392 | 392 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
| 393 | - function (ElementEvent $event) { |
|
| 393 | + function(ElementEvent $event) { |
|
| 394 | 394 | Craft::debug( |
| 395 | 395 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
| 396 | 396 | __METHOD__ |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | Event::on( |
| 413 | 413 | Plugins::class, |
| 414 | 414 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
| 415 | - function () { |
|
| 415 | + function() { |
|
| 416 | 416 | // Install these only after all other plugins have loaded |
| 417 | 417 | $request = Craft::$app->getRequest(); |
| 418 | 418 | // Only respond to non-console site requests |
@@ -430,26 +430,26 @@ discard block |
||
| 430 | 430 | Event::on( |
| 431 | 431 | Gql::class, |
| 432 | 432 | Gql::EVENT_REGISTER_GQL_TYPES, |
| 433 | - function (RegisterGqlTypesEvent $event) { |
|
| 433 | + function(RegisterGqlTypesEvent $event) { |
|
| 434 | 434 | Craft::debug( |
| 435 | 435 | 'Gql::EVENT_REGISTER_GQL_TYPES', |
| 436 | 436 | __METHOD__ |
| 437 | 437 | ); |
| 438 | - $event->types[] = RetourInterface::class; |
|
| 438 | + $event->types[ ] = RetourInterface::class; |
|
| 439 | 439 | } |
| 440 | 440 | ); |
| 441 | 441 | // Handler: Gql::EVENT_REGISTER_GQL_QUERIES |
| 442 | 442 | Event::on( |
| 443 | 443 | Gql::class, |
| 444 | 444 | Gql::EVENT_REGISTER_GQL_QUERIES, |
| 445 | - function (RegisterGqlQueriesEvent $event) { |
|
| 445 | + function(RegisterGqlQueriesEvent $event) { |
|
| 446 | 446 | Craft::debug( |
| 447 | 447 | 'Gql::EVENT_REGISTER_GQL_QUERIES', |
| 448 | 448 | __METHOD__ |
| 449 | 449 | ); |
| 450 | 450 | $queries = RetourQuery::getQueries(); |
| 451 | 451 | foreach ($queries as $key => $value) { |
| 452 | - $event->queries[$key] = $value; |
|
| 452 | + $event->queries[ $key ] = $value; |
|
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | ); |
@@ -458,13 +458,13 @@ discard block |
||
| 458 | 458 | Event::on( |
| 459 | 459 | Gql::class, |
| 460 | 460 | Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS, |
| 461 | - function (RegisterGqlSchemaComponentsEvent $event) { |
|
| 461 | + function(RegisterGqlSchemaComponentsEvent $event) { |
|
| 462 | 462 | Craft::debug( |
| 463 | 463 | 'Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS', |
| 464 | 464 | __METHOD__ |
| 465 | 465 | ); |
| 466 | 466 | $label = Craft::t('retour', 'Retour'); |
| 467 | - $event->queries[$label]['retour.all:read'] = ['label' => Craft::t('retour', 'Query Retour data')]; |
|
| 467 | + $event->queries[ $label ][ 'retour.all:read' ] = [ 'label' => Craft::t('retour', 'Query Retour data') ]; |
|
| 468 | 468 | } |
| 469 | 469 | ); |
| 470 | 470 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | Event::on( |
| 475 | 475 | Schema::class, |
| 476 | 476 | AlterSchemaFields::EVENT, |
| 477 | - [GetCraftQLSchema::class, 'handle'] |
|
| 477 | + [ GetCraftQLSchema::class, 'handle' ] |
|
| 478 | 478 | ); |
| 479 | 479 | } |
| 480 | 480 | } |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | Event::on( |
| 489 | 489 | UrlManager::class, |
| 490 | 490 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
| 491 | - function (RegisterUrlRulesEvent $event) { |
|
| 491 | + function(RegisterUrlRulesEvent $event) { |
|
| 492 | 492 | Craft::debug( |
| 493 | 493 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
| 494 | 494 | __METHOD__ |
@@ -511,15 +511,15 @@ discard block |
||
| 511 | 511 | Event::on( |
| 512 | 512 | Dashboard::class, |
| 513 | 513 | Dashboard::EVENT_REGISTER_WIDGET_TYPES, |
| 514 | - function (RegisterComponentTypesEvent $event) { |
|
| 515 | - $event->types[] = RetourWidget::class; |
|
| 514 | + function(RegisterComponentTypesEvent $event) { |
|
| 515 | + $event->types[ ] = RetourWidget::class; |
|
| 516 | 516 | } |
| 517 | 517 | ); |
| 518 | 518 | // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES |
| 519 | 519 | Event::on( |
| 520 | 520 | UrlManager::class, |
| 521 | 521 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
| 522 | - function (RegisterUrlRulesEvent $event) { |
|
| 522 | + function(RegisterUrlRulesEvent $event) { |
|
| 523 | 523 | Craft::debug( |
| 524 | 524 | 'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
| 525 | 525 | __METHOD__ |
@@ -535,13 +535,13 @@ discard block |
||
| 535 | 535 | Event::on( |
| 536 | 536 | UserPermissions::class, |
| 537 | 537 | UserPermissions::EVENT_REGISTER_PERMISSIONS, |
| 538 | - function (RegisterUserPermissionsEvent $event) { |
|
| 538 | + function(RegisterUserPermissionsEvent $event) { |
|
| 539 | 539 | Craft::debug( |
| 540 | 540 | 'UserPermissions::EVENT_REGISTER_PERMISSIONS', |
| 541 | 541 | __METHOD__ |
| 542 | 542 | ); |
| 543 | 543 | // Register our custom permissions |
| 544 | - $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions(); |
|
| 544 | + $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions(); |
|
| 545 | 545 | } |
| 546 | 546 | ); |
| 547 | 547 | } |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | Event::on( |
| 558 | 558 | ErrorHandler::class, |
| 559 | 559 | ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION, |
| 560 | - function (ExceptionEvent $event) { |
|
| 560 | + function(ExceptionEvent $event) { |
|
| 561 | 561 | Craft::debug( |
| 562 | 562 | 'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION', |
| 563 | 563 | __METHOD__ |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | [ |
| 642 | 642 | 'key' => 'retour-redirect-caches', |
| 643 | 643 | 'label' => Craft::t('retour', 'Retour redirect caches'), |
| 644 | - 'action' => [self::$plugin->redirects, 'invalidateCaches'], |
|
| 644 | + 'action' => [ self::$plugin->redirects, 'invalidateCaches' ], |
|
| 645 | 645 | ], |
| 646 | 646 | ]; |
| 647 | 647 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @var array The URIs for the element before it was saved |
| 59 | 59 | */ |
| 60 | - public $oldElementUris = []; |
|
| 60 | + public $oldElementUris = [ ]; |
|
| 61 | 61 | |
| 62 | 62 | // Public Methods |
| 63 | 63 | // ========================================================================= |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | // Stash the old URLs by element id, and do so only once, |
| 71 | 71 | // in case we are called more than once per request |
| 72 | - if (empty($this->oldElementUris[$element->id])) { |
|
| 73 | - $this->oldElementUris[$element->id] = $this->getAllElementUris($element); |
|
| 72 | + if (empty($this->oldElementUris[ $element->id ])) { |
|
| 73 | + $this->oldElementUris[ $element->id ] = $this->getAllElementUris($element); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | public function handleElementUriChange(Element $element) |
| 81 | 81 | { |
| 82 | 82 | $uris = $this->getAllElementUris($element); |
| 83 | - if (!empty($this->oldElementUris[$element->id])) { |
|
| 84 | - $oldElementUris = $this->oldElementUris[$element->id]; |
|
| 83 | + if (!empty($this->oldElementUris[ $element->id ])) { |
|
| 84 | + $oldElementUris = $this->oldElementUris[ $element->id ]; |
|
| 85 | 85 | foreach ($uris as $siteId => $newUri) { |
| 86 | - if (!empty($oldElementUris[$siteId])) { |
|
| 87 | - $oldUri = $oldElementUris[$siteId]; |
|
| 86 | + if (!empty($oldElementUris[ $siteId ])) { |
|
| 87 | + $oldUri = $oldElementUris[ $siteId ]; |
|
| 88 | 88 | Craft::debug( |
| 89 | 89 | Craft::t( |
| 90 | 90 | 'retour', |
| 91 | 91 | 'Comparing old: {oldUri} to new: {newUri}', |
| 92 | - ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)] |
|
| 92 | + [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ] |
|
| 93 | 93 | ), |
| 94 | 94 | __METHOD__ |
| 95 | 95 | ); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if (Retour::$settings->uriChangeRedirectSrcMatch === 'fullurl') { |
| 110 | 110 | try { |
| 111 | 111 | if ($redirectSiteId !== null) { |
| 112 | - $redirectSiteId = (int)$redirectSiteId; |
|
| 112 | + $redirectSiteId = (int) $redirectSiteId; |
|
| 113 | 113 | } |
| 114 | 114 | $oldUri = \craft\helpers\UrlHelper::siteUrl($oldUri, null, null, $redirectSiteId); |
| 115 | 115 | $newUri = UrlHelper::siteUrl($newUri, null, null, $redirectSiteId); |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | 'siteId' => $redirectSiteId, |
| 128 | 128 | ]; |
| 129 | 129 | // Trigger a 'beforeSaveEntryRedirect' event |
| 130 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
| 130 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
| 131 | 131 | $event = new RedirectEvent([ |
| 132 | 132 | 'isNew' => $isNew, |
| 133 | - 'legacyUrl' => $redirectConfig['redirectSrcUrl'], |
|
| 134 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
| 135 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
| 136 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
| 137 | - 'siteId' => $redirectConfig['siteId'], |
|
| 133 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrl' ], |
|
| 134 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
| 135 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
| 136 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
| 137 | + 'siteId' => $redirectConfig[ 'siteId' ], |
|
| 138 | 138 | ]); |
| 139 | 139 | $this->trigger(self::EVENT_BEFORE_SAVE_ENTRY_REDIRECT, $event); |
| 140 | 140 | if (!$event->isValid) { |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function getAllElementUris(Element $element): array |
| 158 | 158 | { |
| 159 | - $uris = []; |
|
| 159 | + $uris = [ ]; |
|
| 160 | 160 | if (!Retour::$craft32 || !ElementHelper::isDraftOrRevision($element)) { |
| 161 | 161 | $sites = Craft::$app->getSites()->getAllSites(); |
| 162 | 162 | foreach ($sites as $site) { |
| 163 | 163 | $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id); |
| 164 | 164 | if ($uri !== null) { |
| 165 | - $uris[$site->id] = $uri; |
|
| 165 | + $uris[ $site->id ] = $uri; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | Craft::t( |
| 172 | 172 | 'retour', |
| 173 | 173 | 'Getting Element URIs: {uris}', |
| 174 | - ['uris' => print_r($uris, true)] |
|
| 174 | + [ 'uris' => print_r($uris, true) ] |
|
| 175 | 175 | ), |
| 176 | 176 | __METHOD__ |
| 177 | 177 | ); |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | $siteId = $source->siteId; |
| 41 | 41 | } else { |
| 42 | 42 | // Otherwise use the passed in arguments, or defaults |
| 43 | - $uri = $arguments['uri'] ?? '/'; |
|
| 44 | - $siteId = $arguments['siteId'] ?? null; |
|
| 43 | + $uri = $arguments[ 'uri' ] ?? '/'; |
|
| 44 | + $siteId = $arguments[ 'siteId' ] ?? null; |
|
| 45 | 45 | } |
| 46 | 46 | $uri = trim($uri === '/' ? '__home__' : $uri); |
| 47 | 47 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public static function resolveAll($source, array $arguments, $context, ResolveInfo $resolveInfo) |
| 78 | 78 | { |
| 79 | - $siteId = $arguments['siteId'] ?? Craft::$app->getSites()->getCurrentSite()->id; |
|
| 79 | + $siteId = $arguments[ 'siteId' ] ?? Craft::$app->getSites()->getCurrentSite()->id; |
|
| 80 | 80 | |
| 81 | 81 | $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId); |
| 82 | 82 | |
@@ -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,34 +71,34 @@ 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/web/assets/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; |
|
| 101 | - $variables['settings'] = Retour::$settings; |
|
| 98 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
| 99 | + $variables[ 'selectedSubnavItem' ] = 'dashboard'; |
|
| 100 | + $variables[ 'showWelcome' ] = $showWelcome; |
|
| 101 | + $variables[ 'settings' ] = Retour::$settings; |
|
| 102 | 102 | |
| 103 | 103 | // Render the template |
| 104 | 104 | return $this->renderTemplate('retour/dashboard/index', $variables); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | Craft::t( |
| 117 | 117 | 'retour', |
| 118 | 118 | 'Retour statistics cleared: {error}', |
| 119 | - ['error' => $error] |
|
| 119 | + [ 'error' => $error ] |
|
| 120 | 120 | ), |
| 121 | 121 | __METHOD__ |
| 122 | 122 | ); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | Craft::t( |
| 152 | 152 | 'retour', |
| 153 | 153 | 'Retour statistics deleted: {error}', |
| 154 | - ['error' => $stickyError] |
|
| 154 | + [ 'error' => $stickyError ] |
|
| 155 | 155 | ), |
| 156 | 156 | __METHOD__ |
| 157 | 157 | ); |