From 9a460a2dc78dbdbe0975d426fd48295b7e1e4dbe Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 2 Dec 2017 15:41:43 +0100 Subject: [PATCH] Fix update null/null objs --- DataStorage/DataMapperInterface.php | 4 ++-- DataStorage/Database/DataMapperAbstract.php | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DataStorage/DataMapperInterface.php b/DataStorage/DataMapperInterface.php index c9454d8e8..2071d5bf7 100644 --- a/DataStorage/DataMapperInterface.php +++ b/DataStorage/DataMapperInterface.php @@ -47,11 +47,11 @@ interface DataMapperInterface * * @param mixed $obj Object reference (gets filled with insert id) * - * @return int Status + * @return mixed * * @since 1.0.0 */ - public static function update($obj) : int; + public static function update($obj); /** * Delete data. diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 0f09a5fe1..8d0f8f4bb 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -346,7 +346,7 @@ class DataMapperAbstract implements DataMapperInterface { self::extend(__CLASS__); - if ($obj === null || + if (!isset($obj) || (strpos($className = get_class($obj), '\Null') !== false && is_object($obj)) ) { return null; @@ -1152,14 +1152,18 @@ class DataMapperAbstract implements DataMapperInterface * @param mixed $obj Object reference (gets filled with insert id) * @param int $relations Create all relations as well * - * @return int + * @return mixed * * @since 1.0.0 */ - public static function update($obj, int $relations = RelationType::ALL) : int + public static function update($obj, int $relations = RelationType::ALL) { self::extend(__CLASS__); + if(!isset($obj) || strpos(get_class($obj), '\Null') !== false) { + return null; + } + $reflectionClass = new \ReflectionClass($obj); $objId = self::getObjectId($obj, $reflectionClass); $update = true;