-
Notifications
You must be signed in to change notification settings - Fork 53
Enhancement: Restorable Rich Feature Values #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
@timacdonald sorry #135 was a bit more of a POC so I've closed it. I've had some time to consider and I think this is a better approach. I'll start working on a PR for the docs if it shows any promise. There's a lot to review here I know, and it will likely require a version bump so I'm not expecting any rush. I'm already using in my own project via an extension (of database driver) and a couple of macros which don't feel like much of a burden, so no worries at all on my end. |
Appreciate it. I'm gonna mark this one as a draft so I have time to review before we push it to Taylor for final review and consideration. I have some ideas on how this could work since and just wanna make sure we align on how to make it happen. Will try and get to this next week. |
@timacdonald apologies for the ping, I know I said no rush but is there any news on this? I know you've been busy with wayfinder and I'm sure there are many other things as well. I Just ran |
Hey! I'm still interested in making this happen. We are leading up to the Nightwatch release, so my time is limited right now. After we get that out the door I will circle back to this one. Sorry for the delay. |
No worries! Thanks for the update. Also looking forward to the nightwatch release! 👍 |
@timacdonald in typical fashion, turns out what I wanted wasn't what I thought I wanted. While I still believe this is a great feature, let me show you what it turns out I actually wanted: Stateless features unless overridden by stateful features.So how I achieved this is by using the array driver as my default driver, but checking with the database driver in the closure definition, something like so: public function boot()
{
Feature::driver('array')->define('custom-font', function (User $scope) {
try {
if (Feature::driver('database')->for($scope)->active('custom-font')) {
return Feature::driver('database')->for($scope)->value('custom-font');
}
} catch (QueryException $e) {
//
}
return false;
});
}
public function resetDefaults(mixed $scope = null, ?string $name = null)
{
$query = DB::connection(config('pennant.stores.database.connection'))
->table('features');
if ($scope) {
$query->where('scope', Feature::serializeScope($scope));
}
if ($name) {
$query->where('name', $name);
}
$query->delete();
} |
As discussed with @timacdonald in #133 this adds a boolean column for the database driver to allow marking a feature flag inactive without erasing its previous value. This means that after a temporary rollback of a feature, a user's value for that feature can be restored upon reactivation, using the following new api:
This PR also allows restoring features for all scopes, in the same manner as
Feature::restoreForEveryone()
Includes tests, and events
FeatureRestored
andFeatureRestoredForAllScopes
which are fired uponFeature::restore
andFeature::restoreForEveryone
, respectively.Major changes:
false
).