Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117923691
D5178.1775440511.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D5178.1775440511.diff
View Options
diff --git a/src/app/Console/Commands/Data/Stats/CollectorCommand.php b/src/app/Console/Commands/Data/Stats/CollectorCommand.php
--- a/src/app/Console/Commands/Data/Stats/CollectorCommand.php
+++ b/src/app/Console/Commands/Data/Stats/CollectorCommand.php
@@ -4,7 +4,9 @@
use App\Http\Controllers\API\V4\Admin\StatsController;
use App\Payment;
+use App\Transaction;
use App\User;
+use App\Wallet;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
@@ -39,10 +41,11 @@
*/
protected function collectPayersCount(): void
{
- // A subquery to get the all wallets with a successful payment
- $payments = DB::table('payments')
- ->selectRaw('distinct wallet_id')
- ->where('status', Payment::STATUS_PAID);
+ // A subquery to get the all wallets with a credit/award transaction
+ $transactions = DB::table('transactions')
+ ->selectRaw('distinct object_id as wallet_id')
+ ->where('object_type', Wallet::class)
+ ->whereIn('type', [Transaction::WALLET_AWARD, Transaction::WALLET_CREDIT]);
// A subquery to get users' wallets (by entitlement) - one record per user
$wallets = DB::table('entitlements')
@@ -50,14 +53,14 @@
->where('entitleable_type', User::class)
->groupBy('entitleable_id');
- // Count all non-degraded and non-deleted users with any successful payment
+ // Count all non-degraded and non-deleted users that are payers
$counts = DB::table('users')
->selectRaw('count(*) as total, users.tenant_id')
->joinSub($wallets, 'wallets', function ($join) {
$join->on('users.id', '=', 'wallets.user_id');
})
- ->joinSub($payments, 'payments', function ($join) {
- $join->on('wallets.id', '=', 'payments.wallet_id');
+ ->joinSub($transactions, 'transactions', function ($join) {
+ $join->on('wallets.id', '=', 'transactions.wallet_id');
})
->whereNull('users.deleted_at')
->whereNot('users.status', '&', User::STATUS_DEGRADED)
diff --git a/src/tests/Feature/Console/Data/Stats/CollectorTest.php b/src/tests/Feature/Console/Data/Stats/CollectorTest.php
--- a/src/tests/Feature/Console/Data/Stats/CollectorTest.php
+++ b/src/tests/Feature/Console/Data/Stats/CollectorTest.php
@@ -3,7 +3,6 @@
namespace Tests\Feature\Console\Data\Stats;
use App\Http\Controllers\API\V4\Admin\StatsController;
-use App\Payment;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
@@ -17,7 +16,7 @@
parent::setUp();
DB::table('stats')->truncate();
- DB::table('payments')->truncate();
+ DB::table('transactions')->truncate();
}
/**
@@ -26,7 +25,7 @@
public function tearDown(): void
{
DB::table('stats')->truncate();
- DB::table('payments')->truncate();
+ DB::table('transactions')->truncate();
parent::tearDown();
}
@@ -47,19 +46,7 @@
$john = $this->getTestUser('john@kolab.org');
$wallet = $john->wallet();
-
- \App\Payment::create([
- 'id' => 'test1',
- 'description' => '',
- 'status' => Payment::STATUS_PAID,
- 'amount' => 1000,
- 'credit_amount' => 1000,
- 'type' => Payment::TYPE_ONEOFF,
- 'wallet_id' => $wallet->id,
- 'provider' => 'mollie',
- 'currency' => $wallet->currency,
- 'currency_amount' => 1000,
- ]);
+ $wallet->award(1000);
$code = \Artisan::call("data:stats:collector");
$output = trim(\Artisan::output());
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 1:55 AM (15 h, 30 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18835219
Default Alt Text
D5178.1775440511.diff (3 KB)
Attached To
Mode
D5178: Stats: Make payers count depend on transactions not payments
Attached
Detach File
Event Timeline