| Conditions | 21 |
| Paths | 641 |
| Total Lines | 94 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 151 | protected function importData(array $inData): void |
||
| 152 | { |
||
| 153 | $access = $this->pageinfo !== []; |
||
| 154 | $beUser = $this->getBackendUser(); |
||
| 155 | if ($this->id && $access || $beUser->isAdmin() && !$this->id) { |
||
|
|
|||
| 156 | if ($beUser->isAdmin() && !$this->id) { |
||
| 157 | $this->pageinfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0]; |
||
| 158 | } |
||
| 159 | if ($inData['new_import']) { |
||
| 160 | unset($inData['import_mode']); |
||
| 161 | } |
||
| 162 | $import = GeneralUtility::makeInstance(Import::class); |
||
| 163 | $import->init(); |
||
| 164 | $import->update = $inData['do_update']; |
||
| 165 | $import->import_mode = $inData['import_mode']; |
||
| 166 | $import->enableLogging = $inData['enableLogging']; |
||
| 167 | $import->global_ignore_pid = $inData['global_ignore_pid']; |
||
| 168 | $import->force_all_UIDS = $inData['force_all_UIDS']; |
||
| 169 | $import->showDiff = !$inData['notShowDiff']; |
||
| 170 | $import->softrefInputValues = $inData['softrefInputValues']; |
||
| 171 | |||
| 172 | // OUTPUT creation: |
||
| 173 | |||
| 174 | // Make input selector: |
||
| 175 | // must have trailing slash. |
||
| 176 | $path = $this->getDefaultImportExportFolder(); |
||
| 177 | $exportFiles = $this->getExportFiles(); |
||
| 178 | |||
| 179 | $this->shortcutName .= ' (' . htmlspecialchars($this->pageinfo['title']) . ')'; |
||
| 180 | |||
| 181 | // Configuration |
||
| 182 | $selectOptions = ['']; |
||
| 183 | foreach ($exportFiles as $file) { |
||
| 184 | $selectOptions[$file->getCombinedIdentifier()] = $file->getPublicUrl(); |
||
| 185 | } |
||
| 186 | |||
| 187 | $this->standaloneView->assign('import', $import); |
||
| 188 | $this->standaloneView->assign('inData', $inData); |
||
| 189 | $this->standaloneView->assign('fileSelectOptions', $selectOptions); |
||
| 190 | |||
| 191 | if ($path) { |
||
| 192 | $this->standaloneView->assign('importPath', sprintf($this->lang->getLL('importdata_fromPathS'), $path->getCombinedIdentifier())); |
||
| 193 | } else { |
||
| 194 | $this->standaloneView->assign('importPath', $this->lang->getLL('importdata_no_default_upload_folder')); |
||
| 195 | } |
||
| 196 | $this->standaloneView->assign('isAdmin', $beUser->isAdmin()); |
||
| 197 | |||
| 198 | // Upload file: |
||
| 199 | $tempFolder = $this->getDefaultImportExportFolder(); |
||
| 200 | if ($tempFolder) { |
||
| 201 | $this->standaloneView->assign('tempFolder', $tempFolder->getCombinedIdentifier()); |
||
| 202 | $this->standaloneView->assign('hasTempUploadFolder', true); |
||
| 203 | if (GeneralUtility::_POST('_upload')) { |
||
| 204 | $this->standaloneView->assign('submitted', GeneralUtility::_POST('_upload')); |
||
| 205 | $this->standaloneView->assign('noFileUploaded', $this->fileProcessor->internalUploadMap[1]); |
||
| 206 | if ($this->uploadedFiles[0]) { |
||
| 207 | $this->standaloneView->assign('uploadedFile', $this->uploadedFiles[0]->getName()); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | // Perform import or preview depending: |
||
| 213 | if (isset($inData['file'])) { |
||
| 214 | $inFile = $this->getFile($inData['file']); |
||
| 215 | if ($inFile !== null && $inFile->exists()) { |
||
| 216 | $this->standaloneView->assign('metaDataInFileExists', true); |
||
| 217 | $importInhibitedMessages = []; |
||
| 218 | if ($import->loadFile($inFile->getForLocalProcessing(false), 1)) { |
||
| 219 | $importInhibitedMessages = $import->checkImportPrerequisites(); |
||
| 220 | if ($inData['import_file']) { |
||
| 221 | if (empty($importInhibitedMessages)) { |
||
| 222 | $import->importData($this->id); |
||
| 223 | BackendUtility::setUpdateSignal('updatePageTree'); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | $import->display_import_pid_record = $this->pageinfo; |
||
| 227 | $this->standaloneView->assign('contentOverview', $import->displayContentOverview()); |
||
| 228 | } |
||
| 229 | // Compile messages which are inhibiting a proper import and add them to output. |
||
| 230 | if (!empty($importInhibitedMessages)) { |
||
| 231 | $flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)->getMessageQueueByIdentifier('impexp.errors'); |
||
| 232 | foreach ($importInhibitedMessages as $message) { |
||
| 233 | $flashMessageQueue->addMessage(GeneralUtility::makeInstance( |
||
| 234 | FlashMessage::class, |
||
| 235 | $message, |
||
| 236 | '', |
||
| 237 | FlashMessage::ERROR |
||
| 238 | )); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | $this->standaloneView->assign('errors', $import->errorLog); |
||
| 245 | } |
||
| 338 |