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