Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117781095
D5427.1775248001.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D5427.1775248001.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D5427: Slim down number of wallet check jobs
Attached
Detach File
Event Timeline