@@ -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 | // ========================================================================= |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function actionImportCsv(string $siteHandle = null): Response |
| 156 | 156 | { |
| 157 | - $variables = []; |
|
| 157 | + $variables = [ ]; |
|
| 158 | 158 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
| 159 | 159 | // If your CSV document was created or is read on a Macintosh computer, |
| 160 | 160 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -172,38 +172,38 @@ discard block |
||
| 172 | 172 | } catch (InvalidConfigException $e) { |
| 173 | 173 | Craft::error($e->getMessage(), __METHOD__); |
| 174 | 174 | } |
| 175 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
| 175 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
| 176 | 176 | '@nystudio107/retour/assetbundles/retour/dist', |
| 177 | 177 | true |
| 178 | 178 | ); |
| 179 | 179 | // Enabled sites |
| 180 | 180 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
| 181 | - $variables['controllerHandle'] = 'file'; |
|
| 181 | + $variables[ 'controllerHandle' ] = 'file'; |
|
| 182 | 182 | |
| 183 | 183 | // Basic variables |
| 184 | - $variables['fullPageForm'] = true; |
|
| 185 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
| 186 | - $variables['pluginName'] = $pluginName; |
|
| 187 | - $variables['title'] = $templateTitle; |
|
| 188 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 189 | - $variables['crumbs'] = [ |
|
| 184 | + $variables[ 'fullPageForm' ] = true; |
|
| 185 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
| 186 | + $variables[ 'pluginName' ] = $pluginName; |
|
| 187 | + $variables[ 'title' ] = $templateTitle; |
|
| 188 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 189 | + $variables[ 'crumbs' ] = [ |
|
| 190 | 190 | [ |
| 191 | 191 | 'label' => $pluginName, |
| 192 | 192 | 'url' => UrlHelper::cpUrl('retour'), |
| 193 | 193 | ], |
| 194 | 194 | [ |
| 195 | 195 | 'label' => 'Redirects', |
| 196 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
| 196 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
| 197 | 197 | ], |
| 198 | 198 | ]; |
| 199 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 200 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
| 199 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
| 200 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
| 201 | 201 | |
| 202 | 202 | // The CSV file |
| 203 | 203 | $file = UploadedFile::getInstanceByName('file'); |
| 204 | 204 | if ($file !== null) { |
| 205 | 205 | $filename = uniqid($file->name, true); |
| 206 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
| 206 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
| 207 | 207 | $file->saveAs($filePath, false); |
| 208 | 208 | // Also save the file to the cache as a backup way to access it |
| 209 | 209 | $cache = Craft::$app->getCache(); |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | $csv = Reader::createFromPath($file->tempName); |
| 220 | 220 | $headers = $csv->fetchOne(0); |
| 221 | 221 | Craft::info(print_r($headers, true), __METHOD__); |
| 222 | - $variables['headers'] = $headers; |
|
| 223 | - $variables['filename'] = $filePath; |
|
| 222 | + $variables[ 'headers' ] = $headers; |
|
| 223 | + $variables[ 'filename' ] = $filePath; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Render the template |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | // Query the db table |
| 268 | 268 | $data = (new Query()) |
| 269 | - ->from([$table]) |
|
| 269 | + ->from([ $table ]) |
|
| 270 | 270 | ->select(array_keys($columns)) |
| 271 | 271 | ->orderBy('hitCount DESC') |
| 272 | 272 | ->all(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | $csv->insertOne(array_values($columns)); |
| 281 | 281 | $csv->insertAll($data); |
| 282 | - $csv->output($filename.'.csv'); |
|
| 282 | + $csv->output($filename . '.csv'); |
|
| 283 | 283 | exit(0); |
| 284 | 284 | } |
| 285 | 285 | |
@@ -292,16 +292,16 @@ discard block |
||
| 292 | 292 | { |
| 293 | 293 | $csv->setOffset(1); |
| 294 | 294 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
| 295 | - $csv->each(function ($row) use ($headers, $columns) { |
|
| 295 | + $csv->each(function($row) use ($headers, $columns) { |
|
| 296 | 296 | $redirectConfig = [ |
| 297 | 297 | 'id' => 0, |
| 298 | 298 | ]; |
| 299 | 299 | $index = 0; |
| 300 | 300 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
| 301 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
| 302 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
| 301 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
| 302 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
| 303 | 303 | ? null |
| 304 | - : $row[$headers[$columns[$index]]]; |
|
| 304 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
| 305 | 305 | } |
| 306 | 306 | $index++; |
| 307 | 307 | } |
@@ -331,10 +331,10 @@ discard block |
||
| 331 | 331 | ]; |
| 332 | 332 | $index = 0; |
| 333 | 333 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
| 334 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
| 335 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
| 334 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
| 335 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
| 336 | 336 | ? null |
| 337 | - : $row[$headers[$columns[$index]]]; |
|
| 337 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
| 338 | 338 | } |
| 339 | 339 | $index++; |
| 340 | 340 | } |