Import/Sync: cleanly rollback transactions
Helps to avoid side-effects
This commit is contained in:
parent
31e1b27628
commit
7cf1af15cb
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Icinga\Module\Director\Import;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Module\Director\Hook\ImportSourceHook;
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
|
@ -322,6 +323,8 @@ class Import
|
|||
|
||||
$db->beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
if ($this->isEmpty()) {
|
||||
$newRows = array();
|
||||
$newProperties = array();
|
||||
|
@ -359,6 +362,10 @@ class Import
|
|||
$db->commit();
|
||||
|
||||
$this->rowsetExists = true;
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Icinga\Module\Director\Import;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
|
@ -685,6 +686,8 @@ class Sync
|
|||
$db = $this->db;
|
||||
$dba = $db->getDbAdapter();
|
||||
$dba->beginTransaction();
|
||||
|
||||
try {
|
||||
$formerActivityChecksum = Util::hex2binary(
|
||||
$db->getLastActivityChecksum()
|
||||
);
|
||||
|
@ -742,6 +745,11 @@ class Sync
|
|||
(microtime(true) - $this->runStartTime) * 1000
|
||||
))->store();
|
||||
|
||||
} catch (Exception $e) {
|
||||
$dba->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->run->id;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue