@@ -96,18 +96,18 @@ discard block |
||
| 96 | 96 | public function rules() |
| 97 | 97 | { |
| 98 | 98 | return [ |
| 99 | - ['id', 'integer'], |
|
| 100 | - ['siteId', 'integer'], |
|
| 101 | - ['siteId', 'default', 'value' => null], |
|
| 102 | - ['associatedElementId', 'default', 'value' => 0], |
|
| 103 | - ['associatedElementId', 'integer'], |
|
| 104 | - ['enabled', 'boolean'], |
|
| 105 | - ['redirectSrcMatch', 'default', 'value' => 'pathonly'], |
|
| 106 | - ['redirectSrcMatch', DbStringValidator::class, 'max' => 32], |
|
| 107 | - ['redirectSrcMatch', 'string'], |
|
| 108 | - ['redirectMatchType', 'default', 'value' => 'exactmatch'], |
|
| 109 | - ['redirectMatchType', DbStringValidator::class, 'max' => 32], |
|
| 110 | - ['redirectMatchType', 'string'], |
|
| 99 | + [ 'id', 'integer' ], |
|
| 100 | + [ 'siteId', 'integer' ], |
|
| 101 | + [ 'siteId', 'default', 'value' => null ], |
|
| 102 | + [ 'associatedElementId', 'default', 'value' => 0 ], |
|
| 103 | + [ 'associatedElementId', 'integer' ], |
|
| 104 | + [ 'enabled', 'boolean' ], |
|
| 105 | + [ 'redirectSrcMatch', 'default', 'value' => 'pathonly' ], |
|
| 106 | + [ 'redirectSrcMatch', DbStringValidator::class, 'max' => 32 ], |
|
| 107 | + [ 'redirectSrcMatch', 'string' ], |
|
| 108 | + [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ], |
|
| 109 | + [ 'redirectMatchType', DbStringValidator::class, 'max' => 32 ], |
|
| 110 | + [ 'redirectMatchType', 'string' ], |
|
| 111 | 111 | [ |
| 112 | 112 | [ |
| 113 | 113 | 'redirectSrcUrl', |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | 'default', |
| 118 | 118 | 'value' => '' |
| 119 | 119 | ], |
| 120 | - ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'], |
|
| 120 | + [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ], |
|
| 121 | 121 | [ |
| 122 | 122 | [ |
| 123 | 123 | 'redirectSrcUrl', |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | ], |
| 145 | 145 | 'string' |
| 146 | 146 | ], |
| 147 | - ['redirectHttpCode', 'integer'], |
|
| 148 | - ['redirectHttpCode', 'default', 'value' => 301], |
|
| 149 | - ['hitCount', 'default', 'value' => 0], |
|
| 150 | - ['hitCount', 'integer'], |
|
| 151 | - ['hitLastTime', 'safe'], |
|
| 147 | + [ 'redirectHttpCode', 'integer' ], |
|
| 148 | + [ 'redirectHttpCode', 'default', 'value' => 301 ], |
|
| 149 | + [ 'hitCount', 'default', 'value' => 0 ], |
|
| 150 | + [ 'hitCount', 'integer' ], |
|
| 151 | + [ 'hitLastTime', 'safe' ], |
|
| 152 | 152 | ]; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public function actionDashboard(string $range = 'day', int $siteId = 0): Response |
| 56 | 56 | { |
| 57 | 57 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
| 58 | - $data = []; |
|
| 58 | + $data = [ ]; |
|
| 59 | 59 | $days = 1; |
| 60 | 60 | switch ($range) { |
| 61 | 61 | case 'day': |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | 'COUNT(handledByRetour = 1 or null) as handled_cnt', |
| 82 | 82 | ]) |
| 83 | 83 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )"); |
| 84 | - if ((int)$siteId !== 0) { |
|
| 85 | - $query->andWhere(['siteId' => $siteId]); |
|
| 84 | + if ((int) $siteId !== 0) { |
|
| 85 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 86 | 86 | } |
| 87 | 87 | $query |
| 88 | 88 | ->orderBy('date_formatted ASC') |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt", |
| 100 | 100 | ]) |
| 101 | 101 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )"); |
| 102 | - if ((int)$siteId !== 0) { |
|
| 103 | - $query->andWhere(['siteId' => $siteId]); |
|
| 102 | + if ((int) $siteId !== 0) { |
|
| 103 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
| 104 | 104 | } |
| 105 | 105 | $query |
| 106 | 106 | ->orderBy('date_formatted ASC') |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | $stats = $query->all(); |
| 109 | 109 | } |
| 110 | 110 | if ($stats) { |
| 111 | - $data[] = [ |
|
| 111 | + $data[ ] = [ |
|
| 112 | 112 | 'name' => '404 hits', |
| 113 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'cnt')), |
|
| 114 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
| 113 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'cnt')), |
|
| 114 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
| 115 | 115 | ]; |
| 116 | - $data[] = [ |
|
| 116 | + $data[ ] = [ |
|
| 117 | 117 | 'name' => 'Handled 404 hits', |
| 118 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
| 119 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
| 118 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
| 119 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
| 120 | 120 | ]; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function actionWidget($days = 1): Response |
| 134 | 134 | { |
| 135 | - $data = []; |
|
| 135 | + $data = [ ]; |
|
| 136 | 136 | // Different dbs do it different ways |
| 137 | 137 | $stats = null; |
| 138 | 138 | $handledStats = null; |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | if ($stats) { |
| 165 | 165 | $data = [ |
| 166 | - (int)$stats, |
|
| 167 | - (int)$handledStats, |
|
| 166 | + (int) $stats, |
|
| 167 | + (int) $handledStats, |
|
| 168 | 168 | ]; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public static function setSitesMenuVariables(array &$variables) |
| 37 | 37 | { |
| 38 | 38 | // Set defaults based on the section settings |
| 39 | - $variables['sitesMenu'] = [ |
|
| 39 | + $variables[ 'sitesMenu' ] = [ |
|
| 40 | 40 | 0 => Craft::t( |
| 41 | 41 | 'retour', |
| 42 | 42 | 'All Sites' |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | /** @var Site $site */ |
| 50 | 50 | foreach ($sites->getAllGroups() as $group) { |
| 51 | 51 | $groupSites = $sites->getSitesByGroupId($group->id); |
| 52 | - $variables['sitesMenu'][$group->name] |
|
| 53 | - = ['optgroup' => $group->name]; |
|
| 52 | + $variables[ 'sitesMenu' ][ $group->name ] |
|
| 53 | + = [ 'optgroup' => $group->name ]; |
|
| 54 | 54 | foreach ($groupSites as $groupSite) { |
| 55 | 55 | if (in_array($groupSite->id, $editableSites, false)) { |
| 56 | - $variables['sitesMenu'][$groupSite->id] = $groupSite->name; |
|
| 56 | + $variables[ 'sitesMenu' ][ $groupSite->id ] = $groupSite->name; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -73,53 +73,53 @@ discard block |
||
| 73 | 73 | $sites = Craft::$app->getSites(); |
| 74 | 74 | if (Craft::$app->getIsMultiSite()) { |
| 75 | 75 | // Set defaults based on the section settings |
| 76 | - $variables['enabledSiteIds'] = []; |
|
| 77 | - $variables['siteIds'] = []; |
|
| 76 | + $variables[ 'enabledSiteIds' ] = [ ]; |
|
| 77 | + $variables[ 'siteIds' ] = [ ]; |
|
| 78 | 78 | |
| 79 | 79 | /** @var Site $site */ |
| 80 | 80 | foreach ($sites->getEditableSiteIds() as $editableSiteId) { |
| 81 | - $variables['enabledSiteIds'][] = $editableSiteId; |
|
| 82 | - $variables['siteIds'][] = $editableSiteId; |
|
| 81 | + $variables[ 'enabledSiteIds' ][ ] = $editableSiteId; |
|
| 82 | + $variables[ 'siteIds' ][ ] = $editableSiteId; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // Make sure the $siteId they are trying to edit is in our array of editable sites |
| 86 | - if (!\in_array($siteId, $variables['enabledSiteIds'], false)) { |
|
| 87 | - if (!empty($variables['enabledSiteIds'])) { |
|
| 86 | + if (!\in_array($siteId, $variables[ 'enabledSiteIds' ], false)) { |
|
| 87 | + if (!empty($variables[ 'enabledSiteIds' ])) { |
|
| 88 | 88 | if ($siteId !== 0) { |
| 89 | - $siteId = reset($variables['enabledSiteIds']); |
|
| 89 | + $siteId = reset($variables[ 'enabledSiteIds' ]); |
|
| 90 | 90 | } |
| 91 | 91 | } else { |
| 92 | - self::requirePermission('editSite:'.$siteId); |
|
| 92 | + self::requirePermission('editSite:' . $siteId); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | // Set the currentSiteId and currentSiteHandle |
| 97 | - $variables['currentSiteId'] = empty($siteId) ? 0 : $siteId; |
|
| 98 | - $variables['currentSiteHandle'] = empty($siteHandle) |
|
| 97 | + $variables[ 'currentSiteId' ] = empty($siteId) ? 0 : $siteId; |
|
| 98 | + $variables[ 'currentSiteHandle' ] = empty($siteHandle) |
|
| 99 | 99 | ? Craft::$app->getSites()->currentSite->handle |
| 100 | 100 | : $siteHandle; |
| 101 | 101 | |
| 102 | 102 | // Page title |
| 103 | - $variables['showSites'] = ( |
|
| 103 | + $variables[ 'showSites' ] = ( |
|
| 104 | 104 | Craft::$app->getIsMultiSite() && |
| 105 | - \count($variables['enabledSiteIds']) |
|
| 105 | + \count($variables[ 'enabledSiteIds' ]) |
|
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | - if ($variables['showSites']) { |
|
| 109 | - if ($variables['currentSiteId'] === 0) { |
|
| 110 | - $variables['sitesMenuLabel'] = Craft::t( |
|
| 108 | + if ($variables[ 'showSites' ]) { |
|
| 109 | + if ($variables[ 'currentSiteId' ] === 0) { |
|
| 110 | + $variables[ 'sitesMenuLabel' ] = Craft::t( |
|
| 111 | 111 | 'retour', |
| 112 | 112 | 'All Sites' |
| 113 | 113 | ); |
| 114 | 114 | } else { |
| 115 | - $variables['sitesMenuLabel'] = Craft::t( |
|
| 115 | + $variables[ 'sitesMenuLabel' ] = Craft::t( |
|
| 116 | 116 | 'site', |
| 117 | - $sites->getSiteById((int)$variables['currentSiteId'])->name |
|
| 117 | + $sites->getSiteById((int) $variables[ 'currentSiteId' ])->name |
|
| 118 | 118 | ); |
| 119 | 119 | } |
| 120 | 120 | } else { |
| 121 | - $variables['currentSiteId'] = 0; |
|
| 122 | - $variables['sitesMenuLabel'] = ''; |
|
| 121 | + $variables[ 'currentSiteId' ] = 0; |
|
| 122 | + $variables[ 'sitesMenuLabel' ] = ''; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | if ($siteHandle !== null) { |
| 138 | 138 | $site = Craft::$app->getSites()->getSiteByHandle($siteHandle); |
| 139 | 139 | if (!$site) { |
| 140 | - throw new NotFoundHttpException('Invalid site handle: '.$siteHandle); |
|
| 140 | + throw new NotFoundHttpException('Invalid site handle: ' . $siteHandle); |
|
| 141 | 141 | } |
| 142 | 142 | $siteId = $site->id; |
| 143 | 143 | } else { |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | // Update retour widget type |
| 21 | 21 | $this->update('{{%widgets}}', [ |
| 22 | 22 | 'type' => RetourWidget::class |
| 23 | - ], ['type' => 'Retour']); |
|
| 23 | + ], [ 'type' => 'Retour' ]); |
|
| 24 | 24 | |
| 25 | 25 | return true; |
| 26 | 26 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | // Update retour widget type |
| 21 | 21 | $this->update('{{%widgets}}', [ |
| 22 | 22 | 'type' => RetourWidget::class |
| 23 | - ], ['type' => 'Retour']); |
|
| 23 | + ], [ 'type' => 'Retour' ]); |
|
| 24 | 24 | |
| 25 | 25 | return true; |
| 26 | 26 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | // Protected Properties |
| 42 | 42 | // ========================================================================= |
| 43 | 43 | |
| 44 | - protected $allowAnonymous = []; |
|
| 44 | + protected $allowAnonymous = [ ]; |
|
| 45 | 45 | |
| 46 | 46 | // Public Methods |
| 47 | 47 | // ========================================================================= |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function actionRedirects(string $siteHandle = null): Response |
| 59 | 59 | { |
| 60 | - $variables = []; |
|
| 60 | + $variables = [ ]; |
|
| 61 | 61 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 62 | 62 | // Get the site to edit |
| 63 | 63 | $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle); |
@@ -70,32 +70,32 @@ discard block |
||
| 70 | 70 | } catch (InvalidConfigException $e) { |
| 71 | 71 | Craft::error($e->getMessage(), __METHOD__); |
| 72 | 72 | } |
| 73 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
| 73 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
| 74 | 74 | '@nystudio107/retour/assetbundles/retour/dist', |
| 75 | 75 | true |
| 76 | 76 | ); |
| 77 | 77 | // Enabled sites |
| 78 | 78 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
| 79 | - $variables['controllerHandle'] = 'redirects'; |
|
| 79 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
| 80 | 80 | |
| 81 | 81 | // Basic variables |
| 82 | - $variables['fullPageForm'] = false; |
|
| 83 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 84 | - $variables['pluginName'] = $pluginName; |
|
| 85 | - $variables['title'] = $templateTitle; |
|
| 86 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 87 | - $variables['crumbs'] = [ |
|
| 82 | + $variables[ 'fullPageForm' ] = false; |
|
| 83 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 84 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 85 | + $variables[ 'title' ] = $templateTitle; |
|
| 86 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 87 | + $variables[ 'crumbs' ] = [ |
|
| 88 | 88 | [ |
| 89 | 89 | 'label' => $pluginName, |
| 90 | 90 | 'url' => UrlHelper::cpUrl('retour'), |
| 91 | 91 | ], |
| 92 | 92 | [ |
| 93 | 93 | 'label' => $templateTitle, |
| 94 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
| 94 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
| 95 | 95 | ], |
| 96 | 96 | ]; |
| 97 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
| 98 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
| 97 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
| 98 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
| 99 | 99 | |
| 100 | 100 | // Render the template |
| 101 | 101 | return $this->renderTemplate('retour/redirects/index', $variables); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | int $siteId = 0, |
| 120 | 120 | StaticRedirectsModel $redirect = null |
| 121 | 121 | ): Response { |
| 122 | - $variables = []; |
|
| 122 | + $variables = [ ]; |
|
| 123 | 123 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 124 | 124 | |
| 125 | 125 | // Load in the redirect |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | if ($redirect === null) { |
| 134 | 134 | $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId); |
| 135 | 135 | if ($redirectConfig === null) { |
| 136 | - $redirectConfig = []; |
|
| 136 | + $redirectConfig = [ ]; |
|
| 137 | 137 | Craft::error( |
| 138 | 138 | Craft::t( |
| 139 | 139 | 'retour', |
| 140 | 140 | "Couldn't load redirect id {id}", |
| 141 | - ['id' => $redirectId] |
|
| 141 | + [ 'id' => $redirectId ] |
|
| 142 | 142 | ), |
| 143 | 143 | __METHOD__ |
| 144 | 144 | ); |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | if ($redirect->siteId) { |
| 152 | 152 | $site = $sites->getSiteById($redirect->siteId); |
| 153 | 153 | if ($site) { |
| 154 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
| 154 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | if ($siteId) { |
| 158 | 158 | $site = $sites->getSiteById($siteId); |
| 159 | 159 | if ($site) { |
| 160 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
| 160 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | $pluginName = Retour::$settings->pluginName; |
@@ -169,20 +169,20 @@ discard block |
||
| 169 | 169 | } catch (InvalidConfigException $e) { |
| 170 | 170 | Craft::error($e->getMessage(), __METHOD__); |
| 171 | 171 | } |
| 172 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
| 172 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
| 173 | 173 | '@nystudio107/retour/assetbundles/retour/dist', |
| 174 | 174 | true |
| 175 | 175 | ); |
| 176 | 176 | // Sites menu |
| 177 | 177 | MultiSiteHelper::setSitesMenuVariables($variables); |
| 178 | - $variables['controllerHandle'] = 'redirects'; |
|
| 178 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
| 179 | 179 | |
| 180 | 180 | // Basic variables |
| 181 | - $variables['fullPageForm'] = true; |
|
| 182 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 183 | - $variables['pluginName'] = $pluginName; |
|
| 184 | - $variables['title'] = $templateTitle; |
|
| 185 | - $variables['crumbs'] = [ |
|
| 181 | + $variables[ 'fullPageForm' ] = true; |
|
| 182 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 183 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 184 | + $variables[ 'title' ] = $templateTitle; |
|
| 185 | + $variables[ 'crumbs' ] = [ |
|
| 186 | 186 | [ |
| 187 | 187 | 'label' => $pluginName, |
| 188 | 188 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | ], |
| 194 | 194 | [ |
| 195 | 195 | 'label' => $templateTitle, |
| 196 | - 'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId), |
|
| 196 | + 'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId), |
|
| 197 | 197 | ], |
| 198 | 198 | ]; |
| 199 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 200 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
| 201 | - $variables['redirect'] = $redirect; |
|
| 199 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 200 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
| 201 | + $variables[ 'redirect' ] = $redirect; |
|
| 202 | 202 | |
| 203 | 203 | // Render the template |
| 204 | 204 | return $this->renderTemplate('retour/redirects/_edit', $variables); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | if ($redirectConfig === null) { |
| 245 | 245 | throw new NotFoundHttpException('Redirect not found'); |
| 246 | 246 | } |
| 247 | - $redirectConfig['id'] = (int)$redirectConfig['id']; |
|
| 247 | + $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ]; |
|
| 248 | 248 | $redirect = new StaticRedirectsModel($redirectConfig); |
| 249 | 249 | // Make sure the redirect validates |
| 250 | 250 | if (!$redirect->validate()) { |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
| 262 | 262 | // Handle the case where the redirect wasn't saved because it'd create a redirect loop |
| 263 | 263 | $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl( |
| 264 | - $redirectConfig['redirectSrcUrl'], |
|
| 265 | - $redirectConfig['siteId'] |
|
| 264 | + $redirectConfig[ 'redirectSrcUrl' ], |
|
| 265 | + $redirectConfig[ 'siteId' ] |
|
| 266 | 266 | ); |
| 267 | 267 | if ($testRedirectConfig === null) { |
| 268 | 268 | Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop.")); |
@@ -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/assetbundles/retour/dist', |
| 76 | 76 | true |
| 77 | 77 | ); |
| 78 | 78 | // Enabled sites |
| 79 | 79 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
| 80 | - $variables['controllerHandle'] = 'dashboard'; |
|
| 80 | + $variables[ 'controllerHandle' ] = 'dashboard'; |
|
| 81 | 81 | |
| 82 | 82 | // Basic variables |
| 83 | - $variables['fullPageForm'] = false; |
|
| 84 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 85 | - $variables['pluginName'] = $pluginName; |
|
| 86 | - $variables['title'] = $templateTitle; |
|
| 87 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 88 | - $variables['crumbs'] = [ |
|
| 83 | + $variables[ 'fullPageForm' ] = false; |
|
| 84 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 85 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 86 | + $variables[ 'title' ] = $templateTitle; |
|
| 87 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 88 | + $variables[ 'crumbs' ] = [ |
|
| 89 | 89 | [ |
| 90 | 90 | 'label' => $pluginName, |
| 91 | 91 | 'url' => UrlHelper::cpUrl('retour'), |
| 92 | 92 | ], |
| 93 | 93 | [ |
| 94 | 94 | 'label' => $templateTitle, |
| 95 | - 'url' => UrlHelper::cpUrl('retour/dashboard'.$siteHandleUri), |
|
| 95 | + 'url' => UrlHelper::cpUrl('retour/dashboard' . $siteHandleUri), |
|
| 96 | 96 | ], |
| 97 | 97 | ]; |
| 98 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
| 99 | - $variables['selectedSubnavItem'] = 'dashboard'; |
|
| 100 | - $variables['showWelcome'] = $showWelcome; |
|
| 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 | ); |
@@ -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 | |