. * @author niel * @copyright 2016 nZEDb */ namespace app\extensions\command; use \app\extensions\util\Versions; use \lithium\console\command\Help; /** * Returns the current version (or branch) of the indexer. * * Actions: * * all Show all of following info. * * branch Show git branch name. * * git Show git tag for current version. * * sql Show SQL patch level * * @package app\extensions\command */ class Version extends \app\extensions\console\Command { /** * @var \app\extensions\util\Versions; */ protected $versions = null; /** * Constructor. * * @param array $config */ public function __construct(array $config = []) { $defaults = [ 'classes' => $this->_classes, 'request' => null, 'response' => [], ]; parent::__construct($config + $defaults); } public function run() { if (!$this->request->args()) { return $this->_help(); } return false; } protected function all() { $this->git(); $this->sql(); } protected function branch() { $this->primary('Git branch: ' . $this->versions->getGitBranch()); } /** * Fetch git tag for latest version. * * @param null $path Optional path to the versions XML file. */ protected function git() { if (!$this->plain) { $this->primary('Looking up Git tag version(s)'); } $this->out('Hash: ' . $this->versions->getGitHeadHash(), 0); $this->out('XML version: ' . $this->versions->getGitTagInFile()); $this->out('Git version: ' . $this->versions->getGitTagInRepo()); } /** * Fetch SQL latest patch version. * * @param null $path Optional path to the versions XML file. */ protected function sql() { if (!$this->plain) { $this->primary('Looking up SQL patch version(s)'); } if (in_array($this->request->params['args']['sqlcheck'], ['xml', 'both', 'all'])) { $latest = $this->versions->getSQLPatchFromFile(); $this->out("XML version: $latest"); } if (in_array($this->request->params['args']['sqlcheck'], ['db', 'both', 'all'])) { $dbpatch = $this->versions->getSQLPatchFromDB(); if ($dbpatch->count()) { $dbVersion = $dbpatch->data()[0]['value']; if (!is_numeric($dbVersion)) { $this->error("Bad sqlpatch value: '$dbVersion'\n"); } else { $this->out(" DB version: " . $dbVersion); } } else { $this->error("Unable to fetch Databse SQL level!"); } } } /** * Invokes the `Help` command. * The invoked Help command will take over request and response objects of * the originally invoked command. Thus the response of the Help command * becomes the response of the original one. * * @return boolean */ protected function _help() { $help = new Help([ 'request' => $this->request, 'response' => $this->response, 'classes' => $this->_classes ]); return $help->run(get_class($this)); } /** * Class initializer. Parses template and sets up params that need to be filled. * * @return void */ protected function _init() { parent::_init(); $this->request->params['args'] += ['sqlcheck' => 'all']; // Default to all versions/ $this->versions = new Versions(); } }