ImportSource: fix cloning

fixes #2005
fixes #1997
This commit is contained in:
Thomas Gelf 2019-11-05 16:49:59 +01:00
parent 13e217c725
commit 50315d8714
3 changed files with 10 additions and 6 deletions

View File

@ -125,6 +125,9 @@ class ImportsourceController extends ActionController
$this->addTitle('Clone: %s', $source->get('source_name')); $this->addTitle('Clone: %s', $source->get('source_name'));
$form = new CloneImportSourceForm($source); $form = new CloneImportSourceForm($source);
$this->content()->add($form); $this->content()->add($form);
$form->on(CloneImportSourceForm::ON_SUCCESS, function (CloneImportSourceForm $form) {
$this->getResponse()->redirectAndExit($form->getSuccessUrl());
});
$form->handleRequest($this->getServerRequest()); $form->handleRequest($this->getServerRequest());
} }

View File

@ -115,11 +115,11 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
public function setModifiers(array $modifiers) public function setModifiers(array $modifiers)
{ {
if ($this->loadedRowModifiers === null) { if ($this->loadedRowModifiers === null && $this->hasBeenLoadedFromDb()) {
$this->loadedRowModifiers = $this->fetchRowModifiers(); $this->loadedRowModifiers = $this->fetchRowModifiers();
} }
$current = $this->loadedRowModifiers; $current = $this->loadedRowModifiers;
if (count($current) !== count($modifiers)) { if ($current !== null && count($current) !== count($modifiers)) {
$this->newRowModifiers = $modifiers; $this->newRowModifiers = $modifiers;
} else { } else {
$i = 0; $i = 0;
@ -394,7 +394,6 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
public function fetchRowModifiers() public function fetchRowModifiers()
{ {
$db = $this->getDb(); $db = $this->getDb();
$modifiers = ImportRowModifier::loadAll( $modifiers = ImportRowModifier::loadAll(
$this->getConnection(), $this->getConnection(),
$db->select() $db->select()
@ -403,7 +402,11 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
->order('priority ASC') ->order('priority ASC')
); );
if ($modifiers) {
return $modifiers; return $modifiers;
} else {
return [];
}
} }
protected function fetchFlatRowModifiers() protected function fetchFlatRowModifiers()

View File

@ -52,13 +52,11 @@ class CloneImportSourceForm extends Form
$newName = $this->getElement('source_name')->getValue(); $newName = $this->getElement('source_name')->getValue();
$export->source_name = $newName; $export->source_name = $newName;
unset($export->originalId); unset($export->originalId);
if (ImportSource::existsWithName($newName, $this->source->getConnection())) { if (ImportSource::existsWithName($newName, $this->source->getConnection())) {
$this->getElement('source_name')->addMessage('Name already exists'); $this->getElement('source_name')->addMessage('Name already exists');
} }
$this->newSource = ImportSource::import($export, $this->getTargetDb()); $this->newSource = ImportSource::import($export, $this->getTargetDb());
$this->newSource->store(); $this->newSource->store();
$this->redirectOnSuccess();
} }
public function getSuccessUrl() public function getSuccessUrl()