Kode
6 years ago
11 changed files with 206 additions and 83 deletions
@ -0,0 +1,63 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Jobs; |
||||
|
|
||||
|
use Illuminate\Bus\Queueable; |
||||
|
use Illuminate\Queue\SerializesModels; |
||||
|
use Illuminate\Queue\InteractsWithQueue; |
||||
|
use Illuminate\Contracts\Queue\ShouldQueue; |
||||
|
use Illuminate\Foundation\Bus\Dispatchable; |
||||
|
use App\Application; |
||||
|
use App\SupportedApps; |
||||
|
|
||||
|
class ProcessApps implements ShouldQueue |
||||
|
{ |
||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||||
|
|
||||
|
/** |
||||
|
* Create a new job instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
// |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Execute the job. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function handle() |
||||
|
{ |
||||
|
$localapps = Application::all(); |
||||
|
$list = json_decode(SupportedApps::getList()->getBody()); |
||||
|
$validapps = []; |
||||
|
foreach($list->apps as $app) { |
||||
|
$validapps[] = $app->appid; |
||||
|
if(!file_exists(app_path('SupportedApps/'.className($app->name)))) { |
||||
|
SupportedApps::getFiles($app); |
||||
|
$application = new Application; |
||||
|
SupportedApps::saveApp($app, $application); |
||||
|
} else { |
||||
|
// check if there has been an update for this app |
||||
|
$localapp = $localapps->where('appid', $app->appid)->first(); |
||||
|
if($localapp) { |
||||
|
if($localapp->sha !== $app->sha) { |
||||
|
SupportedApps::getFiles($app); |
||||
|
SupportedApps::saveApp($app, $localapp); |
||||
|
} |
||||
|
} else { |
||||
|
SupportedApps::getFiles($app); |
||||
|
$application = new Application; |
||||
|
SupportedApps::saveApp($app, $application); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
//$delete = Application::whereNotIn('appid', $validapps)->delete(); // delete any apps not in list |
||||
|
// removed the delete so local apps can be added |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
use Illuminate\Database\Schema\Blueprint; |
||||
|
use Illuminate\Database\Migrations\Migration; |
||||
|
|
||||
|
class CreateJobsTable extends Migration |
||||
|
{ |
||||
|
/** |
||||
|
* Run the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function up() |
||||
|
{ |
||||
|
Schema::create('jobs', function (Blueprint $table) { |
||||
|
$table->bigIncrements('id'); |
||||
|
$table->string('queue')->index(); |
||||
|
$table->longText('payload'); |
||||
|
$table->unsignedTinyInteger('attempts'); |
||||
|
$table->unsignedInteger('reserved_at')->nullable(); |
||||
|
$table->unsignedInteger('available_at'); |
||||
|
$table->unsignedInteger('created_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Reverse the migrations. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function down() |
||||
|
{ |
||||
|
Schema::dropIfExists('jobs'); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue