Permalink
Browse files

bugfix where fields that weren't used would become empty upon importing

  • Loading branch information...
1 parent a0a14bc commit 6de73f8cf682e03bb86905b032e1d824c15a9e47 @kanduvisla kanduvisla committed Jul 15, 2011
Showing with 48 additions and 47 deletions.
  1. +48 −47 content/content.index.php
View
@@ -76,9 +76,8 @@ private function __indexPage()
private function __getCSV()
{
$cache = new Cacheable(Symphony::Database());
- $data = $cache->check('importcsv');
- if($data != false)
- {
+ $data = $cache->check('importcsv');
+ if ($data != false) {
return unserialize($data['data']);
} else {
return false;
@@ -159,7 +158,7 @@ private function __importStep3Page()
$ids = array();
foreach ($csvTitles as $title)
{
- $ids[] = $_POST['field-'. $i];
+ $ids[] = $_POST['field-' . $i];
$i++;
}
$this->__addVar('field-ids', implode(',', $ids));
@@ -203,8 +202,7 @@ private function __ajaxImportRows()
$ignored = array();
$csv = $this->__getCSV();
- if($csv != false)
- {
+ if ($csv != false) {
// Load the drivers:
$drivers = $this->getDrivers();
@@ -219,6 +217,9 @@ private function __ajaxImportRows()
// Load the fieldmanager:
$fm = new FieldManager($this);
+ // Load the entrymanager:
+ $em = new EntryManager($this);
+
// Load the CSV data of the specific rows:
$csvTitles = $csv->titles;
$csvData = $csv->data;
@@ -227,21 +228,21 @@ private function __ajaxImportRows()
// Start by creating a new entry:
$entry = new Entry($this);
$entry->set('section_id', $sectionID);
-
+
+ // Ignore this entry?
+ $ignore = false;
+
// Import this row:
$row = $csvData[$i];
- if($row != false)
- {
+ if ($row != false) {
// If a unique field is used, make sure there is a field selected for this:
- if($uniqueField != 'no' && $fieldIDs[$uniqueField] == 0)
- {
+ if ($uniqueField != 'no' && $fieldIDs[$uniqueField] == 0) {
die(__('[ERROR: No field id sent for: "' . $csvTitles[$uniqueField] . '"]'));
}
// Unique action:
- if($uniqueField != 'no')
- {
+ if ($uniqueField != 'no') {
// Check if there is an entry with this value:
$field = $fm->fetch($fieldIDs[$uniqueField]);
$type = $field->get('type');
@@ -259,63 +260,63 @@ private function __ajaxImportRows()
{
case 'update' :
{
- $entry->set('id', $entryID);
+ $a = $em->fetch($entryID);
+ $entry = $a[0];
$updated[] = $entryID;
break;
}
case 'ignore' :
{
$ignored[] = $entryID;
+ $ignore = true;
break;
}
}
}
}
- // Do the actual importing:
- $j = 0;
- foreach ($row as $value)
- {
- // When no unique field is found, treat it like a new entry
- // Otherwise, stop processing to safe CPU power.
- $fieldID = intval($fieldIDs[$j]);
- // If $fieldID = 0, then `Don't use` is selected as field. So don't use it! :-P
- if($fieldID != 0)
+ if (!$ignore) {
+ // Do the actual importing:
+ $j = 0;
+ foreach ($row as $value)
{
- $field = $fm->fetch($fieldID);
- // Get the corresponding field-type:
- $type = $field->get('type');
- if (isset($drivers[$type])) {
- $drivers[$type]->setField($field);
- $data = $drivers[$type]->import($value, $entryID);
- } else {
- $drivers['default']->setField($field);
- $data = $drivers['default']->import($value, $entryID);
- }
- // Set the data:
- if ($data != false) {
- $entry->setData($fieldID, $data);
+ // When no unique field is found, treat it like a new entry
+ // Otherwise, stop processing to safe CPU power.
+ $fieldID = intval($fieldIDs[$j]);
+ // If $fieldID = 0, then `Don't use` is selected as field. So don't use it! :-P
+ if ($fieldID != 0) {
+ $field = $fm->fetch($fieldID);
+ // Get the corresponding field-type:
+ $type = $field->get('type');
+ if (isset($drivers[$type])) {
+ $drivers[$type]->setField($field);
+ $data = $drivers[$type]->import($value, $entryID);
+ } else {
+ $drivers['default']->setField($field);
+ $data = $drivers['default']->import($value, $entryID);
+ }
+ // Set the data:
+ if ($data != false) {
+ $entry->setData($fieldID, $data);
+ }
}
+ $j++;
}
- $j++;
- }
-
- // Store the entry:
- $entry->commit();
+ // Store the entry:
+ $entry->commit();
+ }
}
}
} else {
die(__('[ERROR: CSV Data not found!]'));
}
- if(count($updated) > 0)
- {
- $messageSuffix .= ' '.__('(updated: ').implode(', ', $updated).')';
+ if (count($updated) > 0) {
+ $messageSuffix .= ' ' . __('(updated: ') . implode(', ', $updated) . ')';
}
- if(count($ignored) > 0)
- {
- $messageSuffix .= ' '.__('(ignored: ').implode(', ', $updated).')';
+ if (count($ignored) > 0) {
+ $messageSuffix .= ' ' . __('(ignored: ') . implode(', ', $updated) . ')';
}
die('[OK]' . $messageSuffix);

0 comments on commit 6de73f8

Please sign in to comment.