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