Custom Commands & Troubleshooting
Totoglu\Console\Support\FeatureDiscoverer automatically discovers custom Symfony Console commands in two ways:
- Module Auto-Discovery: Place
*Command.phpfiles insidesite/modules/<Module>/commands/(registered under the module’sCommandsnamespace). - Composer Package Discovery: Declare command class names inside your package’s
composer.jsonunderextra.processwire-console.commands:
{ "extra": { "processwire-console": { "commands": [ "Vendor\\Package\\Commands\\SyncCatalogCommand" ] } }}Authoring a Custom Command
Section titled “Authoring a Custom Command”Use Totoglu\Console\Traits\InteractWithProcessWire to access the booted ProcessWire instance cleanly and support --dry-run and --json output:
<?php
declare(strict_types=1);
namespace Totoglu\MyModule\Commands;
use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Input\InputOption;use Symfony\Component\Console\Output\OutputInterface;use Totoglu\Console\Traits\InteractWithProcessWire;
final class CatalogStatusCommand extends Command{ use InteractWithProcessWire;
protected function configure(): void { $this ->setName('catalog:status') ->setDescription('Inspect published catalog item counts.') ->addOption('json', null, InputOption::VALUE_NONE, 'Output structured JSON.'); }
protected function execute(InputInterface $input, OutputInterface $output): int { $count = $this->wire()->pages->count('template=yacht'); if ($input->getOption('json')) { $output->writeln(json_encode(['yachts' => $count], JSON_THROW_ON_ERROR)); return Command::SUCCESS; }
$output->writeln("Published yachts: {$count}"); return Command::SUCCESS; }}Troubleshooting
Section titled “Troubleshooting”vendor/bin/wire Cannot Locate ProcessWire Root
Section titled “vendor/bin/wire Cannot Locate ProcessWire Root”- Run
php vendor/bin/wirefrom your ProcessWire project root (the directory containingindex.phpandsite/config.php).
Module Commands Do Not Appear in wire list
Section titled “Module Commands Do Not Appear in wire list”- Confirm the module is installed in ProcessWire (
php vendor/bin/wire module:list --site --json) and that itscommands/*Command.phpnamespace is registered in__construct().
queue:work Exits Immediately or Skips Jobs
Section titled “queue:work Exits Immediately or Skips Jobs”- Verify
queue_jobsexists by runningphp vendor/bin/wire queue:table --json, and check failed jobs viaphp vendor/bin/wire queue:failed --json.