public function process(ResponseHelper $helper) { if ($this->request->isPost()) { $importRows = $this->importFile->getData(); $inputRows = []; $fields = $this->getFields()->getEditableFields(); foreach ($importRows as $row) { $data = []; foreach ($fields as $field) { $id = $field->getId(); $modeId = $id . ':mode'; $mode = $this->request->getPost($modeId); $data[$id] = $this->getFieldValue($id, $mode, $row); } $inputRows[] = $data; } if ($this->isValid($fields, $importRows, $inputRows)) { $this->save($inputRows); $count = count($importRows); $helper->setSuccessMessage("Successfully imported {$count} {$this->getPluralTitle()}.")->redirectToAdminPage('index'); } } }
public function process(ResponseHelper $helper) { if ($this->request->isPost()) { $inputFilter = ImportInputFilterFactory::createInstance(); $inputFilter->setData($_FILES); if (!$inputFilter->isValid() || !is_uploaded_file($_FILES['file']['tmp_name'])) { $this->validationMessages = $inputFilter->getMessages(); } else { $file = ImportFile::fromUploadedFile($_FILES['file'], $this->getUploadPath(), $this->request->getPost('first_row_is_headers')); $gateway = new DbGateway(); $id = $gateway->insert(['component' => $this->component->getFullyQualifiedName(), 'full_path' => $file->getFullPath(), 'first_row_is_headers' => (int) $this->request->getPost('first_row_is_headers')]); $helper->setSuccessMessage('Import file successfully uploaded.')->redirectToAdminPage('import-map-fields', ['id' => $id]); } } }