Skip to content
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

Added optional days argument to clean command #484

Merged
merged 3 commits into from
Mar 11, 2019
Merged

Added optional days argument to clean command #484

merged 3 commits into from
Mar 11, 2019

Conversation

bradcis
Copy link
Contributor

@bradcis bradcis commented Feb 6, 2019

Please bear with me, @freekmurze and team! This is my first ever pull request, so I'm hoping I'm following the proper procedure.

I'm requesting we add the ability to set the number of days threshold on the activitylog:clean command if the end user wants to deviate from the default set in the config file. The use case is that you may have multiple logs and want the retention period to be different for each one of them (i.e. user activities are deleted after 7 days where as project activities are deleted after 30 days).

The end user could then add the activitylog:clean command to their schedule with each variation.

@Gummibeer
Copy link
Collaborator

I like this idea! The only thing is that I would use it as an option and not as argument. Arguments have to be in a fixed order and with every new it get's more complex. That's why I like to have commands with just one argument and the others - primary if optional - as option.
Except of this the PR is fine and I would like to merge it.

@freekmurze
Copy link
Member

Thank you for this PR. Like @Gummibeer suggested, an option would be better in this case. Could you also add a test to ensure that it works as intended.

@bradcis
Copy link
Contributor Author

bradcis commented Feb 14, 2019

Thank you guys! I've updated the code to use an option rather than argument and added test coverage. Will this work?


Artisan::call('activitylog:clean', ['--days' => 7]);

$cutOffDate = Carbon::now()->subDay(7)->format('Y-m-d H:i:s');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multiple days please the subDays() method.


$cutOffDate = Carbon::now()->subDay(7)->format('Y-m-d H:i:s');

$this->assertCount(0, Activity::where('created_at', '<', $cutOffDate)->get());
Copy link
Collaborator

@Gummibeer Gummibeer Feb 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a total count be better here? If I'm not wrong there should be 7 left in the database!?
Or better as a second assert.

@Gummibeer
Copy link
Collaborator

@bradcis and could you please merge the current master in here - this will let pass all unittests again. :)

@Gummibeer Gummibeer changed the base branch from master to ft-command-days-option March 11, 2019 08:09
@Gummibeer Gummibeer merged commit 510ad19 into spatie:ft-command-days-option Mar 11, 2019
@Gummibeer
Copy link
Collaborator

I've merged it into spatie:ft-command-days-option to update my requests and prepare it for a release. Thanks @bradcis for your work here!

@bradcis
Copy link
Contributor Author

bradcis commented Mar 14, 2019

Thanks for finishing this up, @Gummibeer! I apologize for not responding sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants