From 8d2b21a0ce768f67342dcffca628b436a1fbfab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Freyd?= Date: Thu, 1 Mar 2018 20:50:05 -0500 Subject: [PATCH] Fix reset account deleting default account values (#956) This fixes #922 --- CHANGELOG | 1 + app/Account.php | 15 ++++++++++++--- app/Http/Controllers/SettingsController.php | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 965be645d..0c8d2b98e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ UNRELEASED CHANGES: +* Fix reset account deleting default account values * Fix notifications not working with aysnchronous queue * Support mysql unix socket diff --git a/app/Account.php b/app/Account.php index e6f02e6bc..e7362e2da 100644 --- a/app/Account.php +++ b/app/Account.php @@ -49,9 +49,7 @@ class Account extends Model $account->created_at = Carbon::now(); $account->save(); - $account->populateContactFieldTypeTable(); - $account->populateDefaultGendersTable(); - $account->populateDefaultReminderRulesTable(); + $account->populateDefaultFields($account); // create the first user for this account User::createDefault($account->id, $first_name, $last_name, $email, $password); @@ -59,6 +57,17 @@ class Account extends Model return $account; } + /** + * Populates all the default column that should be there when a new account + * is created or reset. + */ + public static function populateDefaultFields($account) + { + $account->populateContactFieldTypeTable(); + $account->populateDefaultGendersTable(); + $account->populateDefaultReminderRulesTable(); + } + /** * Get the activity records associated with the account. * diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 1ddcc1083..ac3a12b7a 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -149,6 +149,8 @@ class SettingsController extends Controller DB::table($tableName)->where('account_id', $account->id)->delete(); } + $account->populateDefaultFields($account); + return redirect('/settings') ->with('status', trans('settings.reset_success')); }