Update and add lithium based update scripts

This commit is contained in:
DariusIII
2016-04-15 10:34:12 +02:00
parent f82324afa6
commit a28a192c72
7 changed files with 361 additions and 31 deletions
+2
View File
@@ -1,3 +1,5 @@
2016-04-15 DariusIII
* Upd: Update and add lithium based update scripts
2016-04-14 DariusIII
* Upd: Add link to forum and fix forum pages
* Upd: Update composer and themes with new autosize and colorbox libs.
+49 -1
View File
@@ -73,4 +73,52 @@ use lithium\data\Connections;
// 'strict' => false
// ));
?>
$config1 = LITHIUM_APP_PATH . DS . 'config' . DS . 'db-config.php';
$config2 = NN_ROOT . 'nzedb' . DS . 'config' . DS . 'config.php';
$config = file_exists($config1) ? $config1 : $config2;
if (file_exists($config)) {
require_once $config;
switch (DB_TYPE) {
case 'mysql':
$adapter = 'MySql';
break;
case 'pgsql':
$adapter = 'PostgreSql';
break;
default:
break;
}
if (isset($adapter)) {
Connections::add('default',
[
'type' => 'database',
'adapter' => $adapter,
'host' => DB_HOST,
'port' => DB_PORT,
'login' => DB_USER,
'password' => DB_PASSWORD,
'database' => DB_NAME,
'encoding' => 'UTF-8',
'persistent' => false
]
);
}
} else {
/** throw new ErrorException("Couldn't open newznab-tmux configuration file!"); */
Connections::add('default',
[
'type' => 'database',
'adapter' => 'Mock',
'host' => 'localhost',
'port' => '3306',
'login' => 'root',
'password' => 'root_pass',
'database' => 'newznab',
'encoding' => 'UTF-8'
]
);
}
?>
+9
View File
@@ -49,6 +49,13 @@ class Update extends \app\extensions\console\Command
parent::__construct($config + $defaults);
}
public function db()
{
// TODO Add check to determine if the indexer or other scripts are running. Hopefully
// also prevent web access.
$this->primary("Checking Schema versions...");
}
public function git()
{
/*
@@ -56,12 +63,14 @@ class Update extends \app\extensions\console\Command
$this->gitBranch = $git->getBranch();
$this->gitTag = $git->tagLatest();
*/
$this->error("Not implemented yet!!");
}
public function nntmux()
{
try {
$this->composer();
$this->db();
} catch (Exception $e) {
$this->error($e->getMessage());
}
+59 -28
View File
@@ -19,8 +19,9 @@
namespace app\extensions\command;
use \Exception;
use \app\models\Settings;
use \app\extensions\util\Git;
use \lithium\console\command\Help;
use \newznab\utility\Git;
use newznab\utility\Utility;
@@ -36,16 +37,6 @@ use newznab\utility\Utility;
*/
class Version extends \app\extensions\console\Command
{
/**
* @var \newznab\utility\Git instance variable.
*/
//protected $git;
/**
* @var array of stable branches.
*/
//protected $stable = ['0.x'];
/**
* @var object simpleXMLElement
*/
@@ -81,34 +72,74 @@ class Version extends \app\extensions\console\Command
$this->sql();
}
protected function getGitTagFromFile()
{
$this->_loadVersionsFile();
return ($this->xml === null) ? null : $this->_vers->git->tag->__toString();
}
protected function getGitTagFromRepo()
{
$git = new Git();
return $git->tagLatest();
}
protected function getSQLPatchFromDB()
{
return Settings::find('setting', ['conditions' => '..sqlpatch']);
}
protected function getSQLPatchFromFile()
{
$this->_loadVersionsFile();
return ($this->xml === null) ? null : $this->_vers->sql->file->__toString();
}
/**
* Fetch git tag for latest version.
*
* @param null $versions Optional path to the versions XML file.
* @param null $path Optional path to the versions XML file.
*/
protected function git($versions = null)
protected function git()
{
$git = new Git();
$latest = $git->tagLatest();
$current = $this->getGitTagFromFile();
$latest = $this->getGitTagFromRepo();
$this->out("NNTmux version: $latest");
$this->primary('Looking up Git tag version(s)');
$this->out("XML version: $current");
$this->out("Git version: $latest");
}
/**
* Fetch SQL latest patch version.
*
* @param null $versions Optional path to the versions XML file.
* @param null $path Optional path to the versions XML file.
*/
protected function sql($versions = null)
protected function sql()
{
$this->_loadVersionsFile($versions);
$latest = $this->getSQLPatchFromFile();
$this->out("SQL version: $latest");
}
$this->request->params['args'] += ['sqlcheck' => 'all'];
$this->primary('Looking up SQL patch version(s)');
protected function getSQLPatchFromFile()
{
return ($this->xml === null) ? null : $this->_vers->sql->file->__toString();
if (in_array($this->request->params['args']['sqlcheck'], ['xml', 'both', 'all'])) {
$latest = $this->getSQLPatchFromFile();
$this->out("XML version: $latest");
}
if (in_array($this->request->params['args']['sqlcheck'], ['db', 'both', 'all'])) {
$dbpatch = self::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 ");
}
}
}
protected function _loadVersionsFile($versions = null)
@@ -130,13 +161,13 @@ class Version extends \app\extensions\console\Command
}
if ($this->xml->count() > 0) {
$vers = $this->xml->xpath('/newznab/versions');
$vers = $this->xml->xpath('/nzedb/versions');
if ($vers[0]->count() == 0) {
$this->error("Your versions XML file ({NN_VERSIONS}) does not contain version info, try updating from git.");
$this->error("Your versions XML file ($versions) does not contain version info, try updating from git.");
throw new \Exception("Failed to find versions node in XML file '$versions'");
} else {
$this->primary("Your versions XML file ({NN_VERSIONS}) looks okay, continuing.");
//$this->primary("Your versions XML file ($versions) looks okay, continuing.");
$this->_vers = &$this->xml->versions;
}
} else {
+8
View File
@@ -33,5 +33,13 @@ class Command extends \lithium\console\Command
parent::__construct($config + $defaults);
require_once NN_ROOT . 'constants.php';
}
public function primary($text)
{
if ($this->silent) {
return;
}
$this->out($text, 'primary');
}
}
?>
+165
View File
@@ -0,0 +1,165 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program (see LICENSE.txt in the base directory. If
* not, see:
*
* @link <http://www.gnu.org/licenses/>.
* @author niel
* @copyright 2016 nZEDb
*/
namespace app\extensions\util;
use \GitRepo;
class Git extends \lithium\core\Object
{
/**
* @var \GitRepo object
*/
protected $repo;
private $branch;
public function __construct(array $config = [])
{
$defaults = [
'branches' => ['0.x', 'dev', 'latest-testing', 'dev-test'],
'create' => false,
'initialise' => false,
'filepath' => NN_ROOT,
];
$config += $defaults;
parent::__construct($config);
}
/**
* Run describe command.
*
* @param string $options
*
* @return string
*/
public function describe($options = null)
{
return $this->run("describe $options");
}
/**
* Return the currently active branch
*
* @return string
*/
public function getBranch()
{
return $this->branch;
}
/**
* Determine if the supplied object is commited to the repository or not.
*
* @param $gitObject
*
* @return bool
* @throws \Exception
*/
public function isCommited($gitObject)
{
$cmd = "cat-file -e $gitObject";
try {
$result = $this->run($cmd);
} catch (\Exception $e) {
$message = explode("\n", $e->getMessage());
if ($message[0] === "fatal: Not a valid object name $gitObject") {
$result = false;
} else {
throw new \Exception($message);
}
}
return ($result === '');
}
/**
* Run the log command.
*
* @param null $options
*
* @return string
*/
public function log($options = null)
{
return $this->run("log $options");
}
/**
* Fetches the array of branch names that are considered to be core.
*
* @return array
*/
public function mainBranches()
{
return $this->_config->branches;
}
/**
* Run a git command in the git repository
* Accepts a git command to run
*
* @access public
*
* @param string $command Command to run
*
* @return string
*/
public function run($command)
{
return $this->repo->run($command);
}
/**
* Run the tag command.
*
* @param string $options
*
* @return string
*/
public function tag($options = null)
{
return $this->run("tag $options");
}
/**
* Fetch the most recently added tag.
*
* Be aware this might cause problems if tags are added out of order?
*
* @return string
*/
public function tagLatest()
{
return $this->describe("--tags --abbrev=0 HEAD");
}
protected function _init()
{
parent::_init();
$this->repo = new GitRepo(
$this->_config['filepath'],
$this->_config['create'],
$this->_config['initialise']
);
$this->branch = $this->repo->active_branch();
}
}
+69 -2
View File
@@ -19,9 +19,76 @@
namespace app\models;
/**
* Settings - model for settings table.
*
* li3 app completely ignore the 'setting' column and only uses 'section', 'subsection', and 'name'
* for finding values/hints.
*
*@package app\models
*/
class Settings extends \lithium\data\Model {
public $validates = array();
public $validates = [];
protected $_meta = [
'key' => ['section', 'subsection', 'name']
];
public static function init()
{
static::finder('setting',
function ($params, $next) {
if (!is_array($params['options']['conditions'])) {
$params['options']['conditions'] = self::dottedToArray($params['options']['conditions']);
} elseif (count($params) == 1) {
$params['options']['conditions'] = self::dottedToArray($params['options']['conditions'][0]);
}
$params['type'] = 'first';
$array = array_diff_key(
$params['options'],
array_fill_keys(['conditions', 'fields', 'order', 'limit', 'page'], 0)
);
$params['options'] = array_diff_key($params['options'], $array);
$params['options']['fields'] = ['value', 'hint'];
$result = $next($params);
return $result;
}
);
}
protected static function dottedToArray($setting)
{
$result = [];
if (is_string($setting)) {
$array = explode('.', $setting);
$count = count($array);
if ($count > 3) {
return false;
}
while (3 - $count > 0) {
array_unshift($array, '');
$count++;
}
list(
$result['section'],
$result['subsection'],
$result['name'],
) = $array;
} else {
return false;
}
//var_dump($result);
return $result;
}
}
?>
Settings::init();