tenant = $this->option("tenant"); setup_db_connection(); if(config('database.connections.mysql-tenant.database') != config('json.prefix_db') . "_ente{$this->tenant}") { config(['database.connections.mysql-tenant.database' => config('json.prefix_db') . "_ente{$this->tenant}"]); DB::purge('mysql-tenant'); } $collections = Conservazione::where("stato", "<=", 20)->limit(200)->get(); foreach($collections as $collection) { if($collection->tipologia == "conservazione") { if ($collection->items()->count() < 1) { $this->info("Scheduling retrieval of files for package #{$collection->codice}"); GetFilesJob::dispatchSync($this->tenant, $collection->codice); } if($collection->items()->where('stato', '<>', '20')->count() < 1) { $this->info("Checking the status of package #{$collection->codice}"); CheckPreservationStatusJob::dispatchSync($this->tenant, $collection->codice); } else { $this->info("Scheduling the sending of package #{$collection->codice}"); SendPackageJob::dispatch($this->tenant, $collection->codice) ->onConnection("database") ->onQueue("preservation") ->delay(0); } } } $collections = Conservazione::where("stato", "=", 90)->limit(100)->get(); if(! empty($collections)) { foreach($collections as $collection) { $collection->items()->update(['stato' => 0, 'uID' => null, 'hash' => null]); $collection->pid = null; $collection->stato = 5; $collection->save(); $this->info("Scheduling the sending of package #{$collection->codice}, which previously failed"); SendPackageJob::dispatch($this->tenant, $collection->codice) ->onConnection("database") ->onQueue("preservation") ->delay(0); } } return 0; } }