protected function processColumns($params)
 {
     $completionPosition = 1;
     if (!isset($params["columnNameToProcess"])) {
         $params["columnNameToProcess"] = $this->getNextMappedColumnName($this->mappingData);
     } else {
         assert('is_string($params["columnNameToProcess"])');
     }
     $completionPosition = array_search($params["columnNameToProcess"], $this->sanitizableColumnNames) + 1;
     if ($completionPosition != count($this->sanitizableColumnNames)) {
         $completionPosition++;
     }
     $this->subSequenceCompletionPercentage = $completionPosition / count($this->sanitizableColumnNames) * 100;
     //Run data analyzer
     if ($this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType'] == null) {
         throw new NotSupportedException();
     }
     $importDataAnalyzer = new ImportDataAnalyzer($this->importRules, $this->dataProvider);
     $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($params["columnNameToProcess"], $this->mappingData[$params["columnNameToProcess"]]);
     $messagesData = $importDataAnalyzer->getMessagesData();
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $unserializedData = unserialize($this->import->serializedData);
     $unserializedData['mappingData'] = ImportMappingUtil::resolveImportInstructionsDataIntoMappingData($this->mappingData, $importInstructionsData);
     $this->import->serializedData = serialize($unserializedData);
     ImportUtil::setDataAnalyzerMessagesDataToImport($this->import, $messagesData, true);
     $saved = $this->import->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $nextColumnName = $this->getNextMappedColumnName($this->mappingData, $params['columnNameToProcess']);
     if ($nextColumnName == null) {
         $this->nextStep = null;
         $this->nextMessage = null;
         $this->complete = true;
         return null;
     } else {
         $params['columnNameToProcess'] = $nextColumnName;
         $this->nextStep = 'processColumns';
         $this->setNextMessageByStep($this->nextStep);
         $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRules->getType(), $this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType']);
         $this->nextMessage .= ' ' . $attributeImportRules->getDisplayLabel();
         return $params;
     }
 }
 /**
  * @depends testImportDataAnalysisResultsForMultiSelectMissingMappingRuleForm
  */
 public function testImportDataAnalysisResults()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     R::exec("update " . $import->getTempTableName() . " set column_8 = " . Yii::app()->user->userModel->id . " where id != 1 limit 4");
     $externalSystemIdColumnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     //Add test ImportModelTestItem models for use in this test.
     $importModelTestItemModel1 = ImportTestHelper::createImportModelTestItem('aaa', 'aba');
     $importModelTestItemModel2 = ImportTestHelper::createImportModelTestItem('ddw', 'daf');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_10 = " . $importModelTestItemModel1->id . " where id != 1 limit 3");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem::getTableName('ImportModelTestItem') . " set {$externalSystemIdColumnName} = 'B' where id = {$importModelTestItemModel2->id}");
     //Add test ImportModelTestItem2 models for use in this test.
     $importModelTestItem2Model1 = ImportTestHelper::createImportModelTestItem2('aaa');
     $importModelTestItem2Model2 = ImportTestHelper::createImportModelTestItem2('bbb');
     $importModelTestItem2Model3 = ImportTestHelper::createImportModelTestItem2('ccc');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping.
     R::exec("update " . $import->getTempTableName() . " set column_14 = " . $importModelTestItem2Model1->id . " where id != 1 limit 4");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem2::getTableName('ImportModelTestItem2') . " set {$externalSystemIdColumnName} = 'B' where id = {$importModelTestItem2Model2->id}");
     //Add test ImportModelTestItem3 models for use in this test.
     $importModelTestItem3Model1 = ImportTestHelper::createImportModelTestItem3('aaa');
     $importModelTestItem3Model2 = ImportTestHelper::createImportModelTestItem3('dd');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_17 = " . $importModelTestItem3Model1->id . " where id != 1 limit 3");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem3::getTableName('ImportModelTestItem3') . " set {$externalSystemIdColumnName} = 'K' where id = {$importModelTestItem3Model2->id}");
     //Add test ImportModelTestItem4 models for use in this test.
     $importModelTestItem4Model1 = ImportTestHelper::createImportModelTestItem4('aaa');
     $importModelTestItem4Model2 = ImportTestHelper::createImportModelTestItem4('dd');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_12 = " . $importModelTestItem4Model1->id . " where id != 1 limit 5");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem3::getTableName('ImportModelTestItem4') . " set {$externalSystemIdColumnName} = 'J' where id = {$importModelTestItem4Model2->id}");
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'phone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'float', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_3' => array('attributeIndexOrDerivedType' => 'boolean', 'type' => 'importColumn'), 'column_4' => array('attributeIndexOrDerivedType' => 'date', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null), 'ValueFormatMappingRuleForm' => array('format' => 'MM-dd-yyyy'))), 'column_5' => array('attributeIndexOrDerivedType' => 'dateTime', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null), 'ValueFormatMappingRuleForm' => array('format' => 'MM-dd-yyyy hh:mm'))), 'column_6' => array('attributeIndexOrDerivedType' => 'dropDown', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_7' => array('attributeIndexOrDerivedType' => 'createdByUser', 'type' => 'importColumn', 'mappingRulesData' => array('UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME))), 'column_8' => array('attributeIndexOrDerivedType' => 'modifiedByUser', 'type' => 'importColumn', 'mappingRulesData' => array('UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID))), 'column_9' => array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID))), 'column_10' => array('attributeIndexOrDerivedType' => 'id', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_11' => array('attributeIndexOrDerivedType' => 'id', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_12' => array('attributeIndexOrDerivedType' => 'hasOneAlso', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_13' => array('attributeIndexOrDerivedType' => 'hasOneAlso', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_14' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_15' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_16' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME))), 'column_17' => array('attributeIndexOrDerivedType' => 'ImportModelTestItem3Derived', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_18' => array('attributeIndexOrDerivedType' => 'ImportModelTestItem3Derived', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_19' => array('attributeIndexOrDerivedType' => 'url', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_20' => array('attributeIndexOrDerivedType' => 'textArea', 'type' => 'importColumn'), 'column_21' => array('attributeIndexOrDerivedType' => 'integer', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_22' => array('attributeIndexOrDerivedType' => 'currencyValue', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_23' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_24' => array('attributeIndexOrDerivedType' => 'multiDropDown', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_25' => array('attributeIndexOrDerivedType' => 'tagCloud', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem');
     $config = array('pagination' => array('pageSize' => 2));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider);
     foreach ($mappingData as $columnName => $columnMappingData) {
         $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData);
     }
     $messagesData = $importDataAnalyzer->getMessagesData();
     $compareData = array('column_0' => array(array('message' => '1 value(s) are too short for this field. These rows will be skipped during import.', 'sanitizerUtilType' => 'MinimumLength', 'moreAvailable' => false), array('message' => '1 value(s) are too large for this field. These values will be truncated to a length of 64 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false), array('message' => '1 value(s) are missing and are required. These rows will be skipped on import.', 'sanitizerUtilType' => 'Required', 'moreAvailable' => false)), 'column_1' => array(array('message' => '2 value(s) are too large for this field. These values will be truncated to a length of 14 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_2' => array(array('message' => '2 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_3' => array(array('message' => '2 value(s) have invalid check box values. These values will be set to false upon import.', 'sanitizerUtilType' => 'Boolean', 'moreAvailable' => false)), 'column_4' => array(array('message' => '2 value(s) have invalid date formats. These values will be cleared during import.', 'sanitizerUtilType' => 'Date', 'moreAvailable' => false)), 'column_5' => array(array('message' => '2 value(s) have invalid date time formats. These values will be cleared during import.', 'sanitizerUtilType' => 'DateTime', 'moreAvailable' => false)), 'column_6' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'DropDown', 'moreAvailable' => false)), 'column_7' => array(array('message' => '2 username(s) specified were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false)), 'column_8' => array(array('message' => '1 zurmo user id(s) across 7 row(s) were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false)), 'column_9' => array(array('message' => '2 external system user id(s) specified were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false), array('message' => '1 value(s) are missing and are required. These rows will be skipped on import.', 'sanitizerUtilType' => 'ModelIdRequired', 'moreAvailable' => false)), 'column_10' => array(array('message' => '3 record(s) will be updated and 9 record(s) will be skipped during import.', 'sanitizerUtilType' => 'SelfIdValueType', 'moreAvailable' => false)), 'column_11' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be created during the import.', 'sanitizerUtilType' => 'SelfIdValueType', 'moreAvailable' => false)), 'column_12' => array(array('message' => '5 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ModelIdValueType', 'moreAvailable' => false)), 'column_13' => array(array('message' => '2 record(s) will be updated and 10 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ModelIdValueType', 'moreAvailable' => false)), 'column_14' => array(array('message' => '4 record(s) will be updated and 8 record(s) will be skipped during import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_15' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be skipped during import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_16' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be created during the import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_17' => array(array('message' => '3 record(s) will be updated and 9 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ImportModelTestItem3DerivedIdValueType', 'moreAvailable' => false)), 'column_18' => array(array('message' => '2 record(s) will be updated and 10 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ImportModelTestItem3DerivedIdValueType', 'moreAvailable' => false)), 'column_19' => array(array('message' => '1 value(s) have urls that are invalid. These values will be cleared during import.', 'sanitizerUtilType' => 'Url', 'moreAvailable' => false)), 'column_21' => array(array('message' => '1 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_22' => array(array('message' => '1 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_23' => array(array('message' => '1 value(s) are too large for this field. These rows will be skipped during import.', 'sanitizerUtilType' => 'FullName', 'moreAvailable' => false)), 'column_24' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'MultiSelectDropDown', 'moreAvailable' => false)), 'column_25' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'MultiSelectDropDown', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array('column_6' => array('DropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('neverpresent', 'notpresent'))));
     $compareInstructionsData['column_24'] = array('MultiSelectDropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('Multi 5', 'Multi 4')));
     $compareInstructionsData['column_25'] = array('MultiSelectDropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('Cloud 5', 'Cloud 4')));
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
     ImportUtil::setDataAnalyzerMessagesDataToImport($import, $messagesData);
     $compareData = unserialize($import->serializedData);
     $compareData = $compareData['dataAnalyzerMessagesData'];
     $this->assertEquals($compareData, $messagesData);
     $newMappingData = ImportMappingUtil::resolveImportInstructionsDataIntoMappingData($mappingData, $importInstructionsData);
     $compareMappingData = $mappingData;
     $compareMappingData['column_6']['importInstructionsData'] = $compareInstructionsData['column_6'];
     $compareMappingData['column_24']['importInstructionsData'] = $compareInstructionsData['column_24'];
     $compareMappingData['column_25']['importInstructionsData'] = $compareInstructionsData['column_25'];
     $this->assertEquals($compareMappingData, $newMappingData);
 }
Beispiel #3
0
 /**
  * @depends testImportNameAndRelatedNameWithApostrophes
  */
 public function testSetDataAnalyzerMessagesDataToImport()
 {
     $import = new Import();
     ImportUtil::setDataAnalyzerMessagesDataToImport($import, array('a' => 'b'));
     $unserializedData = unserialize($import->serializedData);
     $this->assertEquals(array('a' => 'b'), $unserializedData['dataAnalyzerMessagesData']);
     //Test that setting it again wipes out the old value
     ImportUtil::setDataAnalyzerMessagesDataToImport($import, array('d' => 'e'));
     $unserializedData = unserialize($import->serializedData);
     $this->assertEquals(array('d' => 'e'), $unserializedData['dataAnalyzerMessagesData']);
     //Test that setting it with merge = true, merges with the existing value.
     ImportUtil::setDataAnalyzerMessagesDataToImport($import, array('k' => 'j'), true);
     $unserializedData = unserialize($import->serializedData);
     $this->assertEquals(array('d' => 'e', 'k' => 'j'), $unserializedData['dataAnalyzerMessagesData']);
 }