ImportSource: take over modifier loading logic
This commit is contained in:
parent
8d2f546a2e
commit
38bf19eb92
|
@ -76,24 +76,10 @@ class ImportsourceHookTable extends QuickTable
|
|||
|
||||
protected function applyModifiers()
|
||||
{
|
||||
$modifiers = $this->source->fetchRowModifiers();
|
||||
if (empty($modifiers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$propertyModifiers = array();
|
||||
|
||||
|
||||
foreach ($modifiers as $mod) {
|
||||
if (! array_key_exists($mod->property_name, $propertyModifiers)) {
|
||||
$propertyModifiers[$mod->property_name] = array();
|
||||
}
|
||||
|
||||
$propertyModifiers[$mod->property_name][] = $mod->getInstance();
|
||||
}
|
||||
$modifiers = $this->source->getRowModifiers();
|
||||
|
||||
foreach ($this->dataCache as & $row) {
|
||||
foreach ($propertyModifiers as $key => $mods) {
|
||||
foreach ($modifiers as $key => $mods) {
|
||||
foreach ($mods as $mod) {
|
||||
if (is_array($row->$key)) {
|
||||
foreach ($row->$key as & $k) {
|
||||
|
|
|
@ -26,28 +26,9 @@ abstract class PropertyModifierHook
|
|||
return $class;
|
||||
}
|
||||
|
||||
public static function loadById($property_id, Db $connection)
|
||||
public function getTargetProperty()
|
||||
{
|
||||
$db = $connection->getDbAdapter();
|
||||
$modifier = $db->fetchRow(
|
||||
$db->select()->from(
|
||||
'import_row_modifier',
|
||||
array('id', 'provider_class')
|
||||
)->where('property_id = ?', $property_id)
|
||||
);
|
||||
|
||||
$settings = $db->fetchPairs(
|
||||
$db->select()->from(
|
||||
'import_row_modifier_settings',
|
||||
array('setting_name', 'setting_value')
|
||||
)->where('modifier_id = ?', $modifier->id)
|
||||
);
|
||||
|
||||
$obj = new $modifier->provider_class;
|
||||
$obj->setSettings($settings);
|
||||
$obj->setDb($db);
|
||||
|
||||
return $obj;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setDb(Db $db)
|
||||
|
|
|
@ -166,7 +166,7 @@ class Import
|
|||
)->fetchData();
|
||||
}
|
||||
|
||||
$modifiers = $this->prepareModifiers();
|
||||
$modifiers = $this->source->getRowModifiers();
|
||||
|
||||
if (empty($modifiers)) {
|
||||
return $this->data;
|
||||
|
@ -224,23 +224,6 @@ class Import
|
|||
return $this->properties[$checksum];
|
||||
}
|
||||
|
||||
// TODO: move to ImportSource, this duplicates logic from preview
|
||||
protected function prepareModifiers()
|
||||
{
|
||||
$modifiers = $this->source->fetchRowModifiers();
|
||||
$propertyModifiers = array();
|
||||
|
||||
foreach ($modifiers as $mod) {
|
||||
if (! array_key_exists($mod->property_name, $propertyModifiers)) {
|
||||
$propertyModifiers[$mod->property_name] = array();
|
||||
}
|
||||
|
||||
$propertyModifiers[$mod->property_name][] = $mod->getInstance();
|
||||
}
|
||||
|
||||
return $propertyModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk through each row, prepare properties and calculate checksums
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,8 @@ class ImportSource extends DbObjectWithSettings
|
|||
|
||||
protected $settingsRemoteId = 'source_id';
|
||||
|
||||
private $rowModifiers;
|
||||
|
||||
public function fetchLastRun($required = false)
|
||||
{
|
||||
return $this->fetchLastRunBefore(time() + 1, $required);
|
||||
|
@ -75,6 +77,15 @@ class ImportSource extends DbObjectWithSettings
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getRowModifiers()
|
||||
{
|
||||
if ($this->rowModifiers === null) {
|
||||
$this->prepareRowModifiers();
|
||||
}
|
||||
|
||||
return $this->rowModifiers;
|
||||
}
|
||||
|
||||
public function fetchRowModifiers()
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
@ -87,6 +98,21 @@ class ImportSource extends DbObjectWithSettings
|
|||
);
|
||||
}
|
||||
|
||||
protected function prepareRowModifiers()
|
||||
{
|
||||
$modifiers = array();
|
||||
|
||||
foreach ($this->fetchRowModifiers() as $mod) {
|
||||
if (! array_key_exists($mod->property_name, $modifiers)) {
|
||||
$modifiers[$mod->property_name] = array();
|
||||
}
|
||||
|
||||
$modifiers[$mod->property_name][] = $mod->getInstance();
|
||||
}
|
||||
|
||||
$this->rowModifiers = $modifiers;
|
||||
}
|
||||
|
||||
public function checkForChanges($runImport = false)
|
||||
{
|
||||
$hadChanges = false;
|
||||
|
|
Loading…
Reference in New Issue