@@ -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 | } |