1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use App\Models\Release; |
||
6 | use App\Models\UsenetGroup; |
||
7 | use Illuminate\Console\Command; |
||
8 | use Illuminate\Support\Facades\DB; |
||
9 | |||
10 | class NntmuxResetTruncate extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'nntmux:reset-truncate'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'This command removes releases with no NZBs, resets all groups, truncates article tables. All other releases are left alone.'; |
||
25 | |||
26 | /** |
||
27 | * Create a new command instance. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | public function __construct() |
||
32 | { |
||
33 | parent::__construct(); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Execute the console command. |
||
38 | */ |
||
39 | public function handle(): void |
||
40 | { |
||
41 | UsenetGroup::query()->update(['first_record' => 0, 'first_record_postdate' => null, 'last_record' => 0, 'last_record_postdate' => null, 'last_updated' => null]); |
||
42 | $this->info('Reseting all groups completed.'); |
||
43 | DB::statement('SET FOREIGN_KEY_CHECKS = 0;'); |
||
44 | |||
45 | foreach (['parts', 'missed_parts', 'binaries', 'collections'] as &$value) { |
||
0 ignored issues
–
show
|
|||
46 | DB::statement("TRUNCATE TABLE $value"); |
||
47 | $this->info("Truncating $value completed."); |
||
48 | } |
||
49 | unset($value); |
||
50 | |||
51 | $delcount = Release::query()->where('nzbstatus', '=', 0)->delete(); |
||
52 | $this->info($delcount.' releases had no nzb, deleted.'); |
||
53 | DB::statement('SET FOREIGN_KEY_CHECKS = 1;'); |
||
54 | } |
||
55 | } |
||
56 |
Let?s assume that you have the following
foreach
statement:$itemValue
is assigned by reference. This is possible because the expression (in the example$array
) can be used as a reference target.However, if we were to replace
$array
with something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference