From 29b37a815dc31c51294a24df0b903f01e5b2d268 Mon Sep 17 00:00:00 2001 From: David Maack Date: Tue, 16 Apr 2013 16:05:00 +0200 Subject: [PATCH 1/4] Fixed claculation of missing keys in target Table --- system/modules/tabimporter/Tabimporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/modules/tabimporter/Tabimporter.php b/system/modules/tabimporter/Tabimporter.php index e820c64..b8d9eea 100644 --- a/system/modules/tabimporter/Tabimporter.php +++ b/system/modules/tabimporter/Tabimporter.php @@ -438,7 +438,7 @@ public function runStep($intStep, $line=false) // delete data missing in target, but existing in the source table elseif(in_array('missing',$arrTableimport['deleteOnStart']) && is_array($arrTableimport['existentKeysSource']) && is_array($arrTableimport['existentKeysTarget'])) { - $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrTableimport['existentKeysSource']); + $arrToDelete=array_diff($arrTableimport['existentKeysSource'],$arrTableimport['existentKeysTarget']); if(count($arrToDelete>0)) { $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); From d0d5e804ac74dbe978890bd84d5d1b0b0957502d Mon Sep 17 00:00:00 2001 From: David Maack Date: Tue, 16 Apr 2013 16:06:07 +0200 Subject: [PATCH 2/4] Fixed wrong brackets in count statement --- system/modules/tabimporter/Tabimporter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/modules/tabimporter/Tabimporter.php b/system/modules/tabimporter/Tabimporter.php index b8d9eea..6940f20 100644 --- a/system/modules/tabimporter/Tabimporter.php +++ b/system/modules/tabimporter/Tabimporter.php @@ -439,7 +439,7 @@ public function runStep($intStep, $line=false) elseif(in_array('missing',$arrTableimport['deleteOnStart']) && is_array($arrTableimport['existentKeysSource']) && is_array($arrTableimport['existentKeysTarget'])) { $arrToDelete=array_diff($arrTableimport['existentKeysSource'],$arrTableimport['existentKeysTarget']); - if(count($arrToDelete>0)) + if(count($arrToDelete)>0) { $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, @@ -470,7 +470,7 @@ public function runStep($intStep, $line=false) { $arrNotExistent=array_diff($arrTableimport['existentKeysSource'],$arrTableimport['existentKeysTarget']); $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrNotExistent); - if(count($arrToDelete>0)) + if(count($arrToDelete)>0) { $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, From d21ca1b3deaa09ffc8c9292f045f5859ca3e4fbf Mon Sep 17 00:00:00 2001 From: David Maack Date: Tue, 16 Apr 2013 16:08:33 +0200 Subject: [PATCH 3/4] Added 'field_' to array-keys when reading a csv without field names in the first row. --- .../tabimporter/TabimporterSource_csv.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/system/modules/tabimporter/TabimporterSource_csv.php b/system/modules/tabimporter/TabimporterSource_csv.php index 4d22ebe..a2cc4da 100644 --- a/system/modules/tabimporter/TabimporterSource_csv.php +++ b/system/modules/tabimporter/TabimporterSource_csv.php @@ -82,19 +82,24 @@ public function getAllData($arrTableimport) for($i=0;$i < sizeof($arrContent); $i++) { $arrContent[$i] = $this->String->splitCsv($arrContent[$i], $strDelimiter); - - // get field names ba first line - if($arrTableimport['hasFieldnames']) + $arrNewContent = array(); + + //skip first row with field names + if ($i == 0 && $arrTableimport['hasFieldnames']) continue; + + // get field names of first line or set key to field_x + for($ii=0;$ii0) - { - unset($arrContent[$i][$ii]); - } - } - } + $arrNewContent[$arrContent[0][$ii]] = $arrContent[$i][$ii]; + }else{ + $arrNewContent['field_'.$ii] = $arrContent[$i][$ii]; + } + } + + $arrContent[$i] = $arrNewContent; } @@ -126,7 +131,7 @@ public function getExistentKeysSource($arrTableimport) $arrKeys[] = $arrData[($arrTableimport['hasFieldnames'] ? $arrTableimport['uniqueSource'] : - str_replace('field_','',$arrTableimport['uniqueSource']))]; + $arrTableimport['uniqueSource'])]; } if(!$arrKeys || count($arrKeys)<1) From 86302a6c1519efc6ee55b1004adf0a11590a7df3 Mon Sep 17 00:00:00 2001 From: David Maack Date: Tue, 16 Apr 2013 17:25:02 +0200 Subject: [PATCH 4/4] fixed calculation of entries to delete. Also updated the retrieval of existing keys, now all entries are fetched and the list is not limited to entries of the source file. --- system/modules/tabimporter/Tabimporter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/modules/tabimporter/Tabimporter.php b/system/modules/tabimporter/Tabimporter.php index 6940f20..fa6a791 100644 --- a/system/modules/tabimporter/Tabimporter.php +++ b/system/modules/tabimporter/Tabimporter.php @@ -438,10 +438,10 @@ public function runStep($intStep, $line=false) // delete data missing in target, but existing in the source table elseif(in_array('missing',$arrTableimport['deleteOnStart']) && is_array($arrTableimport['existentKeysSource']) && is_array($arrTableimport['existentKeysTarget'])) { - $arrToDelete=array_diff($arrTableimport['existentKeysSource'],$arrTableimport['existentKeysTarget']); + $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrTableimport['existentKeysSource']); if(count($arrToDelete)>0) { - $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); + $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, $objSteps->title, sprintf($GLOBALS['TL_LANG']['tl_tabimporter']['missing_ok'],$arrTableimport['targetTable']), @@ -472,7 +472,7 @@ public function runStep($intStep, $line=false) $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrNotExistent); if(count($arrToDelete)>0) { - $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); + $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, $objSteps->title, sprintf($GLOBALS['TL_LANG']['tl_tabimporter']['existent_ok'],$arrTableimport['targetTable']), @@ -955,7 +955,7 @@ public function getExistentKeysTarget($arrTableimport) } else { - $objKeys = $this->Database->prepare("SELECT ".$arrTableimport['uniqueTarget']." FROM ".$arrTableimport['targetTable']." WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrTableimport['existentKeysSource'])."')") + $objKeys = $this->Database->prepare("SELECT ".$arrTableimport['uniqueTarget']." FROM ".$arrTableimport['targetTable']." ") ->executeUncached(); $arrKeys = $objKeys->fetchEach($arrTableimport['uniqueTarget']);