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

feat: refactor reminders #2223

Merged
merged 65 commits into from
Jan 15, 2019
Merged

feat: refactor reminders #2223

merged 65 commits into from
Jan 15, 2019

Conversation

djaiss
Copy link
Member

@djaiss djaiss commented Dec 28, 2018

This PR completely refactors how reminders are managed.

  • The Notification object has been completely removed.
  • There are 3 tables for reminders:
    • reminders
    • reminder_outbox
    • reminder_sent
  • Special Dates do not have a reminder_id column anymore
  • A reminder is now only defined by an initial_date.
  • A reminder in itself is not sent - once it's scheduled, we create a ReminderOutbox object that will be sent.
  • Think of ReminderOutbox as the queue for reminders that need to be sent.
  • A ReminderOutbox object has a nature field which can contain two values: reminder and notification. notification means that it's a reminder that needs to be sent a few days the actual reminder is sent - these correspond to the Reminder Rules set in the account.

New processes

  • Once a reminder is created, we create ReminderOutbox objects
    • one of the reminder type
    • two for each reminder rules setup in the account.
  • Once a reminder outbox is sent:
    • we create a new corresponding entry in the reminder_sent table and delete the Reminderoutbox object.
    • we schedule the new reminder outbox if it's a recurring reminder
    • we mark the corresponding reminder if it's a one time reminder
    • we delete the reminder outbox
  • A reminder is scheduled for a specific user.
  • The only cron that remains with this new system is the send:reminders command which takes care of everything.
  • Special dates do not have a reminder_id anymore. It shouldn't be special dates' responsibilities to know if they have a reminder associated with them. All reminders should be linked to contacts. Therefore, we got rid of the setReminder method in the specialDate class.
  • We don't store anymore on the reminders table the next expected date of the reminder - we only store the initial date, then we always calculate the next date on the fly.
  • Some reminders shouldn't be deleted from the UI - for instance, reminders about birthdays. For those birthdays, we don't display the Edit and Delete buttons in the list of reminders - this is controlled by the new delible field in the reminder object.

Other changes

  • Create all services for reminder management
  • Add foreign keys for reminders, contacts, reminder rules, special dates

Limitations

  • No API methods for managing ReminderOutbox and ReminderSent objects yet.
  • Reminders that have been sent are not displayed in the UI yet.

  • Make sure existing data is migrated

Copy link

@sonarqubecloud sonarqubecloud bot left a comment

Choose a reason for hiding this comment

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

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 18

Including the following issue(s) which could not be reported in line:

  1. Code Smell Code Smell: Define a constant instead of duplicating this literal "account_id" 15 times. (more)
  2. Code Smell Code Smell: 1 duplicated blocks of code must be removed. (more)
  3. Code Smell Code Smell: 1 duplicated blocks of code must be removed. (more)

See all issues in SonarCloud

@djaiss djaiss changed the title feat: refactor reminders [wip] feat: refactor reminders Jan 6, 2019
@djaiss
Copy link
Member Author

djaiss commented Jan 6, 2019

@asbiin ready for review 😀

asbiin
asbiin previously requested changes Jan 14, 2019
Copy link
Member

@asbiin asbiin left a comment

Choose a reason for hiding this comment

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

See my review here.
Some little change request, and questions.
Thanks @djaiss !

app/Http/Controllers/ContactsController.php Outdated Show resolved Hide resolved
app/Models/User/User.php Outdated Show resolved Hide resolved
@@ -72,15 +74,19 @@ public function execute(array $data) : LifeEvent
private function addYearlyReminder($data, $lifeEvent)
{
if ($data['has_reminder']) {
$array = [
$date = Carbon::parse($data['happened_at']);
Copy link
Member

Choose a reason for hiding this comment

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

You should use

Suggested change
$date = Carbon::parse($data['happened_at']);
$date = DateHelper::parseDate($data['happened_at']);

Copy link
Member Author

Choose a reason for hiding this comment

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

No because it's Y-m-d format and this helper needs H:i:s as well. It expects DateTime and I have a Date.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, DateHelper::parseDateTime parse a DateTime, but DateHelper::parseDate needs a Date format, and render a Date format.

Copy link
Member Author

Choose a reason for hiding this comment

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

ahhhh ok I get it.

app/Http/Controllers/ContactsController.php Outdated Show resolved Hide resolved
@djaiss djaiss merged commit 69cfdeb into master Jan 15, 2019
@asbiin asbiin mentioned this pull request Jan 19, 2019
@djaiss djaiss deleted the 2018-12-22-fix-one-time-reminder branch March 2, 2019 12:10
@github-actions
Copy link

This pull request has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants