diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index e82e1368bb..13235bd65e 100755 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -2567,7 +2567,7 @@ class ImportCsv 'extra_'.$careerDiagramExtraFieldName => serialize($graph), 'extra_'.$extraFieldName => $id, ]; - $extraFieldValue->saveFieldValues($params); + $extraFieldValue->saveFieldValues($params, true); } } } diff --git a/main/inc/lib/extra_field_value.lib.php b/main/inc/lib/extra_field_value.lib.php index cf20251c98..b3f195fb4f 100755 --- a/main/inc/lib/extra_field_value.lib.php +++ b/main/inc/lib/extra_field_value.lib.php @@ -76,11 +76,12 @@ class ExtraFieldValue extends Model * In order to save this function needs a item_id (user id, course id, etc) * This function is used with $extraField->addElements() * @param array $params array for the insertion into the *_field_values table + * @param bool $onlySubmittedFields Only save parameters in the $param array * @param bool $showQuery * @return mixed false on empty params, void otherwise * @assert (array()) === false */ - public function saveFieldValues($params, $showQuery = false) + public function saveFieldValues($params, $onlySubmittedFields = false, $showQuery = false) { foreach ($params as $key => $value) { $found = strpos($key, '__persist__'); @@ -119,6 +120,10 @@ class ExtraFieldValue extends Model } } + if ($onlySubmittedFields && !isset($params['extra_'.$field_variable])) { + continue; + } + if (isset($params['extra_'.$field_variable])) { $value = $params['extra_'.$field_variable]; } else { @@ -332,11 +337,11 @@ class ExtraFieldValue extends Model /** * Save values in the *_field_values table * @param array $params Structured array with the values to save - * @param boolean $show_query Whether to show the insert query (passed to the parent save() method) + * @param boolean $showQuery Whether to show the insert query (passed to the parent save() method) * @return mixed The result sent from the parent method * @assert (array()) === false */ - public function save($params, $show_query = false) + public function save($params, $showQuery = false) { $extra_field = $this->getExtraField(); @@ -421,7 +426,7 @@ class ExtraFieldValue extends Model } $params['value'] = $value_to_insert; - $params['author_id'] = api_get_user_id(); + //$params['author_id'] = api_get_user_id(); // Insert if (empty($field_values)) { @@ -478,10 +483,10 @@ class ExtraFieldValue extends Model $params['value'] = $optionId; if ($optionId) { - return parent::save($params, $show_query); + return parent::save($params, $showQuery); } } else { - return parent::save($params, $show_query); + return parent::save($params, $showQuery); } } } else { @@ -537,7 +542,7 @@ class ExtraFieldValue extends Model } else { $params['id'] = $field_values['id']; - return parent::update($params, $show_query); + return parent::update($params, $showQuery); } } } diff --git a/main/inc/lib/model.lib.php b/main/inc/lib/model.lib.php index 3330dfbfb9..d926b9c8e0 100755 --- a/main/inc/lib/model.lib.php +++ b/main/inc/lib/model.lib.php @@ -214,11 +214,11 @@ class Model /** * Updates the obj in the database. The $params['id'] must exist in order to update a record * @param array $params - * + * @param bool $showQuery * @return bool * */ - public function update($params) + public function update($params, $showQuery = false) { $params = $this->clean_parameters($params); @@ -244,7 +244,8 @@ class Model $result = Database::update( $this->table, $params, - array('id = ?' => $id) + array('id = ?' => $id), + $showQuery ); if ($result) { return true;