mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
add command event:fire + fetch imdb when torrent created
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\TorrentCreated;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FireEvent extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'event:fire {--name=} {--id=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fire a event, options: --name, --id';
|
||||
|
||||
protected array $eventMaps = [
|
||||
"torrent_created" => TorrentCreated::class
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$name = $this->option('name');
|
||||
$id = $this->option('id');
|
||||
$log = "FireEvent, name: $name, id: $id";
|
||||
if (isset($this->eventMaps[$name])) {
|
||||
$result = call_user_func([$this->eventMaps[$name], "dispatch"], $id);
|
||||
$this->info("$log, success call dispatch, result: " . var_export($result, true));
|
||||
} else {
|
||||
$this->error("$log, no event match this name");
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\TorrentCreated;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TorrentFetchImdb extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'torrent:fetch_imdb {torrent_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch torrent imdb info';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$torrentId = $this->argument("torrent_id");
|
||||
$this->info("torrentId: $torrentId");
|
||||
if (!$torrentId) {
|
||||
$this->error("require argument torrent_id");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
TorrentCreated::dispatch($torrentId);
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user