From 8fade3a9d651dabce72eb6542ba42575b74a5b59 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 8 Apr 2015 17:12:16 -0500 Subject: [PATCH] users: Fix saving of custom data on new user --- include/class.organization.php | 2 ++ include/class.user.php | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/class.organization.php b/include/class.organization.php index 587d0d5a7..32e2c1ec9 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -106,6 +106,8 @@ class Organization extends OrganizationModel { function addDynamicData($data) { $entry = $this->addForm(OrganizationForm::objects()->one(), 1, $data); + // FIXME: For some reason, the second save here is required or the + // custom data is not properly saved $entry->save(); return $entry; diff --git a/include/class.user.php b/include/class.user.php index 886c18db9..db6e7936d 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -254,12 +254,12 @@ class User extends UserModel { return $this->created; } - function addForm($form, $sort=1) { - $form = $form->instanciate(); - $form->set('sort', $sort); - $form->set('object_type', 'U'); - $form->set('object_id', $this->getId()); - $form->save(); + function addForm($form, $sort=1, $data=null) { + $entry = $form->instanciate($sort, $data); + $entry->set('object_type', 'U'); + $entry->set('object_id', $this->getId()); + $entry->save(); + return $entry; } function to_json() { @@ -292,14 +292,11 @@ class User extends UserModel { } function addDynamicData($data) { - $uf = UserForm::getNewInstance(); - $uf->setClientId($this->id); - foreach ($uf->getFields() as $f) - if (isset($data[$f->get('name')])) - $uf->setAnswer($f->get('name'), $data[$f->get('name')]); - $uf->save(); - - return $uf; + $entry = $this->addForm(UserForm::objects()->one(), 1, $data); + // FIXME: For some reason, the second save here is required or the + // custom data is not properly saved + $entry->save(); + return $entry; } function getDynamicData($create=true) { -- GitLab