Page MenuHomePhorge

D5427.1775248001.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D5427.1775248001.diff

diff --git a/src/app/Console/Commands/Wallet/ChargeCommand.php b/src/app/Console/Commands/Wallet/ChargeCommand.php
--- a/src/app/Console/Commands/Wallet/ChargeCommand.php
+++ b/src/app/Console/Commands/Wallet/ChargeCommand.php
@@ -7,7 +7,9 @@
use App\Jobs\Wallet\CheckJob;
use App\User;
use App\Wallet;
+use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
+use Illuminate\Support\Facades\DB;
class ChargeCommand extends Command
{
@@ -60,10 +62,20 @@
->whereNot('users.status', '&', User::STATUS_DEGRADED | User::STATUS_SUSPENDED)
->cursor();
} else {
- // Get all wallets, excluding deleted accounts
+ // Get all wallets...
$wallets = Wallet::select('wallets.id')
->join('users', 'users.id', '=', 'wallets.user_id')
+ // exclude deleted accounts
->whereNull('users.deleted_at')
+ // exclude wallets w/o entitlements (but not wallets with a negative balance)
+ ->where(static function ($query) {
+ $query->where('balance', '<', 0)
+ ->orWhereExists(static function (Builder $query) {
+ $query->select(DB::raw(1))
+ ->from('entitlements')
+ ->whereColumn('entitlements.wallet_id', 'wallets.id');
+ });
+ })
->cursor();
}
diff --git a/src/tests/Feature/Console/Wallet/ChargeTest.php b/src/tests/Feature/Console/Wallet/ChargeTest.php
--- a/src/tests/Feature/Console/Wallet/ChargeTest.php
+++ b/src/tests/Feature/Console/Wallet/ChargeTest.php
@@ -61,18 +61,14 @@
$user1 = $this->getTestUser('john@kolab.org');
$wallet1 = $user1->wallets()->first();
- $user2 = $this->getTestUser('wallet-charge@kolabnow.com');
+ $user2 = $this->getTestUser('fred@' . \config('app.domain'));
$wallet2 = $user2->wallets()->first();
- $count = Wallet::join('users', 'users.id', '=', 'wallets.user_id')
- ->whereNull('users.deleted_at')
- ->count();
-
Queue::fake();
$this->artisan('wallet:charge')->assertExitCode(0);
- Queue::assertPushed(CheckJob::class, $count);
+ Queue::assertPushed(CheckJob::class, 4);
Queue::assertPushed(CheckJob::class, static function ($job) use ($wallet1) {
$job_wallet_id = TestCase::getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet1->id;

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 8:26 PM (1 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18826001
Default Alt Text
D5427.1775248001.diff (2 KB)

Event Timeline