itsblue-website/plugins/git-sync/cli/SyncCommand.php

50 lines
1.2 KiB
PHP
Executable file

<?php
namespace Grav\Plugin\Console;
use Grav\Console\ConsoleCommand;
use Grav\Plugin\GitSync\GitSync;
/**
* Class LogCommand
*
* @package Grav\Plugin\Console
*/
class SyncCommand extends ConsoleCommand
{
protected function configure()
{
$this
->setName('sync')
->setDescription('Performs a synchronization of your site')
->setHelp('The <info>sync</info> command performs a synchronization of your site. Useful if you want to run a periodic crontab job to automate it.')
;
}
protected function serve()
{
$plugin = new GitSync();
$repository = $plugin->getConfig('repository', false);
$this->output->writeln('');
if (!$repository) {
$this->output->writeln('<red>ERROR:</red> No repository has been configured');
}
$this->output->writeln('Synchronizing with <cyan>' . $repository . '</cyan>');
if ($plugin->hasChangesToCommit()) {
$this->output->writeln('Changes detected, adding and committing...');
$plugin->add();
$plugin->commit();
}
$this->output->write('Starting Synchronization...');
$plugin->sync();
$this->output->writeln('completed.');
}
}