mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Trigger no longer fires or creates reminders for piggy banks.
This commit is contained in:
@@ -107,159 +107,6 @@ class EloquentPiggybankTrigger
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whenever a repetition is made, the decision is there to make reminders for it. Or not.
|
||||
* Some combinations are "invalid" or impossible and will never trigger reminders. Others do.
|
||||
*
|
||||
* The numbers below refer to a small list I made in a text-file (it no longer exists) which contained the eight
|
||||
* binary combinations that can be made of three properties each piggy bank has (among others):
|
||||
*
|
||||
* - Whether or not it has a start date.
|
||||
* - Whether or not it has an end date.
|
||||
* - Whether or not the piggy bank repeats itself.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @param \PiggybankRepetition $repetition
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function createdRepetition(\PiggybankRepetition $repetition)
|
||||
{
|
||||
\Log::debug('TRIGGER on createdRepetition() for repetition #' . $repetition->id);
|
||||
|
||||
$piggyBank = $repetition->piggybank;
|
||||
|
||||
// first, exclude all combinations that will not generate (valid) reminders
|
||||
|
||||
// no reminders needed (duh)
|
||||
if (is_null(($piggyBank->reminder))) {
|
||||
\Log::debug('No reminders because no reminder needed.');
|
||||
return null;
|
||||
}
|
||||
|
||||
// no start, no target, no repeat (#1):
|
||||
if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 0) {
|
||||
\Log::debug('No reminders because no start, no target, no repeat (#1)');
|
||||
return null;
|
||||
}
|
||||
|
||||
// no start, but repeats (#5):
|
||||
if (is_null($piggyBank->startdate) && $piggyBank->repeats == 1) {
|
||||
\Log::debug('No reminders because no start, but repeats (#5)');
|
||||
return null;
|
||||
}
|
||||
|
||||
// no start, no end, but repeats (#6)
|
||||
if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) {
|
||||
\Log::debug('No reminders because no start, no end, but repeats (#6)');
|
||||
return null;
|
||||
}
|
||||
|
||||
// no end, but repeats (#7)
|
||||
if (is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) {
|
||||
\Log::debug('No reminders because no end, but repeats (#7)');
|
||||
return null;
|
||||
}
|
||||
|
||||
\Log::debug('Will continue...');
|
||||
/*
|
||||
* #2, #3, #4 and #8 are valid combo's.
|
||||
*
|
||||
* We add two years to the end when the repetition has no target date; we "pretend" there is a target date.
|
||||
*
|
||||
*/
|
||||
if (is_null($repetition->targetdate)) {
|
||||
$end = new Carbon;
|
||||
$end->addYears(2);
|
||||
} else {
|
||||
$end = $repetition->targetdate;
|
||||
}
|
||||
/*
|
||||
* If there is no start date, the start dat becomes right now.
|
||||
*/
|
||||
if (is_null($repetition->startdate)) {
|
||||
$start = new Carbon;
|
||||
} else {
|
||||
$start = $repetition->startdate;
|
||||
}
|
||||
|
||||
/*
|
||||
* Firefly checks every period X between $start and $end and if necessary creates a reminder. Firefly
|
||||
* only creates reminders if the $current date is after today. Piggy banks may have their start in the past.
|
||||
*
|
||||
* This loop will jump a month when the reminder is set monthly, a week when it's set weekly, etcetera.
|
||||
*/
|
||||
$current = $start;
|
||||
$today = new Carbon;
|
||||
$today->startOfDay();
|
||||
while ($current <= $end) {
|
||||
\Log::debug('Looping reminder dates; now at ' . $current);
|
||||
/*
|
||||
* Piggy bank reminders start X days before the actual date of the event.
|
||||
*/
|
||||
$reminderStart = clone $current;
|
||||
switch ($piggyBank->reminder) {
|
||||
case 'day':
|
||||
$reminderStart->subDay();
|
||||
break;
|
||||
case 'week':
|
||||
$reminderStart->subDays(4);
|
||||
break;
|
||||
case 'month':
|
||||
$reminderStart->subDays(21);
|
||||
break;
|
||||
case 'year':
|
||||
$reminderStart->subMonths(9);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the date is past today we create a reminder, otherwise we don't. The end date is the date
|
||||
* the reminder is due; after that it is invalid.
|
||||
*/
|
||||
if ($current >= $today) {
|
||||
$reminder = new \PiggybankReminder;
|
||||
$reminder->piggybank()->associate($piggyBank);
|
||||
$reminder->user()->associate(\Auth::user());
|
||||
$reminder->startdate = $reminderStart;
|
||||
$reminder->enddate = $current;
|
||||
$reminder->active = 1;
|
||||
\Log::debug('Will create a reminder. Is it valid?');
|
||||
\Log::debug($reminder->validate());
|
||||
try {
|
||||
|
||||
$reminder->save();
|
||||
} catch (QueryException $e) {
|
||||
\Log::error('Could not save reminder: ' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
\Log::debug('Current is before today, will not make a reminder.');
|
||||
}
|
||||
|
||||
/*
|
||||
* Here Firefly jumps ahead to the next reminder period.
|
||||
*/
|
||||
switch ($piggyBank->reminder) {
|
||||
case 'day':
|
||||
$current->addDays($piggyBank->reminder_skip);
|
||||
break;
|
||||
case 'week':
|
||||
$current->addWeeks($piggyBank->reminder_skip);
|
||||
break;
|
||||
case 'month':
|
||||
$current->addMonths($piggyBank->reminder_skip);
|
||||
break;
|
||||
case 'year':
|
||||
$current->addYears($piggyBank->reminder_skip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
@@ -356,9 +203,6 @@ class EloquentPiggybankTrigger
|
||||
'piggybanks.check', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@checkRepeatingPiggies'
|
||||
);
|
||||
|
||||
$events->listen(
|
||||
'piggybanks.repetition', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@createdRepetition'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user