From c7b3d74a21fc6656b850c44e9f8b2359b09b2c8e Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 20 Aug 2015 20:00:54 +0200 Subject: [PATCH] MT#14317 passing now() to interval catchup and resize formerly, the contract_balance catchup (and resize) procedures used contracts.modified_timestamp, whose value was intended to be set explicitly upon update operations. it turns out that mysql ON UPDATE current_timestamp columns effectively ignore the explicit timestamp value, unless it exactly matches the old timestamp value. while this is not an issue for the logic in production usage, this seems to be the reason why the api-balance_intervals.t test fails occassionally with its time-warp cases. Change-Id: I504dd98548b88c99079e071598806d884c4422eb --- lib/NGCP/Panel/Controller/Contract.pm | 6 ++++-- lib/NGCP/Panel/Controller/Customer.pm | 6 ++++-- lib/NGCP/Panel/Role/API/Contracts.pm | 6 ++++-- lib/NGCP/Panel/Role/API/Customers.pm | 6 ++++-- lib/NGCP/Panel/Utils/ProfilePackages.pm | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index 0c6a4b7744..0ae34af9bb 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -163,7 +163,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) { $form->values->{$_.'_id'} = $form->values->{$_}{id} || undef; delete $form->values->{$_}; } - $form->values->{modify_timestamp} = $now; + $form->values->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns my $mappings_to_create = []; my $delete_mappings = 0; @@ -192,11 +192,13 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) { my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, contract => $contract, - old_package => $old_package,); + old_package => $old_package, + now => $now); $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, contract => $contract, old_package => $old_package, balance => $balance, + now => $now, ); if ($is_peering_reseller && diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 6162241a63..a83fb0f828 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -480,7 +480,7 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) { delete $form->values->{$_}; } $form->values->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; - $form->values->{modify_timestamp} = $now; + $form->values->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns $form->values->{external_id} = $form->field('external_id')->value; unless($form->values->{max_subscribers} && length($form->values->{max_subscribers})) { $form->values->{max_subscribers} = undef; @@ -516,11 +516,13 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) { my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, contract => $contract, - old_package => $old_package,); + old_package => $old_package, + now => $now); $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, contract => $contract, old_package => $old_package, balance => $balance, + now => $now, ); my $new_ext_id = $contract->external_id // ''; diff --git a/lib/NGCP/Panel/Role/API/Contracts.pm b/lib/NGCP/Panel/Role/API/Contracts.pm index 6884aa23ea..d1995dd43e 100644 --- a/lib/NGCP/Panel/Role/API/Contracts.pm +++ b/lib/NGCP/Panel/Role/API/Contracts.pm @@ -170,7 +170,7 @@ sub update_contract { }); delete $resource->{type}; - $resource->{modify_timestamp} = $now; + $resource->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns if($old_resource->{contact_id} != $resource->{contact_id}) { my $syscontact = $c->model('DB')->resultset('contacts') @@ -197,11 +197,13 @@ sub update_contract { my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, contract => $contract, - old_package => $old_package,); + old_package => $old_package, + now => $now); #make balance_intervals.t work $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, contract => $contract, old_package => $old_package, balance => $balance, + now => $now, ); if($old_resource->{status} ne $resource->{status}) { diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index 30ea35260c..36ce17991d 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -182,7 +182,7 @@ sub update_customer { }); delete $resource->{type}; - $resource->{modify_timestamp} = $now; + $resource->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns my $custcontact; if($old_resource->{contact_id} != $resource->{contact_id}) { @@ -263,11 +263,13 @@ sub update_customer { my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, contract => $customer, - old_package => $old_package,); + old_package => $old_package, + now => $now); #make balance_intervals.t work $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, contract => $customer, old_package => $old_package, balance => $balance, + now => $now, ); if(($customer->external_id // '') ne $old_ext_id) { diff --git a/lib/NGCP/Panel/Utils/ProfilePackages.pm b/lib/NGCP/Panel/Utils/ProfilePackages.pm index 31c96b9664..94412edd17 100644 --- a/lib/NGCP/Panel/Utils/ProfilePackages.pm +++ b/lib/NGCP/Panel/Utils/ProfilePackages.pm @@ -154,7 +154,7 @@ sub catchup_contract_balances { $now //= $contract->modify_timestamp; $old_package = $contract->profile_package if !exists $params{old_package}; - $c->log->debug('catchup contract ' . $contract->id . ' contract_balances to now - ' . NGCP::Panel::Utils::DateTime::to_string($now)) if $c; + #$c->log->debug('catchup contract ' . $contract->id . ' contract_balances (now = ' . NGCP::Panel::Utils::DateTime::to_string($now) . ')') if $c; my ($start_mode,$interval_unit,$interval_value,$carry_over_mode,$has_package,$notopup_expiration);