Index: trunk/core/units/general/cat_dbitem_export.php =================================================================== diff -u -r3648 -r3698 --- trunk/core/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 3648) +++ trunk/core/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 3698) @@ -170,7 +170,25 @@ $object->setError('ExportColumns', 'required'); $ret = false; } + else { + // 1.1. check that all required fields are present in imported file + $missing_columns = Array(); + foreach ($object->Fields as $field_name => $field_options) { + if ($object->SkipField($field_name)) continue; + if (getArrayValue($field_options, 'required') && !in_array($field_name, $this->exportOptions['ExportColumns']) ) { + $missing_columns[] = $field_name; + $object->setError('ExportColumns', 'required_fields_missing', 'la_error_RequiredColumnsMissing'); + $ret = false; + } + } + + if (!$ret) { + $this->Application->Debugger->appendHTML('Missing required for import/export:'); + $this->Application->Debugger->dumpVars($missing_columns); + } + } + // 2. check, that we have only mixed category field or only separated category fields $category_found['mixed'] = false; $category_found['separated'] = false; @@ -372,6 +390,8 @@ $records_exported = 0; foreach ($records as $record_info) { $this->curItem->SetDBFieldsFromHash($record_info); + $this->setCurrentID(); + $this->curItem->raiseEvent('OnAfterItemLoad', $this->curItem->GetID() ); if ($this->hasCustomFields) { $this->loadItemCustomFields(); @@ -415,7 +435,7 @@ $field_name = preg_replace('/^Category(Path|[0-9]+)/', '__CATEGORY__Category\\1', $field_name); $valid_fields = $object->getPossibleExportColumns(); - return isset($valid_fields[$field_name]); + return isset($valid_fields[$field_name]) || isset($valid_fields['__VIRTUAL__'.$field_name]); } /** @@ -471,10 +491,11 @@ $this->customValues = Array(); $data = $this->readRecord(); if ($data) { + $this->curItem->Clear(); foreach ($data as $field_index => $field_value) { $this->setFieldValue($field_index, $field_value); } - $this->curItem->setID( $this->curItem->GetDBField($this->curItem->IDField) ); + $this->setCurrentID(); $this->processCurrentItem($event); } $bytes_imported = ftell($this->filePointer) - $this->exportOptions['start_from']; @@ -490,6 +511,11 @@ return $this->exportOptions; } + function setCurrentID() + { + $this->curItem->setID( $this->curItem->GetDBField($this->curItem->IDField) ); + } + function setFieldValue($field_index, $value) { $field_name = $this->exportFields[$field_index]; @@ -499,11 +525,15 @@ $this->customValues[$field_name] = $value; } elseif ($field_name == 'CategoryPath') { - $this->curItem->CategoryPath = explode($this->exportOptions['CategorySeparator'], $value); + $this->curItem->CategoryPath = $value ? explode($this->exportOptions['CategorySeparator'], $value) : Array(); } elseif (substr($field_name, 0, 8) == 'Category') { $this->curItem->CategoryPath[ (int)substr($field_name, 8) ] = $value; } + elseif (substr($field_name, 0, 11) == '__VIRTUAL__') { + $field_name = substr($field_name, 11); + $this->curItem->SetField($field_name, $value); + } else { $this->curItem->SetField($field_name, $value); } @@ -517,7 +547,7 @@ */ function &getTempItem(&$event) { - return $this->Application->recallObject($event->Prefix.'.-tmpitem', $event->Prefix, Array('skip_autoload' => true)); + return $this->Application->recallObject($event->Prefix.'.-tmpitem'.$event->Special, $event->Prefix, Array('skip_autoload' => true)); } /** @@ -701,6 +731,9 @@ { return $this->getCategoryTitle(); } + elseif (substr($field, 0, 11) == '__VIRTUAL__') { + $ret = substr($field, 11); + } else { $ret = $field; @@ -717,15 +750,17 @@ */ function getFieldValue($field) { - if (substr($field, 0, 10) == '__CUSTOM__') - { + if (substr($field, 0, 10) == '__CUSTOM__') { $field = substr($field, 10, strlen($field) ); $ret = isset($this->customValues[$field]) ? $this->customValues[$field] : ''; } - elseif (substr($field, 0, 12) == '__CATEGORY__') - { + elseif (substr($field, 0, 12) == '__CATEGORY__') { return $this->getCategoryPath(); } + elseif (substr($field, 0, 11) == '__VIRTUAL__') { + $field = substr($field, 11); + return $this->curItem->GetField($field); + } else { $ret = $this->curItem->GetField($field); @@ -742,16 +777,15 @@ */ function getCategoryTitle() { + // category path in separated fields + $category_count = $this->getMaxCategoryLevel(); if ($this->exportOptions['CategoryFormat'] == 1) { // category path in one field - return Array('CategoryPath'); + return $category_count ? Array('CategoryPath') : Array(); } else { - // category path in separated fields - $category_count = $this->getMaxCategoryLevel(); - $i = 0; $ret = Array(); while ($i < $category_count) { @@ -787,13 +821,13 @@ } } + $category_count = $this->getMaxCategoryLevel(); if ($this->exportOptions['CategoryFormat'] == 1) { // category path in single field - $category_path = Array( implode($this->exportOptions['CategorySeparator'], $category_path) ); + $category_path = $category_count ? Array( implode($this->exportOptions['CategorySeparator'], $category_path) ) : Array(); } else { // category path in separated fields - $category_count = $this->getMaxCategoryLevel(); $levels_used = count($category_path); if ($levels_used < $category_count) {