@@ -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 | ); |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | // Iterate through the redirects |
433 | 433 | foreach ($redirects as $redirect) { |
434 | 434 | // Figure out what type of source matching to do |
435 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
436 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
435 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
436 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
437 | 437 | if ($redirectEnabled === true) { |
438 | 438 | switch ($redirectSrcMatch) { |
439 | 439 | case 'pathonly': |
@@ -446,11 +446,11 @@ discard block |
||
446 | 446 | $url = $pathOnly; |
447 | 447 | break; |
448 | 448 | } |
449 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
449 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
450 | 450 | switch ($redirectMatchType) { |
451 | 451 | // Do a straight up match |
452 | 452 | case 'exactmatch': |
453 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
453 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
454 | 454 | $this->incrementRedirectHitCount($redirect); |
455 | 455 | $this->saveRedirectToCache($url, $redirect); |
456 | 456 | |
@@ -473,15 +473,15 @@ discard block |
||
473 | 473 | |
474 | 474 | // Do a regex match |
475 | 475 | case 'regexmatch': |
476 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
476 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
477 | 477 | try { |
478 | 478 | if (preg_match($matchRegEx, $url) === 1) { |
479 | 479 | $this->incrementRedirectHitCount($redirect); |
480 | 480 | // If we're not associated with an EntryID, handle capture group replacement |
481 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
482 | - $redirect['redirectDestUrl'] = preg_replace( |
|
481 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
482 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
483 | 483 | $matchRegEx, |
484 | - $redirect['redirectDestUrl'], |
|
484 | + $redirect[ 'redirectDestUrl' ], |
|
485 | 485 | $url |
486 | 486 | ); |
487 | 487 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | } |
506 | 506 | } catch (\Exception $e) { |
507 | 507 | // That's fine |
508 | - Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__); |
|
508 | + Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | break; |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | 'redirect' => &$redirect, |
520 | 520 | ], |
521 | 521 | ]; |
522 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
522 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
523 | 523 | if ($result) { |
524 | 524 | $this->incrementRedirectHitCount($redirect); |
525 | 525 | $this->saveRedirectToCache($url, $redirect); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | Craft::t( |
560 | 560 | 'retour', |
561 | 561 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
562 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
562 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
563 | 563 | ), |
564 | 564 | __METHOD__ |
565 | 565 | ); |
@@ -586,8 +586,8 @@ discard block |
||
586 | 586 | |
587 | 587 | if ($url !== null && $redirect !== null) { |
588 | 588 | // Save the modified redirect to the cache |
589 | - $redirect['redirectDestUrl'] = $event->redirectDestUrl; |
|
590 | - $redirect['redirectHttpCode'] = $event->redirectHttpCode; |
|
589 | + $redirect[ 'redirectDestUrl' ] = $event->redirectDestUrl; |
|
590 | + $redirect[ 'redirectHttpCode' ] = $event->redirectHttpCode; |
|
591 | 591 | $this->saveRedirectToCache($url, $redirect); |
592 | 592 | } |
593 | 593 | } |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
612 | 612 | /** @var Plugin $plugin */ |
613 | 613 | if (method_exists($plugin, 'retourMatch')) { |
614 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
614 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
@@ -632,12 +632,12 @@ discard block |
||
632 | 632 | } |
633 | 633 | // Query the db table |
634 | 634 | $query = (new Query()) |
635 | - ->from(['{{%retour_static_redirects}}']) |
|
635 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
636 | 636 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
637 | 637 | if ($siteId) { |
638 | 638 | $query |
639 | - ->where(['siteId' => $siteId]) |
|
640 | - ->orWhere(['siteId' => null]); |
|
639 | + ->where([ 'siteId' => $siteId ]) |
|
640 | + ->orWhere([ 'siteId' => null ]); |
|
641 | 641 | } |
642 | 642 | if ($limit) { |
643 | 643 | $query->limit($limit); |
@@ -660,8 +660,8 @@ discard block |
||
660 | 660 | { |
661 | 661 | // Query the db table |
662 | 662 | $redirect = (new Query()) |
663 | - ->from(['{{%retour_static_redirects}}']) |
|
664 | - ->where(['id' => $id]) |
|
663 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
664 | + ->where([ 'id' => $id ]) |
|
665 | 665 | ->one(); |
666 | 666 | |
667 | 667 | return $redirect; |
@@ -679,16 +679,16 @@ discard block |
||
679 | 679 | { |
680 | 680 | // Query the db table |
681 | 681 | $query = (new Query()) |
682 | - ->from(['{{%retour_static_redirects}}']) |
|
683 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
682 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
683 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
684 | 684 | ; |
685 | 685 | if ($siteId) { |
686 | 686 | $query |
687 | - ->andWhere(['or', [ |
|
687 | + ->andWhere([ 'or', [ |
|
688 | 688 | 'siteId' => $siteId, |
689 | 689 | ], [ |
690 | 690 | 'siteId' => null, |
691 | - ]]); |
|
691 | + ] ]); |
|
692 | 692 | } |
693 | 693 | $redirect = $query->one(); |
694 | 694 | |
@@ -730,13 +730,13 @@ discard block |
||
730 | 730 | { |
731 | 731 | if ($redirectConfig !== null) { |
732 | 732 | $db = Craft::$app->getDb(); |
733 | - $redirectConfig['hitCount']++; |
|
734 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
733 | + $redirectConfig[ 'hitCount' ]++; |
|
734 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
735 | 735 | Craft::debug( |
736 | 736 | Craft::t( |
737 | 737 | 'retour', |
738 | 738 | 'Incrementing statistics for: {redirect}', |
739 | - ['redirect' => print_r($redirectConfig, true)] |
|
739 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
740 | 740 | ), |
741 | 741 | __METHOD__ |
742 | 742 | ); |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | $rowsAffected = $db->createCommand()->update( |
746 | 746 | '{{%retour_static_redirects}}', |
747 | 747 | [ |
748 | - 'hitCount' => $redirectConfig['hitCount'], |
|
749 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
748 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
749 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
750 | 750 | ], |
751 | 751 | [ |
752 | - 'id' => $redirectConfig['id'], |
|
752 | + 'id' => $redirectConfig[ 'id' ], |
|
753 | 753 | ] |
754 | 754 | )->execute(); |
755 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
755 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
756 | 756 | } catch (\Exception $e) { |
757 | 757 | Craft::error($e->getMessage(), __METHOD__); |
758 | 758 | } |
@@ -765,9 +765,9 @@ discard block |
||
765 | 765 | public function saveRedirect(array $redirectConfig) |
766 | 766 | { |
767 | 767 | // Handle URL encoded URLs by decoding them before saving them |
768 | - if (isset($redirectConfig['redirectMatchType']) && $redirectConfig['redirectMatchType'] === 'exactmatch') { |
|
769 | - $redirectConfig['redirectSrcUrl'] = urldecode($redirectConfig['redirectSrcUrl'] ?? ''); |
|
770 | - $redirectConfig['redirectSrcUrlParsed'] = urldecode($redirectConfig['redirectSrcUrlParsed'] ?? ''); |
|
768 | + if (isset($redirectConfig[ 'redirectMatchType' ]) && $redirectConfig[ 'redirectMatchType' ] === 'exactmatch') { |
|
769 | + $redirectConfig[ 'redirectSrcUrl' ] = urldecode($redirectConfig[ 'redirectSrcUrl' ] ?? ''); |
|
770 | + $redirectConfig[ 'redirectSrcUrlParsed' ] = urldecode($redirectConfig[ 'redirectSrcUrlParsed' ] ?? ''); |
|
771 | 771 | } |
772 | 772 | // Validate the model before saving it to the db |
773 | 773 | $redirect = new StaticRedirectsModel($redirectConfig); |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | Craft::t( |
777 | 777 | 'retour', |
778 | 778 | 'Error validating redirect {id}: {errors}', |
779 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
779 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
780 | 780 | ), |
781 | 781 | __METHOD__ |
782 | 782 | ); |
@@ -786,32 +786,32 @@ discard block |
||
786 | 786 | // Get the validated model attributes and save them to the db |
787 | 787 | $redirectConfig = $redirect->getAttributes(); |
788 | 788 | // 0 for a siteId needs to be converted to null |
789 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
790 | - $redirectConfig['siteId'] = null; |
|
789 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
790 | + $redirectConfig[ 'siteId' ] = null; |
|
791 | 791 | } |
792 | 792 | // Throw an event to before saving the redirect |
793 | 793 | $db = Craft::$app->getDb(); |
794 | 794 | // See if a redirect exists with this source URL already |
795 | - if ((int)$redirectConfig['id'] === 0) { |
|
795 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
796 | 796 | // Query the db table |
797 | 797 | $redirect = (new Query()) |
798 | - ->from(['{{%retour_static_redirects}}']) |
|
799 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
800 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
798 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
799 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
800 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
801 | 801 | ->one(); |
802 | 802 | // If it exists, update it rather than having duplicates |
803 | 803 | if (!empty($redirect)) { |
804 | - $redirectConfig['id'] = $redirect['id']; |
|
804 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | // Trigger a 'beforeSaveRedirect' event |
808 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
808 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
809 | 809 | $event = new RedirectEvent([ |
810 | 810 | 'isNew' => $isNew, |
811 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
812 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
813 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
814 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
811 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
812 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
813 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
814 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
815 | 815 | ]); |
816 | 816 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
817 | 817 | if (!$event->isValid) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | Craft::t( |
824 | 824 | 'retour', |
825 | 825 | 'Updating existing redirect: {redirect}', |
826 | - ['redirect' => print_r($redirectConfig, true)] |
|
826 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
827 | 827 | ), |
828 | 828 | __METHOD__ |
829 | 829 | ); |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | '{{%retour_static_redirects}}', |
834 | 834 | $redirectConfig, |
835 | 835 | [ |
836 | - 'id' => $redirectConfig['id'], |
|
836 | + 'id' => $redirectConfig[ 'id' ], |
|
837 | 837 | ] |
838 | 838 | )->execute(); |
839 | 839 | } catch (Exception $e) { |
@@ -844,11 +844,11 @@ discard block |
||
844 | 844 | Craft::t( |
845 | 845 | 'retour', |
846 | 846 | 'Creating new redirect: {redirect}', |
847 | - ['redirect' => print_r($redirectConfig, true)] |
|
847 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
848 | 848 | ), |
849 | 849 | __METHOD__ |
850 | 850 | ); |
851 | - unset($redirectConfig['id']); |
|
851 | + unset($redirectConfig[ 'id' ]); |
|
852 | 852 | // Create a new record |
853 | 853 | try { |
854 | 854 | $db->createCommand()->insert( |
@@ -861,15 +861,15 @@ discard block |
||
861 | 861 | } |
862 | 862 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
863 | 863 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
864 | - $redirectConfig['redirectDestUrl'], |
|
865 | - $redirectConfig['siteId'] |
|
864 | + $redirectConfig[ 'redirectDestUrl' ], |
|
865 | + $redirectConfig[ 'siteId' ] |
|
866 | 866 | ); |
867 | 867 | if ($testRedirectConfig !== null) { |
868 | 868 | Craft::debug( |
869 | 869 | Craft::t( |
870 | 870 | 'retour', |
871 | 871 | 'Deleting redirect to prevent a loop: {redirect}', |
872 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
872 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
873 | 873 | ), |
874 | 874 | __METHOD__ |
875 | 875 | ); |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | try { |
878 | 878 | $db->createCommand()->delete( |
879 | 879 | '{{%retour_static_redirects}}', |
880 | - ['id' => $testRedirectConfig['id']] |
|
880 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
881 | 881 | )->execute(); |
882 | 882 | } catch (Exception $e) { |
883 | 883 | Craft::error($e->getMessage(), __METHOD__); |
@@ -920,17 +920,17 @@ discard block |
||
920 | 920 | */ |
921 | 921 | public function excludeUri($uri): bool |
922 | 922 | { |
923 | - $uri = '/'.ltrim($uri, '/'); |
|
923 | + $uri = '/' . ltrim($uri, '/'); |
|
924 | 924 | if (!empty(Retour::$settings->excludePatterns)) { |
925 | 925 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
926 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
926 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
927 | 927 | try { |
928 | 928 | if (preg_match($pattern, $uri) === 1) { |
929 | 929 | return true; |
930 | 930 | } |
931 | 931 | } catch (\Exception $e) { |
932 | 932 | // That's fine |
933 | - Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__); |
|
933 | + Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__); |
|
934 | 934 | } |
935 | 935 | } |
936 | 936 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // Protected Properties |
80 | 80 | // ========================================================================= |
81 | 81 | |
82 | - protected $allowAnonymous = []; |
|
82 | + protected $allowAnonymous = [ ]; |
|
83 | 83 | |
84 | 84 | // Public Methods |
85 | 85 | // ========================================================================= |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function actionImportCsv(string $siteHandle = null): Response |
161 | 161 | { |
162 | - $variables = []; |
|
162 | + $variables = [ ]; |
|
163 | 163 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
164 | 164 | // If your CSV document was created or is read on a Macintosh computer, |
165 | 165 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -177,38 +177,38 @@ discard block |
||
177 | 177 | } catch (InvalidConfigException $e) { |
178 | 178 | Craft::error($e->getMessage(), __METHOD__); |
179 | 179 | } |
180 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
180 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
181 | 181 | '@nystudio107/retour/assetbundles/retour/dist', |
182 | 182 | true |
183 | 183 | ); |
184 | 184 | // Enabled sites |
185 | 185 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
186 | - $variables['controllerHandle'] = 'file'; |
|
186 | + $variables[ 'controllerHandle' ] = 'file'; |
|
187 | 187 | |
188 | 188 | // Basic variables |
189 | - $variables['fullPageForm'] = true; |
|
190 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
191 | - $variables['pluginName'] = $pluginName; |
|
192 | - $variables['title'] = $templateTitle; |
|
193 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
194 | - $variables['crumbs'] = [ |
|
189 | + $variables[ 'fullPageForm' ] = true; |
|
190 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
191 | + $variables[ 'pluginName' ] = $pluginName; |
|
192 | + $variables[ 'title' ] = $templateTitle; |
|
193 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
194 | + $variables[ 'crumbs' ] = [ |
|
195 | 195 | [ |
196 | 196 | 'label' => $pluginName, |
197 | 197 | 'url' => UrlHelper::cpUrl('retour'), |
198 | 198 | ], |
199 | 199 | [ |
200 | 200 | 'label' => 'Redirects', |
201 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
201 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
202 | 202 | ], |
203 | 203 | ]; |
204 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
205 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
204 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
205 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
206 | 206 | |
207 | 207 | // The CSV file |
208 | 208 | $file = UploadedFile::getInstanceByName('file'); |
209 | 209 | if ($file !== null) { |
210 | 210 | $filename = uniqid($file->name, true); |
211 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
211 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
212 | 212 | $file->saveAs($filePath, false); |
213 | 213 | // Also save the file to the cache as a backup way to access it |
214 | 214 | $cache = Craft::$app->getCache(); |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | } |
230 | 230 | $headers = $csv->fetchOne(0); |
231 | 231 | Craft::info(print_r($headers, true), __METHOD__); |
232 | - $variables['headers'] = $headers; |
|
233 | - $variables['filename'] = $filePath; |
|
232 | + $variables[ 'headers' ] = $headers; |
|
233 | + $variables[ 'filename' ] = $filePath; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Render the template |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | // Query the db table |
278 | 278 | $data = (new Query()) |
279 | - ->from([$table]) |
|
279 | + ->from([ $table ]) |
|
280 | 280 | ->select(array_keys($columns)) |
281 | 281 | ->orderBy('hitCount DESC') |
282 | 282 | ->all(); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | $csv->insertOne(array_values($columns)); |
291 | 291 | $csv->insertAll($data); |
292 | - $csv->output($filename.'.csv'); |
|
292 | + $csv->output($filename . '.csv'); |
|
293 | 293 | exit(0); |
294 | 294 | } |
295 | 295 | |
@@ -302,16 +302,16 @@ discard block |
||
302 | 302 | { |
303 | 303 | $csv->setOffset(1); |
304 | 304 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
305 | - $csv->each(function ($row) use ($headers, $columns) { |
|
305 | + $csv->each(function($row) use ($headers, $columns) { |
|
306 | 306 | $redirectConfig = [ |
307 | 307 | 'id' => 0, |
308 | 308 | ]; |
309 | 309 | $index = 0; |
310 | 310 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
311 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
312 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
311 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
312 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
313 | 313 | ? null |
314 | - : $row[$headers[$columns[$index]]]; |
|
314 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
315 | 315 | } |
316 | 316 | $index++; |
317 | 317 | } |
@@ -341,10 +341,10 @@ discard block |
||
341 | 341 | ]; |
342 | 342 | $index = 0; |
343 | 343 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
344 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
345 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
344 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
345 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
346 | 346 | ? null |
347 | - : $row[$headers[$columns[$index]]]; |
|
347 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
348 | 348 | } |
349 | 349 | $index++; |
350 | 350 | } |