Changeset View
Standalone View
src/app/Observers/EntitlementObserver.php
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | class EntitlementObserver | ||||
* @param \App\Entitlement $entitlement The entitlement. | * @param \App\Entitlement $entitlement The entitlement. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function created(Entitlement $entitlement) | public function created(Entitlement $entitlement) | ||||
{ | { | ||||
$entitlement->entitleable->updated_at = Carbon::now(); | $entitlement->entitleable->updated_at = Carbon::now(); | ||||
$entitlement->entitleable->save(); | $entitlement->entitleable->save(); | ||||
$entitlement->createTransaction(\App\Transaction::ENTITLEMENT_CREATED); | |||||
} | } | ||||
/** | /** | ||||
* Handle the entitlement "deleted" event. | * Handle the entitlement "deleted" event. | ||||
* | * | ||||
* @param \App\Entitlement $entitlement The entitlement. | * @param \App\Entitlement $entitlement The entitlement. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function deleted(Entitlement $entitlement) | public function deleted(Entitlement $entitlement) | ||||
{ | { | ||||
// Remove all configured 2FA methods from Roundcube database | // Remove all configured 2FA methods from Roundcube database | ||||
if ($entitlement->sku->title == '2fa') { | if ($entitlement->sku->title == '2fa') { | ||||
// FIXME: Should that be an async job? | // FIXME: Should that be an async job? | ||||
$sf = new \App\Auth\SecondFactor($entitlement->entitleable); | $sf = new \App\Auth\SecondFactor($entitlement->entitleable); | ||||
$sf->removeFactors(); | $sf->removeFactors(); | ||||
} | } | ||||
$entitlement->entitleable->updated_at = Carbon::now(); | $entitlement->entitleable->updated_at = Carbon::now(); | ||||
$entitlement->entitleable->save(); | $entitlement->entitleable->save(); | ||||
$entitlement->createTransaction(\App\Transaction::ENTITLEMENT_DELETED); | |||||
} | } | ||||
} | } | ||||
machniak: I see similar code in a few places. Probably adding Entitlement::createTransaction($type… | |||||
Done Inline ActionsYes, a better version of these de-duplicating code would indeed improve the overall consistency. vanmeeuwen: Yes, a better version of these de-duplicating code would indeed improve the overall consistency. | |||||
Done Inline ActionsWill this work properly when updatedAt->day is e.g. March 30. Could we just calculate $pricePerDay as 1/30 of the monthly cost? machniak: Will this work properly when updatedAt->day is e.g. March 30. Could we just calculate… | |||||
Done Inline ActionsIf $daysLeftInLastMonth ends up 0, the $dayOfThisMonth is also 1. From 03/30 to 04/01, is one day (or two days, edges included, but that's not what we're doing). I would argue that it does work properly. vanmeeuwen: If `$daysLeftInLastMonth` ends up 0, the `$dayOfThisMonth` is also 1. From 03/30 to 04/01, is… | |||||
Done Inline ActionsMy point is that if $updatedAt->day is 30 (or 31) and $daysInLastMonth is 28 (or 29 or 30) we end up with $daysLeftInLastMonth < 0. It's maybe not a problem, but you've got the case for a test. machniak: My point is that if $updatedAt->day is 30 (or 31) and $daysInLastMonth is 28 (or 29 or 30) we… | |||||
Done Inline ActionsAll full months not already billed moving forward up to the point where there is not another full month left. $daysInLastMonth is therefore 28, 29, 30 or 31. $updatedAt, as a copy of having moved forward by monthWithoutOverflow should not yield a March date for anything having moved forward a month from January 31st. It should yield in the 28th or 29th day of the month of February. If you think of a reason I'm wrong, please point out the flaw in my thinking. Otherwise, yes, it is indeed a case of testing. vanmeeuwen: All full months not already billed moving forward up to the point where there is not another… |
I see similar code in a few places. Probably adding Entitlement::createTransaction($type, $amount) method would be useful.