1. Go to this page and download the library: Download trk/processwire-console library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
trk / processwire-console example snippets
declare(strict_types=1);
namespace ProcessWire;
return new class {
public function up(): void
{
$field = new Field();
$field->type = wire('modules')->get('FieldtypeText');
$field->name = 'subtitle';
$field->label = 'Subtitle';
wire('fields')->save($field);
}
public function down(): void
{
$field = wire('fields')->get('subtitle');
if (!$field || !$field->id) {
return;
}
// Guard: field must not be attached to any template
$fieldgroups = $field->getFieldgroups();
if ($fieldgroups->count() > 0) {
$names = $fieldgroups->implode(', ', 'name');
throw new WireException(
"Cannot delete field 'subtitle' — attached to: {$names}. Detach first."
);
}
wire('fields')->delete($field);
}
};
// site/commands/SyncProductsCommand.php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class SyncProductsCommand extends Command
{
protected function configure(): void
{
$this
->setName('products:sync')
->setDescription('Synchronize products from external API.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// Your logic here — $pages, $modules etc. are available via wire()
$io->success('Products synchronized.');
return Command::SUCCESS;
}
}
bash
php vendor/bin/wire make:queue SendEmailQueue
# Save directly to a specific module instead of the global site/queue directory
php vendor/bin/wire make:queue CompileImagesQueue --module=FieldtypeAiAssistant
bash
# Apply all pending
php vendor/bin/wire migrate
# Apply one at a time
php vendor/bin/wire migrate --step=1
# Preview without applying
php vendor/bin/wire migrate --dry-run
# Non-interactive
php vendor/bin/wire migrate --force
# JSON output
php vendor/bin/wire migrate --json