@@ -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 | } |
@@ -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 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | // Protected Properties |
| 74 | 74 | // ========================================================================= |
| 75 | 75 | |
| 76 | - protected $allowAnonymous = []; |
|
| 76 | + protected $allowAnonymous = [ ]; |
|
| 77 | 77 | |
| 78 | 78 | // Public Methods |
| 79 | 79 | // ========================================================================= |
@@ -115,20 +115,20 @@ discard block |
||
| 115 | 115 | if ($headers !== null) { |
| 116 | 116 | $csv->setOffset(1); |
| 117 | 117 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
| 118 | - $csv->each(function ($row) use ($headers, $columns) { |
|
| 118 | + $csv->each(function($row) use ($headers, $columns) { |
|
| 119 | 119 | $redirectConfig = [ |
| 120 | 120 | 'id' => 0, |
| 121 | 121 | ]; |
| 122 | 122 | $index = 0; |
| 123 | 123 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
| 124 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
| 125 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
| 124 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
| 125 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
| 126 | 126 | ? null |
| 127 | - : $row[$headers[$columns[$index]]]; |
|
| 127 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
| 128 | 128 | } |
| 129 | 129 | $index++; |
| 130 | 130 | } |
| 131 | - Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__); |
|
| 131 | + Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__); |
|
| 132 | 132 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
| 133 | 133 | |
| 134 | 134 | return true; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function actionImportCsv(string $siteHandle = null): Response |
| 154 | 154 | { |
| 155 | - $variables = []; |
|
| 155 | + $variables = [ ]; |
|
| 156 | 156 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 157 | 157 | // If your CSV document was created or is read on a Macintosh computer, |
| 158 | 158 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -170,38 +170,38 @@ discard block |
||
| 170 | 170 | } catch (InvalidConfigException $e) { |
| 171 | 171 | Craft::error($e->getMessage(), __METHOD__); |
| 172 | 172 | } |
| 173 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
| 173 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
| 174 | 174 | '@nystudio107/retour/assetbundles/retour/dist', |
| 175 | 175 | true |
| 176 | 176 | ); |
| 177 | 177 | // Enabled sites |
| 178 | 178 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
| 179 | - $variables['controllerHandle'] = 'file'; |
|
| 179 | + $variables[ 'controllerHandle' ] = 'file'; |
|
| 180 | 180 | |
| 181 | 181 | // Basic variables |
| 182 | - $variables['fullPageForm'] = true; |
|
| 183 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 184 | - $variables['pluginName'] = $pluginName; |
|
| 185 | - $variables['title'] = $templateTitle; |
|
| 186 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 187 | - $variables['crumbs'] = [ |
|
| 182 | + $variables[ 'fullPageForm' ] = true; |
|
| 183 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 184 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 185 | + $variables[ 'title' ] = $templateTitle; |
|
| 186 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 187 | + $variables[ 'crumbs' ] = [ |
|
| 188 | 188 | [ |
| 189 | 189 | 'label' => $pluginName, |
| 190 | 190 | 'url' => UrlHelper::cpUrl('retour'), |
| 191 | 191 | ], |
| 192 | 192 | [ |
| 193 | 193 | 'label' => 'Redirects', |
| 194 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
| 194 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
| 195 | 195 | ], |
| 196 | 196 | ]; |
| 197 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 198 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
| 197 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 198 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
| 199 | 199 | |
| 200 | 200 | // The CSV file |
| 201 | 201 | $file = UploadedFile::getInstanceByName('file'); |
| 202 | 202 | if ($file !== null) { |
| 203 | 203 | $filename = uniqid($file->name, true); |
| 204 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
| 204 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
| 205 | 205 | $file->saveAs($filePath, false); |
| 206 | 206 | // Also save the file to the cache as a backup way to access it |
| 207 | 207 | $cache = Craft::$app->getCache(); |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | $csv = Reader::createFromPath($file->tempName); |
| 218 | 218 | $headers = $csv->fetchOne(0); |
| 219 | 219 | Craft::info(print_r($headers, true), __METHOD__); |
| 220 | - $variables['headers'] = $headers; |
|
| 221 | - $variables['filename'] = $filePath; |
|
| 220 | + $variables[ 'headers' ] = $headers; |
|
| 221 | + $variables[ 'filename' ] = $filePath; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // Render the template |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | // Query the db table |
| 266 | 266 | $data = (new Query()) |
| 267 | - ->from([$table]) |
|
| 267 | + ->from([ $table ]) |
|
| 268 | 268 | ->select(array_keys($columns)) |
| 269 | 269 | ->orderBy('hitCount DESC') |
| 270 | 270 | ->all(); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $csv = Writer::createFromFileObject(new \SplTempFileObject()); |
| 273 | 273 | $csv->insertOne(array_values($columns)); |
| 274 | 274 | $csv->insertAll($data); |
| 275 | - $csv->output($filename.'.csv'); |
|
| 275 | + $csv->output($filename . '.csv'); |
|
| 276 | 276 | exit(0); |
| 277 | 277 | } |
| 278 | 278 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function __construct(array $config) |
| 33 | 33 | { |
| 34 | - $config['interfaces'] = [ |
|
| 34 | + $config[ 'interfaces' ] = [ |
|
| 35 | 35 | RetourInterface::getType(), |
| 36 | 36 | ]; |
| 37 | 37 | |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $fieldName = $resolveInfo->fieldName; |
| 47 | 47 | |
| 48 | - return $source[$fieldName]; |
|
| 48 | + return $source[ $fieldName ]; |
|
| 49 | 49 | } |
| 50 | 50 | } |