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]); } } }
protected function save(array $inputRows) { $rowEditor = $this->getRowEditor(); foreach ($inputRows as $inputData) { $this->initializeRowEditor($rowEditor); /** * Not ideal, but we call isValid() a second time here to ensure the row editor * is populated with the data from each import row. isValid() does this population * in part because the input filter is needed to filter values before population. */ $rowEditor->isValid($inputData); $rowEditor->save(); $primaryRow = $rowEditor->getRow($this->getPrimaryRowName()); $primaryName = current($primaryRow->getTable()->getPrimaryKey()); $primaryValue = $primaryRow->get($primaryName); $this->importGateway->insertFile(['dewdrop_import_file_id' => $this->request->getQuery('id'), 'record_primary_key_value' => $primaryValue]); } return $this; }