Adding ability to add Steam apps to the download queue

This commit is contained in:
ilumos 2017-08-16 15:57:08 +01:00
parent ddc0670f6b
commit d1665fa5ca
3 changed files with 66 additions and 2 deletions

View file

@ -8,7 +8,7 @@ use Illuminate\Events\Dispatcher;
use Illuminate\Database\Capsule\Manager as Capsule;
// Import available commands
use Zeropingheroes\LancacheAutofill\Console\Commands\Steam\{UpdateAppList, SearchApps};
use Zeropingheroes\LancacheAutofill\Console\Commands\Steam\{UpdateAppList, SearchApps, QueueApp};
use Zeropingheroes\LancacheAutofill\Console\Commands\CreateDatabase;
// Load Composer's autoloader
@ -34,6 +34,7 @@ $capsule->setAsGlobal();
$app->add(new CreateDatabase);
$app->add(new UpdateAppList);
$app->add(new SearchApps);
$app->add(new QueueApp);
// Run the console app
$app->run();

View file

@ -35,8 +35,11 @@ class CreateDatabase extends Command
$table->string('name');
});
Capsule::schema()->create('dummy', function ($table) {
Capsule::schema()->create('steam_queue', function ($table) {
$table->increments('id')->unique();
$table->integer('appid')->unique();
$table->string('name');
$table->string('status');
});
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Zeropingheroes\LancacheAutofill\Console\Commands\Steam;
use Illuminate\Console\Command;
use Illuminate\Database\Capsule\Manager as Capsule;
class QueueApp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'steam:queue-app {app_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Queue a Steam app for donwloading';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$app = Capsule::table('steam_apps')
->where('appid', $this->argument('app_id'))
->first();
if( ! $app )
{
$this->error('Steam app with ID '.$this->argument('app_id').' not found');
die();
}
$alreadyQueued = Capsule::table('steam_queue')
->where('appid', $app->appid)
->count();
if( $alreadyQueued )
{
$this->error('Steam app "' . $app->name .'" already in download queue');
die();
}
Capsule::table('steam_queue')->insert([
'appid' => $app->appid,
'name' => $app->name,
'status'=> 'Queued'
]);
$this->info('Steam app "' . $app->name .'" added to download queue');
}
}