@@ -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 | ); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $response = Craft::$app->getResponse(); |
| 163 | 163 | if ($redirect !== null) { |
| 164 | 164 | // Figure out what type of source matching was done |
| 165 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
| 165 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
| 166 | 166 | switch ($redirectSrcMatch) { |
| 167 | 167 | case 'pathonly': |
| 168 | 168 | $url = $pathOnly; |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | $url = $pathOnly; |
| 175 | 175 | break; |
| 176 | 176 | } |
| 177 | - $dest = $redirect['redirectDestUrl']; |
|
| 177 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
| 178 | 178 | // If this isn't a full URL, make it one based on the appropriate site |
| 179 | 179 | if (!UrlHelper::isFullUrl($dest)) { |
| 180 | 180 | try { |
| 181 | - $dest = UrlHelper::siteUrl($dest, null, null, $redirect['siteId'] ?? null); |
|
| 181 | + $dest = UrlHelper::siteUrl($dest, null, null, $redirect[ 'siteId' ] ?? null); |
|
| 182 | 182 | } catch (\yii\base\Exception $e) { |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | - $status = $redirect['redirectHttpCode']; |
|
| 191 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
| 192 | 192 | Craft::info( |
| 193 | 193 | Craft::t( |
| 194 | 194 | 'retour', |
| 195 | 195 | 'Redirecting {url} to {dest} with status {status}', |
| 196 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
| 196 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
| 197 | 197 | ), |
| 198 | 198 | __METHOD__ |
| 199 | 199 | ); |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | public function getRedirectFromCache($url, int $siteId = 0) |
| 274 | 274 | { |
| 275 | 275 | $cache = Craft::$app->getCache(); |
| 276 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 276 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 277 | 277 | $redirect = $cache->get($cacheKey); |
| 278 | 278 | Craft::info( |
| 279 | 279 | Craft::t( |
| 280 | 280 | 'retour', |
| 281 | 281 | 'Cached redirect hit for {url}', |
| 282 | - ['url' => $url] |
|
| 282 | + [ 'url' => $url ] |
|
| 283 | 283 | ), |
| 284 | 284 | __METHOD__ |
| 285 | 285 | ); |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | } catch (SiteNotFoundException $e) { |
| 302 | 302 | $siteId = 1; |
| 303 | 303 | } |
| 304 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 304 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 305 | 305 | // Create the dependency tags |
| 306 | 306 | $dependency = new TagDependency([ |
| 307 | 307 | 'tags' => [ |
| 308 | 308 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
| 309 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
| 309 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
| 310 | 310 | ], |
| 311 | 311 | ]); |
| 312 | 312 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | Craft::t( |
| 315 | 315 | 'retour', |
| 316 | 316 | 'Cached redirect saved for {url}', |
| 317 | - ['url' => $url] |
|
| 317 | + [ 'url' => $url ] |
|
| 318 | 318 | ), |
| 319 | 319 | __METHOD__ |
| 320 | 320 | ); |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | $result = null; |
| 333 | 333 | foreach ($redirects as $redirect) { |
| 334 | 334 | // Figure out what type of source matching to do |
| 335 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
| 336 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
| 335 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
| 336 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
| 337 | 337 | if ($redirectEnabled === true) { |
| 338 | 338 | switch ($redirectSrcMatch) { |
| 339 | 339 | case 'pathonly': |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | $url = $pathOnly; |
| 347 | 347 | break; |
| 348 | 348 | } |
| 349 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
| 349 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
| 350 | 350 | switch ($redirectMatchType) { |
| 351 | 351 | // Do a straight up match |
| 352 | 352 | case 'exactmatch': |
| 353 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
| 353 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
| 354 | 354 | $this->incrementRedirectHitCount($redirect); |
| 355 | 355 | $this->saveRedirectToCache($url, $redirect); |
| 356 | 356 | |
@@ -360,14 +360,14 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | // Do a regex match |
| 362 | 362 | case 'regexmatch': |
| 363 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
| 363 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
| 364 | 364 | if (preg_match($matchRegEx, $url) === 1) { |
| 365 | 365 | $this->incrementRedirectHitCount($redirect); |
| 366 | 366 | // If we're not associated with an EntryID, handle capture group replacement |
| 367 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
| 368 | - $redirect['redirectDestUrl'] = preg_replace( |
|
| 367 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
| 368 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
| 369 | 369 | $matchRegEx, |
| 370 | - $redirect['redirectDestUrl'], |
|
| 370 | + $redirect[ 'redirectDestUrl' ], |
|
| 371 | 371 | $url |
| 372 | 372 | ); |
| 373 | 373 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | 'redirect' => &$redirect, |
| 387 | 387 | ], |
| 388 | 388 | ]; |
| 389 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
| 389 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
| 390 | 390 | if ($result) { |
| 391 | 391 | $this->incrementRedirectHitCount($redirect); |
| 392 | 392 | $this->saveRedirectToCache($url, $redirect); |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | Craft::t( |
| 403 | 403 | 'retour', |
| 404 | 404 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
| 405 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
| 405 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
| 406 | 406 | ), |
| 407 | 407 | __METHOD__ |
| 408 | 408 | ); |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
| 427 | 427 | /** @var Plugin $plugin */ |
| 428 | 428 | if (method_exists($plugin, 'retourMatch')) { |
| 429 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
| 429 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | |
@@ -447,12 +447,12 @@ discard block |
||
| 447 | 447 | } |
| 448 | 448 | // Query the db table |
| 449 | 449 | $query = (new Query()) |
| 450 | - ->from(['{{%retour_static_redirects}}']) |
|
| 450 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 451 | 451 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
| 452 | 452 | if ($siteId) { |
| 453 | 453 | $query |
| 454 | - ->where(['siteId' => $siteId]) |
|
| 455 | - ->orWhere(['siteId' => null]); |
|
| 454 | + ->where([ 'siteId' => $siteId ]) |
|
| 455 | + ->orWhere([ 'siteId' => null ]); |
|
| 456 | 456 | } |
| 457 | 457 | if ($limit) { |
| 458 | 458 | $query->limit($limit); |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | { |
| 476 | 476 | // Query the db table |
| 477 | 477 | $redirect = (new Query()) |
| 478 | - ->from(['{{%retour_static_redirects}}']) |
|
| 479 | - ->where(['id' => $id]) |
|
| 478 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 479 | + ->where([ 'id' => $id ]) |
|
| 480 | 480 | ->one(); |
| 481 | 481 | |
| 482 | 482 | return $redirect; |
@@ -494,16 +494,16 @@ discard block |
||
| 494 | 494 | { |
| 495 | 495 | // Query the db table |
| 496 | 496 | $query = (new Query()) |
| 497 | - ->from(['{{%retour_static_redirects}}']) |
|
| 498 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
| 497 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 498 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
| 499 | 499 | ; |
| 500 | 500 | if ($siteId) { |
| 501 | 501 | $query |
| 502 | - ->andWhere(['or', [ |
|
| 502 | + ->andWhere([ 'or', [ |
|
| 503 | 503 | 'siteId' => $siteId, |
| 504 | 504 | ], [ |
| 505 | 505 | 'siteId' => null, |
| 506 | - ]]); |
|
| 506 | + ] ]); |
|
| 507 | 507 | } |
| 508 | 508 | $redirect = $query->one(); |
| 509 | 509 | |
@@ -545,13 +545,13 @@ discard block |
||
| 545 | 545 | { |
| 546 | 546 | if ($redirectConfig !== null) { |
| 547 | 547 | $db = Craft::$app->getDb(); |
| 548 | - $redirectConfig['hitCount']++; |
|
| 549 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
| 548 | + $redirectConfig[ 'hitCount' ]++; |
|
| 549 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
| 550 | 550 | Craft::debug( |
| 551 | 551 | Craft::t( |
| 552 | 552 | 'retour', |
| 553 | 553 | 'Incrementing statistics for: {redirect}', |
| 554 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 554 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 555 | 555 | ), |
| 556 | 556 | __METHOD__ |
| 557 | 557 | ); |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | $rowsAffected = $db->createCommand()->update( |
| 561 | 561 | '{{%retour_static_redirects}}', |
| 562 | 562 | [ |
| 563 | - 'hitCount' => $redirectConfig['hitCount'], |
|
| 564 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
| 563 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
| 564 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
| 565 | 565 | ], |
| 566 | 566 | [ |
| 567 | - 'id' => $redirectConfig['id'], |
|
| 567 | + 'id' => $redirectConfig[ 'id' ], |
|
| 568 | 568 | ] |
| 569 | 569 | )->execute(); |
| 570 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
| 570 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
| 571 | 571 | } catch (Exception $e) { |
| 572 | 572 | Craft::error($e->getMessage(), __METHOD__); |
| 573 | 573 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | Craft::t( |
| 587 | 587 | 'retour', |
| 588 | 588 | 'Error validating redirect {id}: {errors}', |
| 589 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
| 589 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
| 590 | 590 | ), |
| 591 | 591 | __METHOD__ |
| 592 | 592 | ); |
@@ -596,32 +596,32 @@ discard block |
||
| 596 | 596 | // Get the validated model attributes and save them to the db |
| 597 | 597 | $redirectConfig = $redirect->getAttributes(); |
| 598 | 598 | // 0 for a siteId needs to be converted to null |
| 599 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
| 600 | - $redirectConfig['siteId'] = null; |
|
| 599 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
| 600 | + $redirectConfig[ 'siteId' ] = null; |
|
| 601 | 601 | } |
| 602 | 602 | // Throw an event to before saving the redirect |
| 603 | 603 | $db = Craft::$app->getDb(); |
| 604 | 604 | // See if a redirect exists with this source URL already |
| 605 | - if ((int)$redirectConfig['id'] === 0) { |
|
| 605 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
| 606 | 606 | // Query the db table |
| 607 | 607 | $redirect = (new Query()) |
| 608 | - ->from(['{{%retour_static_redirects}}']) |
|
| 609 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
| 610 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
| 608 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 609 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
| 610 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
| 611 | 611 | ->one(); |
| 612 | 612 | // If it exists, update it rather than having duplicates |
| 613 | 613 | if (!empty($redirect)) { |
| 614 | - $redirectConfig['id'] = $redirect['id']; |
|
| 614 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | // Trigger a 'beforeSaveRedirect' event |
| 618 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
| 618 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
| 619 | 619 | $event = new RedirectEvent([ |
| 620 | 620 | 'isNew' => $isNew, |
| 621 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
| 622 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
| 623 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
| 624 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
| 621 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
| 622 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
| 623 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
| 624 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
| 625 | 625 | ]); |
| 626 | 626 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
| 627 | 627 | if (!$event->isValid) { |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | Craft::t( |
| 634 | 634 | 'retour', |
| 635 | 635 | 'Updating existing redirect: {redirect}', |
| 636 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 636 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 637 | 637 | ), |
| 638 | 638 | __METHOD__ |
| 639 | 639 | ); |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | '{{%retour_static_redirects}}', |
| 644 | 644 | $redirectConfig, |
| 645 | 645 | [ |
| 646 | - 'id' => $redirectConfig['id'], |
|
| 646 | + 'id' => $redirectConfig[ 'id' ], |
|
| 647 | 647 | ] |
| 648 | 648 | )->execute(); |
| 649 | 649 | } catch (Exception $e) { |
@@ -654,11 +654,11 @@ discard block |
||
| 654 | 654 | Craft::t( |
| 655 | 655 | 'retour', |
| 656 | 656 | 'Creating new redirect: {redirect}', |
| 657 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 657 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 658 | 658 | ), |
| 659 | 659 | __METHOD__ |
| 660 | 660 | ); |
| 661 | - unset($redirectConfig['id']); |
|
| 661 | + unset($redirectConfig[ 'id' ]); |
|
| 662 | 662 | // Create a new record |
| 663 | 663 | try { |
| 664 | 664 | $db->createCommand()->insert( |
@@ -671,15 +671,15 @@ discard block |
||
| 671 | 671 | } |
| 672 | 672 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
| 673 | 673 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
| 674 | - $redirectConfig['redirectDestUrl'], |
|
| 675 | - $redirectConfig['siteId'] |
|
| 674 | + $redirectConfig[ 'redirectDestUrl' ], |
|
| 675 | + $redirectConfig[ 'siteId' ] |
|
| 676 | 676 | ); |
| 677 | 677 | if ($testRedirectConfig !== null) { |
| 678 | 678 | Craft::debug( |
| 679 | 679 | Craft::t( |
| 680 | 680 | 'retour', |
| 681 | 681 | 'Deleting redirect to prevent a loop: {redirect}', |
| 682 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
| 682 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
| 683 | 683 | ), |
| 684 | 684 | __METHOD__ |
| 685 | 685 | ); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | try { |
| 688 | 688 | $db->createCommand()->delete( |
| 689 | 689 | '{{%retour_static_redirects}}', |
| 690 | - ['id' => $testRedirectConfig['id']] |
|
| 690 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
| 691 | 691 | )->execute(); |
| 692 | 692 | } catch (Exception $e) { |
| 693 | 693 | Craft::error($e->getMessage(), __METHOD__); |
@@ -720,10 +720,10 @@ discard block |
||
| 720 | 720 | */ |
| 721 | 721 | public function excludeUri($uri): bool |
| 722 | 722 | { |
| 723 | - $uri = '/'.ltrim($uri, '/'); |
|
| 723 | + $uri = '/' . ltrim($uri, '/'); |
|
| 724 | 724 | if (!empty(Retour::$settings->excludePatterns)) { |
| 725 | 725 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
| 726 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
| 726 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
| 727 | 727 | if (preg_match($pattern, $uri) === 1) { |
| 728 | 728 | return true; |
| 729 | 729 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | // The number of milliseconds required between trimming of statistics |
| 52 | 52 | 'statisticsRateLimitMs' => 3600000, |
| 53 | 53 | |
| 54 | - // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
| 54 | + // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
| 55 | 55 | 'excludePatterns' => [ |
| 56 | 56 | ], |
| 57 | 57 | ]; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | // Query the db table |
| 62 | 62 | $stats = (new Query()) |
| 63 | - ->from(['{{%retour_stats}}']) |
|
| 63 | + ->from([ '{{%retour_stats}}' ]) |
|
| 64 | 64 | ->orderBy('hitCount DESC') |
| 65 | 65 | ->limit(Retour::$settings->statsDisplayLimit) |
| 66 | 66 | ->all(); |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | public function getRecentStatistics($days = 1, $handled = false): array |
| 80 | 80 | { |
| 81 | 81 | // Ensure is an int |
| 82 | - $handledInt = (int)$handled; |
|
| 83 | - $stats = []; |
|
| 82 | + $handledInt = (int) $handled; |
|
| 83 | + $stats = [ ]; |
|
| 84 | 84 | $db = Craft::$app->getDb(); |
| 85 | 85 | if ($db->getIsMysql()) { |
| 86 | 86 | // Query the db table |
| 87 | 87 | $stats = (new Query()) |
| 88 | - ->from(['{{%retour_stats}}']) |
|
| 88 | + ->from([ '{{%retour_stats}}' ]) |
|
| 89 | 89 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )") |
| 90 | 90 | ->andWhere("handledByRetour = {$handledInt}") |
| 91 | 91 | ->orderBy('hitLastTime DESC') |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | if ($db->getIsPgsql()) { |
| 95 | 95 | // Query the db table |
| 96 | 96 | $stats = (new Query()) |
| 97 | - ->from(['{{%retour_stats}}']) |
|
| 97 | + ->from([ '{{%retour_stats}}' ]) |
|
| 98 | 98 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )") |
| 99 | - ->andWhere(['handledByRetour' => $handledInt]) |
|
| 99 | + ->andWhere([ 'handledByRetour' => $handledInt ]) |
|
| 100 | 100 | ->orderBy('hitLastTime DESC') |
| 101 | 101 | ->all(); |
| 102 | 102 | } |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | $stats->validate(); |
| 164 | 164 | // Find any existing retour_stats record |
| 165 | 165 | $statsConfig = (new Query()) |
| 166 | - ->from(['{{%retour_stats}}']) |
|
| 167 | - ->where(['redirectSrcUrl' => $stats->redirectSrcUrl]) |
|
| 166 | + ->from([ '{{%retour_stats}}' ]) |
|
| 167 | + ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ]) |
|
| 168 | 168 | ->one(); |
| 169 | 169 | // If no record is found, initialize some values |
| 170 | 170 | if ($statsConfig === null) { |
| 171 | 171 | $stats->id = 0; |
| 172 | 172 | $stats->hitCount = 0; |
| 173 | 173 | } else { |
| 174 | - $stats->id = $statsConfig['id']; |
|
| 175 | - $stats->hitCount = $statsConfig['hitCount']; |
|
| 174 | + $stats->id = $statsConfig[ 'id' ]; |
|
| 175 | + $stats->hitCount = $statsConfig[ 'hitCount' ]; |
|
| 176 | 176 | } |
| 177 | 177 | // Merge in the updated info |
| 178 | 178 | $stats->siteId = $siteId; |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | $stats->userAgent = $userAgent; |
| 182 | 182 | $stats->exceptionMessage = $exceptionMessage; |
| 183 | 183 | $stats->exceptionFilePath = $exceptionFilePath; |
| 184 | - $stats->exceptionFileLine = (int)$exceptionFileLine; |
|
| 184 | + $stats->exceptionFileLine = (int) $exceptionFileLine; |
|
| 185 | 185 | $stats->hitLastTime = Db::prepareDateForDb(new \DateTime()); |
| 186 | - $stats->handledByRetour = (int)$handled; |
|
| 186 | + $stats->handledByRetour = (int) $handled; |
|
| 187 | 187 | $stats->hitCount++; |
| 188 | 188 | $statsConfig = $stats->getAttributes(); |
| 189 | 189 | // Record the updated statistics |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | Craft::t( |
| 254 | 254 | 'retour', |
| 255 | 255 | 'Trimmed {rows} from retour_stats table', |
| 256 | - ['rows' => $affectedRows] |
|
| 256 | + [ 'rows' => $affectedRows ] |
|
| 257 | 257 | ), |
| 258 | 258 | __METHOD__ |
| 259 | 259 | ); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | Craft::t( |
| 275 | 275 | 'retour', |
| 276 | 276 | 'Error validating statistics {id}: {errors}', |
| 277 | - ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)] |
|
| 277 | + [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ] |
|
| 278 | 278 | ), |
| 279 | 279 | __METHOD__ |
| 280 | 280 | ); |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | // Get the validated model attributes and save them to the db |
| 285 | 285 | $statsConfig = $stats->getAttributes(); |
| 286 | 286 | $db = Craft::$app->getDb(); |
| 287 | - if ($statsConfig['id'] !== 0) { |
|
| 287 | + if ($statsConfig[ 'id' ] !== 0) { |
|
| 288 | 288 | // Update the existing record |
| 289 | 289 | try { |
| 290 | 290 | $result = $db->createCommand()->update( |
| 291 | 291 | '{{%retour_stats}}', |
| 292 | 292 | $statsConfig, |
| 293 | 293 | [ |
| 294 | - 'id' => $statsConfig['id'], |
|
| 294 | + 'id' => $statsConfig[ 'id' ], |
|
| 295 | 295 | ] |
| 296 | 296 | )->execute(); |
| 297 | 297 | } catch (Exception $e) { |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | // Craft::error($e->getMessage(), __METHOD__); |
| 301 | 301 | } |
| 302 | 302 | } else { |
| 303 | - unset($statsConfig['id']); |
|
| 303 | + unset($statsConfig[ 'id' ]); |
|
| 304 | 304 | // Create a new record |
| 305 | 305 | try { |
| 306 | 306 | $db->createCommand()->insert( |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $now = round(microtime(true) * 1000); |
| 328 | 328 | $cache = Craft::$app->getCache(); |
| 329 | 329 | $then = $cache->get(self::LAST_STATISTICS_TRIM_CACHE_KEY); |
| 330 | - if (($then !== false) && ($now - (int)$then < Retour::$settings->statisticsRateLimitMs)) { |
|
| 330 | + if (($then !== false) && ($now - (int) $then < Retour::$settings->statisticsRateLimitMs)) { |
|
| 331 | 331 | $limited = true; |
| 332 | 332 | } |
| 333 | 333 | $cache->set(self::LAST_STATISTICS_TRIM_CACHE_KEY, $now, 0); |
@@ -62,36 +62,36 @@ discard block |
||
| 62 | 62 | // Boolean field |
| 63 | 63 | $retourField |
| 64 | 64 | ->addBooleanField($field) |
| 65 | - ->resolve(function ($redirect) use ($field) { |
|
| 66 | - $result = $redirect[$field] ?? null; |
|
| 67 | - return $result === null ? $result : (bool)$result; |
|
| 65 | + ->resolve(function($redirect) use ($field) { |
|
| 66 | + $result = $redirect[ $field ] ?? null; |
|
| 67 | + return $result === null ? $result : (bool) $result; |
|
| 68 | 68 | }); |
| 69 | 69 | } elseif (in_array($field, self::INT_FIELDS, true)) { |
| 70 | 70 | // Integer field |
| 71 | 71 | $retourField |
| 72 | 72 | ->addIntField($field) |
| 73 | - ->resolve(function ($redirect) use ($field) { |
|
| 74 | - $result = $redirect[$field] ?? null; |
|
| 75 | - return $result === null ? $result : (int)$result; |
|
| 73 | + ->resolve(function($redirect) use ($field) { |
|
| 74 | + $result = $redirect[ $field ] ?? null; |
|
| 75 | + return $result === null ? $result : (int) $result; |
|
| 76 | 76 | }); |
| 77 | 77 | } else { |
| 78 | 78 | // String field |
| 79 | 79 | $retourField |
| 80 | 80 | ->addStringField($field) |
| 81 | - ->resolve(function ($redirect) use ($field) { |
|
| 82 | - $result = $redirect[$field] ?? null; |
|
| 83 | - return $result === null ? $result : (string)$result; |
|
| 81 | + ->resolve(function($redirect) use ($field) { |
|
| 82 | + $result = $redirect[ $field ] ?? null; |
|
| 83 | + return $result === null ? $result : (string) $result; |
|
| 84 | 84 | }); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | // Add the root |
| 88 | 88 | $event->schema->addField('retour') |
| 89 | - ->arguments(function (FieldBuilder $field) { |
|
| 89 | + ->arguments(function(FieldBuilder $field) { |
|
| 90 | 90 | $field->addStringArgument('uri'); |
| 91 | 91 | $field->addIntArgument('siteId'); |
| 92 | 92 | }) |
| 93 | 93 | ->type($retourField) |
| 94 | - ->resolve(function ($root, $args, $context, $info) { |
|
| 94 | + ->resolve(function($root, $args, $context, $info) { |
|
| 95 | 95 | // If our root is an Element, extract the URI and siteId from it |
| 96 | 96 | if ($root instanceof Element) { |
| 97 | 97 | /** Element $root */ |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | $siteId = $root->siteId; |
| 100 | 100 | } else { |
| 101 | 101 | // Otherwise use the passed in arguments, or defaults |
| 102 | - $uri = $args['uri'] ?? '/'; |
|
| 103 | - $siteId = $args['siteId'] ?? null; |
|
| 102 | + $uri = $args[ 'uri' ] ?? '/'; |
|
| 103 | + $siteId = $args[ 'siteId' ] ?? null; |
|
| 104 | 104 | } |
| 105 | 105 | $uri = trim($uri === '/' ? '__home__' : $uri); |
| 106 | 106 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * @var array The URIs for the element before it was saved |
| 106 | 106 | */ |
| 107 | - public $oldElementUris = []; |
|
| 107 | + public $oldElementUris = [ ]; |
|
| 108 | 108 | |
| 109 | 109 | // Public Methods |
| 110 | 110 | // ========================================================================= |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | Craft::t( |
| 136 | 136 | 'retour', |
| 137 | 137 | '{name} plugin loaded', |
| 138 | - ['name' => $this->name] |
|
| 138 | + [ 'name' => $this->name ] |
|
| 139 | 139 | ), |
| 140 | 140 | __METHOD__ |
| 141 | 141 | ); |
@@ -155,18 +155,18 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function getCpNavItem() |
| 157 | 157 | { |
| 158 | - $subNavs = []; |
|
| 158 | + $subNavs = [ ]; |
|
| 159 | 159 | $navItem = parent::getCpNavItem(); |
| 160 | 160 | $currentUser = Craft::$app->getUser()->getIdentity(); |
| 161 | 161 | // Only show sub-navs the user has permission to view |
| 162 | 162 | if ($currentUser->can('retour:dashboard')) { |
| 163 | - $subNavs['dashboard'] = [ |
|
| 163 | + $subNavs[ 'dashboard' ] = [ |
|
| 164 | 164 | 'label' => 'Dashboard', |
| 165 | 165 | 'url' => 'retour/dashboard', |
| 166 | 166 | ]; |
| 167 | 167 | } |
| 168 | 168 | if ($currentUser->can('retour:redirects')) { |
| 169 | - $subNavs['redirects'] = [ |
|
| 169 | + $subNavs[ 'redirects' ] = [ |
|
| 170 | 170 | 'label' => 'Redirects', |
| 171 | 171 | 'url' => 'retour/redirects', |
| 172 | 172 | ]; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $editableSettings = false; |
| 178 | 178 | } |
| 179 | 179 | if ($currentUser->can('retour:settings') && $editableSettings) { |
| 180 | - $subNavs['settings'] = [ |
|
| 180 | + $subNavs[ 'settings' ] = [ |
|
| 181 | 181 | 'label' => 'Settings', |
| 182 | 182 | 'url' => 'retour/settings', |
| 183 | 183 | ]; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | Event::on( |
| 237 | 237 | ClearCaches::class, |
| 238 | 238 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
| 239 | - function (RegisterCacheOptionsEvent $event) { |
|
| 239 | + function(RegisterCacheOptionsEvent $event) { |
|
| 240 | 240 | Craft::debug( |
| 241 | 241 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
| 242 | 242 | __METHOD__ |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | Event::on( |
| 253 | 253 | Plugins::class, |
| 254 | 254 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
| 255 | - function (PluginEvent $event) { |
|
| 255 | + function(PluginEvent $event) { |
|
| 256 | 256 | if ($event->plugin === $this) { |
| 257 | 257 | // Invalidate our caches after we've been installed |
| 258 | 258 | $this->clearAllCaches(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | Event::on( |
| 280 | 280 | CraftVariable::class, |
| 281 | 281 | CraftVariable::EVENT_INIT, |
| 282 | - function (Event $event) { |
|
| 282 | + function(Event $event) { |
|
| 283 | 283 | /** @var CraftVariable $variable */ |
| 284 | 284 | $variable = $event->sender; |
| 285 | 285 | $variable->set('retour', RetourVariable::class); |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | Event::on( |
| 290 | 290 | Elements::class, |
| 291 | 291 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
| 292 | - function (ElementEvent $event) { |
|
| 292 | + function(ElementEvent $event) { |
|
| 293 | 293 | Craft::debug( |
| 294 | 294 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
| 295 | 295 | __METHOD__ |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | if ($oldElement !== null) { |
| 305 | 305 | // Stash the old URLs by element id, and do so only once, |
| 306 | 306 | // in case we are called more than once per request |
| 307 | - if (empty($this->oldElementUris[$oldElement->id])) { |
|
| 308 | - $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement); |
|
| 307 | + if (empty($this->oldElementUris[ $oldElement->id ])) { |
|
| 308 | + $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement); |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | Event::on( |
| 317 | 317 | Elements::class, |
| 318 | 318 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
| 319 | - function (ElementEvent $event) { |
|
| 319 | + function(ElementEvent $event) { |
|
| 320 | 320 | Craft::debug( |
| 321 | 321 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
| 322 | 322 | __METHOD__ |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | Event::on( |
| 333 | 333 | Plugins::class, |
| 334 | 334 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
| 335 | - function () { |
|
| 335 | + function() { |
|
| 336 | 336 | // Install these only after all other plugins have loaded |
| 337 | 337 | $request = Craft::$app->getRequest(); |
| 338 | 338 | // Only respond to non-console site requests |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | Event::on( |
| 351 | 351 | Schema::class, |
| 352 | 352 | AlterSchemaFields::EVENT, |
| 353 | - [GetCraftQLSchema::class, 'handle'] |
|
| 353 | + [ GetCraftQLSchema::class, 'handle' ] |
|
| 354 | 354 | ); |
| 355 | 355 | } |
| 356 | 356 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | Event::on( |
| 365 | 365 | UrlManager::class, |
| 366 | 366 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
| 367 | - function (RegisterUrlRulesEvent $event) { |
|
| 367 | + function(RegisterUrlRulesEvent $event) { |
|
| 368 | 368 | Craft::debug( |
| 369 | 369 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
| 370 | 370 | __METHOD__ |
@@ -387,15 +387,15 @@ discard block |
||
| 387 | 387 | Event::on( |
| 388 | 388 | Dashboard::class, |
| 389 | 389 | Dashboard::EVENT_REGISTER_WIDGET_TYPES, |
| 390 | - function (RegisterComponentTypesEvent $event) { |
|
| 391 | - $event->types[] = RetourWidget::class; |
|
| 390 | + function(RegisterComponentTypesEvent $event) { |
|
| 391 | + $event->types[ ] = RetourWidget::class; |
|
| 392 | 392 | } |
| 393 | 393 | ); |
| 394 | 394 | // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES |
| 395 | 395 | Event::on( |
| 396 | 396 | UrlManager::class, |
| 397 | 397 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
| 398 | - function (RegisterUrlRulesEvent $event) { |
|
| 398 | + function(RegisterUrlRulesEvent $event) { |
|
| 399 | 399 | Craft::debug( |
| 400 | 400 | 'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
| 401 | 401 | __METHOD__ |
@@ -411,13 +411,13 @@ discard block |
||
| 411 | 411 | Event::on( |
| 412 | 412 | UserPermissions::class, |
| 413 | 413 | UserPermissions::EVENT_REGISTER_PERMISSIONS, |
| 414 | - function (RegisterUserPermissionsEvent $event) { |
|
| 414 | + function(RegisterUserPermissionsEvent $event) { |
|
| 415 | 415 | Craft::debug( |
| 416 | 416 | 'UserPermissions::EVENT_REGISTER_PERMISSIONS', |
| 417 | 417 | __METHOD__ |
| 418 | 418 | ); |
| 419 | 419 | // Register our custom permissions |
| 420 | - $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions(); |
|
| 420 | + $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions(); |
|
| 421 | 421 | } |
| 422 | 422 | ); |
| 423 | 423 | } |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | Event::on( |
| 434 | 434 | ErrorHandler::class, |
| 435 | 435 | ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION, |
| 436 | - function (ExceptionEvent $event) { |
|
| 436 | + function(ExceptionEvent $event) { |
|
| 437 | 437 | Craft::debug( |
| 438 | 438 | 'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION', |
| 439 | 439 | __METHOD__ |
@@ -476,16 +476,16 @@ discard block |
||
| 476 | 476 | protected function handleElementUriChange(Element $element) |
| 477 | 477 | { |
| 478 | 478 | $uris = $this->getAllElementUris($element); |
| 479 | - if (!empty($this->oldElementUris[$element->id])) { |
|
| 480 | - $oldElementUris = $this->oldElementUris[$element->id]; |
|
| 479 | + if (!empty($this->oldElementUris[ $element->id ])) { |
|
| 480 | + $oldElementUris = $this->oldElementUris[ $element->id ]; |
|
| 481 | 481 | foreach ($uris as $siteId => $newUri) { |
| 482 | - if (!empty($oldElementUris[$siteId])) { |
|
| 483 | - $oldUri = $oldElementUris[$siteId]; |
|
| 482 | + if (!empty($oldElementUris[ $siteId ])) { |
|
| 483 | + $oldUri = $oldElementUris[ $siteId ]; |
|
| 484 | 484 | Craft::debug( |
| 485 | 485 | Craft::t( |
| 486 | 486 | 'retour', |
| 487 | 487 | 'Comparing old: {oldUri} to new: {newUri}', |
| 488 | - ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)] |
|
| 488 | + [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ] |
|
| 489 | 489 | ), |
| 490 | 490 | __METHOD__ |
| 491 | 491 | ); |
@@ -520,12 +520,12 @@ discard block |
||
| 520 | 520 | */ |
| 521 | 521 | protected function getAllElementUris(Element $element): array |
| 522 | 522 | { |
| 523 | - $uris = []; |
|
| 523 | + $uris = [ ]; |
|
| 524 | 524 | $sites = Craft::$app->getSites()->getAllSites(); |
| 525 | 525 | foreach ($sites as $site) { |
| 526 | 526 | $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id); |
| 527 | 527 | if ($uri !== null) { |
| 528 | - $uris[$site->id] = $uri; |
|
| 528 | + $uris[ $site->id ] = $uri; |
|
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | Craft::t( |
| 534 | 534 | 'retour', |
| 535 | 535 | 'Getting Element URIs: {uris}', |
| 536 | - ['uris' => print_r($uris, true)] |
|
| 536 | + [ 'uris' => print_r($uris, true) ] |
|
| 537 | 537 | ), |
| 538 | 538 | __METHOD__ |
| 539 | 539 | ); |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | [ |
| 598 | 598 | 'key' => 'retour-redirect-caches', |
| 599 | 599 | 'label' => Craft::t('retour', 'Retour redirect caches'), |
| 600 | - 'action' => [self::$plugin->redirects, 'invalidateCaches'], |
|
| 600 | + 'action' => [ self::$plugin->redirects, 'invalidateCaches' ], |
|
| 601 | 601 | ], |
| 602 | 602 | ]; |
| 603 | 603 | } |