mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
DbObject: Don't allow empty id for multi-column objects
This avoids that the user can actually create duplicate objects in the database. (E.g. for service templates)
This commit is contained in:
parent
76d0ed22e7
commit
0911910856
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Data\Db;
|
namespace Icinga\Module\Director\Data\Db;
|
||||||
|
|
||||||
|
use Icinga\Exception\IcingaException;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
||||||
@ -536,18 +537,22 @@ abstract class DbObject
|
|||||||
*
|
*
|
||||||
* // TODO: may conflict with ->id
|
* // TODO: may conflict with ->id
|
||||||
*
|
*
|
||||||
|
* @throws IcingaException When key can not be calculated
|
||||||
|
*
|
||||||
* @return string|array
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
// TODO: Doesn't work for array() / multicol key
|
|
||||||
if (is_array($this->keyName)) {
|
if (is_array($this->keyName)) {
|
||||||
$id = array();
|
$id = array();
|
||||||
foreach ($this->keyName as $key) {
|
foreach ($this->keyName as $key) {
|
||||||
if (! isset($this->properties[$key])) {
|
if (isset($this->properties[$key])) {
|
||||||
return null; // Really?
|
$id[$key] = $this->properties[$key];
|
||||||
}
|
}
|
||||||
$id[$key] = $this->properties[$key];
|
}
|
||||||
|
|
||||||
|
if (empty($id)) {
|
||||||
|
throw new IcingaException('Could not evaluate id for multi-column object!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user