Import/Sync: cleanly rollback transactions

Helps to avoid side-effects
This commit is contained in:
Thomas Gelf 2016-06-28 12:56:53 +02:00
parent 31e1b27628
commit 7cf1af15cb
2 changed files with 102 additions and 87 deletions

View File

@ -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;
}
}
/**

View File

@ -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;
}
}