Merge remote-tracking branch 'origin/master'

This commit is contained in:
Thomas Gelf 2016-10-27 16:35:19 +00:00
commit e59e2d0c2c
3 changed files with 40 additions and 5 deletions

View File

@ -4,7 +4,7 @@ namespace Icinga\Module\Director\Import;
use Exception; use Exception;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Import\SyncUtils; use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaService;
@ -20,6 +20,11 @@ class Sync
*/ */
protected $rule; protected $rule;
/**
* @var Db
*/
protected $db;
/** /**
* Related ImportSource objects * Related ImportSource objects
* *
@ -63,6 +68,9 @@ class Sync
protected $syncProperties; protected $syncProperties;
/**
* @var SyncRun
*/
protected $run; protected $run;
protected $runStartTime; protected $runStartTime;
@ -72,6 +80,8 @@ class Sync
/** /**
* Constructor. No direct initialization allowed right now. Please use one * Constructor. No direct initialization allowed right now. Please use one
* of the available static factory methods * of the available static factory methods
*
* @param SyncRule $rule
*/ */
public function __construct(SyncRule $rule) public function __construct(SyncRule $rule)
{ {
@ -240,6 +250,7 @@ class Sync
$combinedKey = $this->rule->hasCombinedKey(); $combinedKey = $this->rule->hasCombinedKey();
foreach ($this->sources as $source) { foreach ($this->sources as $source) {
/** @var ImportSource $source */
$sourceId = $source->id; $sourceId = $source->id;
// Provide an alias column for our key. TODO: double-check this! // Provide an alias column for our key. TODO: double-check this!
@ -544,6 +555,8 @@ class Sync
$dba = $db->getDbAdapter(); $dba = $db->getDbAdapter();
$dba->beginTransaction(); $dba->beginTransaction();
$object = null;
try { try {
$formerActivityChecksum = Util::hex2binary( $formerActivityChecksum = Util::hex2binary(
$db->getLastActivityChecksum() $db->getLastActivityChecksum()
@ -604,7 +617,15 @@ class Sync
} catch (Exception $e) { } catch (Exception $e) {
$dba->rollBack(); $dba->rollBack();
throw $e; if ($object !== null && $object instanceof IcingaObject) {
throw new IcingaException(
'Exception while syncing %s %s: %s',
get_class($object), $object->get('object_name'), $e->getMessage(), $e
);
}
else {
throw $e;
}
} }
return $this->run->id; return $this->run->id;

View File

@ -401,7 +401,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
*/ */
public function setAssign_filter($filter) public function setAssign_filter($filter)
{ {
if (! $this->supportsAssignments()) { if (! $this->supportsAssignments() && $filter !== null) {
if ($this->hasProperty('object_type')) { if ($this->hasProperty('object_type')) {
$type = $this->object_type; $type = $this->object_type;
} else { } else {

View File

@ -98,14 +98,28 @@ class PlainObjectRenderer
return self::renderInteger($object); return self::renderInteger($object);
} elseif (is_float($object)) { } elseif (is_float($object)) {
return self::renderFloat($object); return self::renderFloat($object);
} elseif (is_object($object) || static::isAssocArray($object)) {
return self::renderHash($object, $prefix);
} elseif (is_array($object)) { } elseif (is_array($object)) {
return self::renderArray($object, $prefix); return self::renderArray($object, $prefix);
} elseif (is_object($object)) {
return self::renderHash($object, $prefix);
} elseif (is_string($object)) { } elseif (is_string($object)) {
return self::renderString($object); return self::renderString($object);
} else { } else {
return '(UNKNOWN TYPE) ' . var_export($object, 1); return '(UNKNOWN TYPE) ' . var_export($object, 1);
} }
} }
/**
* Check if an array contains assoc keys
*
* @from https://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
* @param $arr
* @return bool
*/
protected static function isAssocArray($arr)
{
if (! is_array($arr)) return false;
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}
} }