From ef4ecd40fbd6e03a6958d7543735f7a7ddd461a0 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 10 Jan 2020 12:44:59 -0500 Subject: [PATCH] Set defaults before saving Objects --- web/includes/Object.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/includes/Object.php b/web/includes/Object.php index 1c17ce312..9f29aed88 100644 --- a/web/includes/Object.php +++ b/web/includes/Object.php @@ -110,8 +110,9 @@ class ZM_Object { public static function _find_one($class, $parameters = array(), $options = array() ) { global $object_cache; - if ( ! isset($object_cache[$class]) ) + if ( ! isset($object_cache[$class]) ) { $object_cache[$class] = array(); + } $cache = &$object_cache[$class]; if ( ( count($parameters) == 1 ) and @@ -290,6 +291,16 @@ Logger::Debug("$k => Have default for $v: "); $this->set($new_values); } + foreach ( $this->defaults as $field => $default ) { + if ( (!array_key_exists($field, $this)) or empty($this->{$field}) ) { + if ( is_array($default) ) { + $this->{$field} = $default['default']; + } else { + $this->{$field} = $default; + } + } + } + $fields = array_filter( $this->defaults, function($v) {