/** * Step 2. Upload the csv to import. */ public function actionStep2($id) { $import = Import::getById((int) $id); $importWizardForm = ImportWizardUtil::makeFormByImport($import); if (isset($_POST[get_class($importWizardForm)])) { ImportWizardUtil::setFormByPostForStep2($importWizardForm, $_POST[get_class($importWizardForm)]); if ($importWizardForm->fileUploadData == null) { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'A file must be uploaded in order to continue the import process.')); } elseif (!ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import)) { if ($importWizardForm->firstRowIsHeaderRow) { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'The file that has been uploaded only has a header row and no additional rows to import.')); } else { $importWizardForm->addError('fileUploadData', Zurmo::t('ImportModule', 'A file must be uploaded with at least one row to import.')); } } else { $importRulesClassName = $importWizardForm->importRulesType . 'ImportRules'; if (!is_subclass_of($importRulesClassName::getModelClassName(), 'SecurableItem')) { $nextStep = 'step4'; } else { $nextStep = 'step3'; } $this->attemptToValidateImportWizardFormAndSave($importWizardForm, $import, $nextStep); } } $title = Zurmo::t('ImportModule', 'Import Wizard - Upload File'); $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType); $progressBarAndStepsView = new ImportStepsAndProgressBarForWizardView($importRulesClassName, 1); $importView = new ImportWizardUploadFileView($this->getId(), $this->getModule()->getId(), $importWizardForm, $title); echo $this->getImportPageView($progressBarAndStepsView, $importView)->render(); }
/** * @depends testSetFormByPostForStep2 */ public function testImportFileHasAtLeastOneImportRow() { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $import->serializedData = serialize(array()); $this->assertTrue($import->save()); $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('headerRowOnlyImportTest.csv', $import->getTempTableName(), true)); $importWizardForm = new ImportWizardForm(); $this->assertTrue(ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import)); //Now set that the first row is a header row and the check will fail. $importWizardForm->firstRowIsHeaderRow = true; $this->assertFalse(ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import)); ZurmoRedBean::$writer->dropTableByTableName($import->getTempTableName()); }