From 44e88f186c86ee3d5334ae61b5a98292c9a031e4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 3 Jun 2016 09:19:13 -0700 Subject: [PATCH] Modernize "favorite project policies" setting Summary: Ref T4103. Convert this into a proper internal setting and use transactions to mutate it. Also remove some no-longer-used old non-modular settings constants. Test Plan: - Used policy dropdown, saw recently-used projects. - Selected some new projects, saw them appear. - Grepped for all removed constants. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D16027 --- src/__phutil_library_map__.php | 2 ++ .../people/storage/PhabricatorUser.php | 9 --------- .../PhabricatorPolicyEditController.php | 19 ++++++++++++------ .../policy/query/PhabricatorPolicyQuery.php | 2 +- .../PhabricatorPolicyFavoritesSetting.php | 16 +++++++++++++++ .../storage/PhabricatorUserPreferences.php | 20 ------------------- .../phui/calendar/PHUICalendarMonthView.php | 2 +- 7 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 src/applications/settings/setting/PhabricatorPolicyFavoritesSetting.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 346f6797ab..db61cc72b6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3031,6 +3031,7 @@ phutil_register_library_map(array( 'PhabricatorPolicyEditField' => 'applications/transactions/editfield/PhabricatorPolicyEditField.php', 'PhabricatorPolicyException' => 'applications/policy/exception/PhabricatorPolicyException.php', 'PhabricatorPolicyExplainController' => 'applications/policy/controller/PhabricatorPolicyExplainController.php', + 'PhabricatorPolicyFavoritesSetting' => 'applications/settings/setting/PhabricatorPolicyFavoritesSetting.php', 'PhabricatorPolicyFilter' => 'applications/policy/filter/PhabricatorPolicyFilter.php', 'PhabricatorPolicyInterface' => 'applications/policy/interface/PhabricatorPolicyInterface.php', 'PhabricatorPolicyManagementShowWorkflow' => 'applications/policy/management/PhabricatorPolicyManagementShowWorkflow.php', @@ -7706,6 +7707,7 @@ phutil_register_library_map(array( 'PhabricatorPolicyEditField' => 'PhabricatorEditField', 'PhabricatorPolicyException' => 'Exception', 'PhabricatorPolicyExplainController' => 'PhabricatorPolicyController', + 'PhabricatorPolicyFavoritesSetting' => 'PhabricatorInternalSetting', 'PhabricatorPolicyFilter' => 'Phobject', 'PhabricatorPolicyInterface' => 'PhabricatorPHIDInterface', 'PhabricatorPolicyManagementShowWorkflow' => 'PhabricatorPolicyManagementWorkflow', diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index 0d450c5a88..b18aa0e4cf 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -606,15 +606,6 @@ final class PhabricatorUser $preferences = new PhabricatorUserPreferences(); $preferences->setUserPHID($this->getPHID()); $preferences->attachUser($this); - - $default_dict = array( - PhabricatorUserPreferences::PREFERENCE_TITLES => 'glyph', - PhabricatorUserPreferences::PREFERENCE_EDITOR => '', - PhabricatorUserPreferences::PREFERENCE_MONOSPACED => '', - PhabricatorUserPreferences::PREFERENCE_DARK_CONSOLE => 0, - ); - - $preferences->setPreferences($default_dict); } $this->preferences = $preferences; diff --git a/src/applications/policy/controller/PhabricatorPolicyEditController.php b/src/applications/policy/controller/PhabricatorPolicyEditController.php index 3dd8924bb6..75701cc748 100644 --- a/src/applications/policy/controller/PhabricatorPolicyEditController.php +++ b/src/applications/policy/controller/PhabricatorPolicyEditController.php @@ -281,10 +281,8 @@ final class PhabricatorPolicyEditController // Save this project as one of the user's most recently used projects, // so we'll show it by default in future menus. - $pref_key = PhabricatorUserPreferences::PREFERENCE_FAVORITE_POLICIES; - - $preferences = $viewer->loadPreferences(); - $favorites = $preferences->getPreference($pref_key); + $favorites_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; + $favorites = $viewer->getUserSetting($favorites_key); if (!is_array($favorites)) { $favorites = array(); } @@ -293,8 +291,17 @@ final class PhabricatorPolicyEditController unset($favorites[$project_phid]); $favorites[$project_phid] = true; - $preferences->setPreference($pref_key, $favorites); - $preferences->save(); + $preferences = PhabricatorUserPreferences::loadUserPreferences($viewer); + + $editor = id(new PhabricatorUserPreferencesEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $xactions = array(); + $xactions[] = $preferences->newTransaction($favorites_key, $favorites); + $editor->applyTransactions($preferences, $xactions); $data = array( 'phid' => $project->getPHID(), diff --git a/src/applications/policy/query/PhabricatorPolicyQuery.php b/src/applications/policy/query/PhabricatorPolicyQuery.php index 81c9bb8a51..e51b2ca401 100644 --- a/src/applications/policy/query/PhabricatorPolicyQuery.php +++ b/src/applications/policy/query/PhabricatorPolicyQuery.php @@ -195,7 +195,7 @@ final class PhabricatorPolicyQuery $viewer = $this->getViewer(); if ($viewer->getPHID()) { - $pref_key = PhabricatorUserPreferences::PREFERENCE_FAVORITE_POLICIES; + $pref_key = PhabricatorPolicyFavoritesSetting::SETTINGKEY; $favorite_limit = 10; $default_limit = 5; diff --git a/src/applications/settings/setting/PhabricatorPolicyFavoritesSetting.php b/src/applications/settings/setting/PhabricatorPolicyFavoritesSetting.php new file mode 100644 index 0000000000..61fb870625 --- /dev/null +++ b/src/applications/settings/setting/PhabricatorPolicyFavoritesSetting.php @@ -0,0 +1,16 @@ +getViewer(); - $week_key = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; + $week_key = PhabricatorWeekStartDaySetting::SETTINGKEY; $week_start = $viewer->getUserSetting($week_key); $week_end = ($week_start + 6) % 7;