@@ -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 | // ========================================================================= |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function actionImportCsv(string $siteHandle = null): Response |
158 | 158 | { |
159 | - $variables = []; |
|
159 | + $variables = [ ]; |
|
160 | 160 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
161 | 161 | // If your CSV document was created or is read on a Macintosh computer, |
162 | 162 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -174,38 +174,38 @@ discard block |
||
174 | 174 | } catch (InvalidConfigException $e) { |
175 | 175 | Craft::error($e->getMessage(), __METHOD__); |
176 | 176 | } |
177 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
177 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
178 | 178 | '@nystudio107/retour/web/assets/dist', |
179 | 179 | true |
180 | 180 | ); |
181 | 181 | // Enabled sites |
182 | 182 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
183 | - $variables['controllerHandle'] = 'file'; |
|
183 | + $variables[ 'controllerHandle' ] = 'file'; |
|
184 | 184 | |
185 | 185 | // Basic variables |
186 | - $variables['fullPageForm'] = true; |
|
187 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
188 | - $variables['pluginName'] = $pluginName; |
|
189 | - $variables['title'] = $templateTitle; |
|
190 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
191 | - $variables['crumbs'] = [ |
|
186 | + $variables[ 'fullPageForm' ] = true; |
|
187 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
188 | + $variables[ 'pluginName' ] = $pluginName; |
|
189 | + $variables[ 'title' ] = $templateTitle; |
|
190 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
191 | + $variables[ 'crumbs' ] = [ |
|
192 | 192 | [ |
193 | 193 | 'label' => $pluginName, |
194 | 194 | 'url' => UrlHelper::cpUrl('retour'), |
195 | 195 | ], |
196 | 196 | [ |
197 | 197 | 'label' => 'Redirects', |
198 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
198 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
199 | 199 | ], |
200 | 200 | ]; |
201 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
202 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
201 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
202 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
203 | 203 | |
204 | 204 | // The CSV file |
205 | 205 | $file = UploadedFile::getInstanceByName('file'); |
206 | 206 | if ($file !== null) { |
207 | 207 | $filename = uniqid($file->name, true); |
208 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
208 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
209 | 209 | $file->saveAs($filePath, false); |
210 | 210 | // Also save the file to the cache as a backup way to access it |
211 | 211 | $cache = Craft::$app->getCache(); |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | } |
227 | 227 | $headers = $csv->fetchOne(0); |
228 | 228 | Craft::info(print_r($headers, true), __METHOD__); |
229 | - $variables['headers'] = $headers; |
|
230 | - $variables['filename'] = $filePath; |
|
229 | + $variables[ 'headers' ] = $headers; |
|
230 | + $variables[ 'filename' ] = $filePath; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Render the template |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | // Query the db table |
275 | 275 | $data = (new Query()) |
276 | - ->from([$table]) |
|
276 | + ->from([ $table ]) |
|
277 | 277 | ->select(array_keys($columns)) |
278 | 278 | ->orderBy('hitCount DESC') |
279 | 279 | ->all(); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | } |
287 | 287 | $csv->insertOne(array_values($columns)); |
288 | 288 | $csv->insertAll($data); |
289 | - $csv->output($filename.'.csv'); |
|
289 | + $csv->output($filename . '.csv'); |
|
290 | 290 | exit(0); |
291 | 291 | } |
292 | 292 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | { |
300 | 300 | $csv->setOffset(1); |
301 | 301 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
302 | - $csv->each(function ($row) use ($headers, $columns) { |
|
302 | + $csv->each(function($row) use ($headers, $columns) { |
|
303 | 303 | $redirectConfig = [ |
304 | 304 | 'id' => 0, |
305 | 305 | ]; |
306 | 306 | $index = 0; |
307 | 307 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
308 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
309 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
308 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
309 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
310 | 310 | ? null |
311 | - : $row[$headers[$columns[$index]]]; |
|
311 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
312 | 312 | } |
313 | 313 | $index++; |
314 | 314 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | ]; |
339 | 339 | $index = 0; |
340 | 340 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
341 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
342 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
341 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
342 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
343 | 343 | ? null |
344 | - : $row[$headers[$columns[$index]]]; |
|
344 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
345 | 345 | } |
346 | 346 | $index++; |
347 | 347 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct(array $config) |
34 | 34 | { |
35 | - $config['interfaces'] = [ |
|
35 | + $config[ 'interfaces' ] = [ |
|
36 | 36 | RetourInterface::getType(), |
37 | 37 | ]; |
38 | 38 | |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | protected function resolve($source, $arguments, $context, ResolveInfo $resolveInfo) |
46 | 46 | { |
47 | 47 | $fieldName = $resolveInfo->fieldName; |
48 | - $result = $source[$fieldName] ?? ''; |
|
48 | + $result = $source[ $fieldName ] ?? ''; |
|
49 | 49 | // Handle the `site` virtual field |
50 | 50 | if ($fieldName === 'site') { |
51 | 51 | $result = null; |
52 | - $siteId = $source['siteId'] ?? null; |
|
52 | + $siteId = $source[ 'siteId' ] ?? null; |
|
53 | 53 | if ($siteId) { |
54 | 54 | $site = Craft::$app->getSites()->getSiteById($siteId); |
55 | 55 | if ($site !== null) { |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | $siteId = $source->siteId; |
41 | 41 | } else { |
42 | 42 | // Otherwise, use the passed in arguments, or defaults |
43 | - $uri = $arguments['uri'] ?? '/'; |
|
44 | - $siteId = $arguments['siteId'] ?? null; |
|
45 | - if (isset($arguments['site'])) { |
|
46 | - $site = Craft::$app->getSites()->getSiteByHandle($arguments['site']); |
|
43 | + $uri = $arguments[ 'uri' ] ?? '/'; |
|
44 | + $siteId = $arguments[ 'siteId' ] ?? null; |
|
45 | + if (isset($arguments[ 'site' ])) { |
|
46 | + $site = Craft::$app->getSites()->getSiteByHandle($arguments[ 'site' ]); |
|
47 | 47 | if ($site !== null) { |
48 | 48 | $siteId = $site->id; |
49 | 49 | } |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | |
64 | 64 | if ($redirect === null && Craft::$app->getElements()->getElementByUri(trim($uri, '/'), $siteId) === null) { |
65 | 65 | // Set the `site` virtual field |
66 | - $redirect['site'] = null; |
|
67 | - if (isset($redirect['siteId']) && (int)$redirect['siteId'] !== 0) { |
|
68 | - $site = Craft::$app->getSites()->getSiteById((int)$redirect['siteId']); |
|
66 | + $redirect[ 'site' ] = null; |
|
67 | + if (isset($redirect[ 'siteId' ]) && (int) $redirect[ 'siteId' ] !== 0) { |
|
68 | + $site = Craft::$app->getSites()->getSiteById((int) $redirect[ 'siteId' ]); |
|
69 | 69 | if ($site !== null) { |
70 | - $redirect['site'] = $site->handle; |
|
70 | + $redirect[ 'site' ] = $site->handle; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | // Increment the stats |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public static function resolveAll($source, array $arguments, $context, ResolveInfo $resolveInfo) |
92 | 92 | { |
93 | - $siteId = $arguments['siteId'] ?? Craft::$app->getSites()->getCurrentSite()->id; |
|
93 | + $siteId = $arguments[ 'siteId' ] ?? Craft::$app->getSites()->getCurrentSite()->id; |
|
94 | 94 | |
95 | 95 | $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId); |
96 | 96 |