Build Laravel 13 ticket assistant with Docker, Livewire admin, and helpdesk scraper command
This commit is contained in:
44
app/Console/Commands/ImportHelpdeskArticlesCommand.php
Normal file
44
app/Console/Commands/ImportHelpdeskArticlesCommand.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\HelpdeskImportService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ImportHelpdeskArticlesCommand extends Command
|
||||
{
|
||||
protected $signature = 'helpdesk:import
|
||||
{--base-url=https://www.internettoday.nl/helpdesk : Base helpdesk URL}
|
||||
{--limit= : Max number of article URLs to process}
|
||||
{--dry-run : Only detect and parse, do not write to database}';
|
||||
|
||||
protected $description = 'Scrape InternetToday helpdesk categories/subcategories/articles and import into articles table.';
|
||||
|
||||
public function handle(HelpdeskImportService $service): int
|
||||
{
|
||||
$limitOption = $this->option('limit');
|
||||
$limit = is_numeric($limitOption) ? (int) $limitOption : null;
|
||||
|
||||
$result = $service->import(
|
||||
(string) $this->option('base-url'),
|
||||
(bool) $this->option('dry-run'),
|
||||
$limit
|
||||
);
|
||||
|
||||
$this->info('Helpdesk import finished.');
|
||||
$this->table(
|
||||
['Metric', 'Value'],
|
||||
[
|
||||
['Categories', $result['categories']],
|
||||
['Sections', $result['sections']],
|
||||
['Article URLs', $result['article_urls']],
|
||||
['Imported', $result['imported']],
|
||||
['Updated', $result['updated']],
|
||||
['Skipped', $result['skipped']],
|
||||
['Dry Run', $result['dry_run'] ? 'yes' : 'no'],
|
||||
]
|
||||
);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user