mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-30 17:58:59 +00:00
Add default constructor to Sites class
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2015-10-26 DariusIII
|
||||
Upd: Sites class, add default constructor
|
||||
Upd: Refactor TV support
|
||||
2015-10-21 DariusIII
|
||||
Fix: NZB error in processing/post/AniDB
|
||||
|
||||
+42
-11
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
namespace newznab;
|
||||
|
||||
use newznab\db\DB;
|
||||
use newznab\db\Settings;
|
||||
use newznab\libraries\Cache;
|
||||
use newznab\utility\Versions;
|
||||
|
||||
|
||||
class Sites
|
||||
{
|
||||
@@ -20,6 +22,38 @@ class Sites
|
||||
const ERR_BADLAMEPATH = -7;
|
||||
const ERR_SABCOMPLETEPATH = -8;
|
||||
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
protected $_db;
|
||||
|
||||
/**
|
||||
* @var \newznab\utility\Versions|bool
|
||||
*/
|
||||
protected $_versions = false;
|
||||
|
||||
/**
|
||||
* @param array $options Class instances.
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$defaults = [
|
||||
'Settings' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->_db = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings());
|
||||
|
||||
if (defined('NN_VERSIONS')) {
|
||||
try {
|
||||
$this->_versions = new Versions(NN_VERSIONS);
|
||||
} catch (\Exception $e) {
|
||||
$this->_versions = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function version()
|
||||
{
|
||||
return "0.4.1 nn-tmux-regexless";
|
||||
@@ -27,7 +61,6 @@ class Sites
|
||||
|
||||
public function update($form)
|
||||
{
|
||||
$db = new DB();
|
||||
$site = $this->row2Object($form);
|
||||
|
||||
if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/')
|
||||
@@ -62,11 +95,11 @@ class Sites
|
||||
|
||||
$sql = $sqlKeys = [];
|
||||
foreach ($form as $settingK => $settingV) {
|
||||
$sql[] = sprintf("WHEN %s THEN %s", $db->escapeString($settingK), $db->escapeString(trim($settingV)));
|
||||
$sqlKeys[] = $db->escapeString($settingK);
|
||||
$sql[] = sprintf("WHEN %s THEN %s", $this->_db->escapeString($settingK), $this->_db->escapeString(trim($settingV)));
|
||||
$sqlKeys[] = $this->_db->escapeString($settingK);
|
||||
}
|
||||
|
||||
$db->exec(sprintf("update site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys)));
|
||||
$this->_db->exec(sprintf("update site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys)));
|
||||
|
||||
return $this->get(true);
|
||||
}
|
||||
@@ -80,8 +113,7 @@ class Sites
|
||||
$cache->delete($sql);
|
||||
}
|
||||
|
||||
$db = new DB();
|
||||
$rows = $db->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
$rows = $this->_db->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
|
||||
|
||||
if ($rows === false)
|
||||
return false;
|
||||
@@ -132,10 +164,9 @@ class Sites
|
||||
|
||||
public function updateItem($setting, $value)
|
||||
{
|
||||
$db = new DB();
|
||||
$sql = sprintf("update settings set value = %s where setting = %s", $db->escapeString($value), $db->escapeString($setting));
|
||||
$sql = sprintf("update settings set value = %s where setting = %s", $this->_db->escapeString($value), $this->_db->escapeString($setting));
|
||||
|
||||
return $db->exec($sql);
|
||||
return $this->_db->exec($sql);
|
||||
}
|
||||
|
||||
public function updateLatestRegexRevision($rev)
|
||||
@@ -154,4 +185,4 @@ class Sites
|
||||
This program is distributed with a commercial licence. See LICENCE.txt for
|
||||
further details." . $n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user