public function loadTables(array $options = []) { $defaults = ['ext' => 'tsv', 'files' => [], 'path' => nZEDb_RES . 'db' . DS . 'schema' . DS . 'data', 'regex' => '#^' . Misc::PATH_REGEX . '(?P<order>\\d+)-(?P<table>\\w+)\\.tsv$#']; $options += $defaults; $show = Misc::isCLI() || nZEDb_DEBUG; $files = empty($options['files']) ? Misc::getDirFiles($options) : $options['files']; natsort($files); $local = $this->pdo->isLocalDb() ? '' : 'LOCAL '; $sql = 'LOAD DATA ' . $local . 'INFILE "%s" IGNORE INTO TABLE `%s` FIELDS TERMINATED BY "\\t" OPTIONALLY ENCLOSED BY "\\"" IGNORE 1 LINES (%s)'; foreach ($files as $file) { if ($show === true) { echo "File: {$file}\n"; } if (is_readable($file)) { if (preg_match($options['regex'], $file, $matches)) { $table = $matches['table']; // Get the first line of the file which holds the columns used. $handle = @fopen($file, "r"); if (is_resource($handle)) { $line = fgets($handle); fclose($handle); if ($line === false) { echo "FAILED reading first line of '{$file}'\n"; continue; } $fields = trim($line); if ($show === true) { echo "Inserting data into table: '{$table}'\n"; } if (Misc::isWin()) { $file = str_replace("\\", '\\/', $file); } $this->pdo->exec(sprintf($sql, $file, $table, $fields)); } else { exit("Failed to open file: '{$file}'\n"); } } else { echo "Incorrectly formatted filename '{$file}' (should match " . str_replace('#', '', $options['regex']) . "\n"; } } else { echo $this->log->error(" Unable to read file: '{$file}'"); } } }
/** * Constructor. Sets up all necessary properties. Instantiates a PDO object * if needed, otherwise returns the current one. * * @param array $options */ public function __construct(array $options = []) { $this->cli = Misc::isCLI(); $defaults = ['checkVersion' => false, 'createDb' => false, 'ct' => new ConsoleTools(), 'dbhost' => defined('DB_HOST') ? DB_HOST : '', 'dbname' => defined('DB_NAME') ? DB_NAME : '', 'dbpass' => defined('DB_PASSWORD') ? DB_PASSWORD : '', 'dbport' => defined('DB_PORT') ? DB_PORT : '', 'dbsock' => defined('DB_SOCKET') ? DB_SOCKET : '', 'dbtype' => defined('DB_SYSTEM') ? DB_SYSTEM : '', 'dbuser' => defined('DB_USER') ? DB_USER : '', 'log' => new ColorCLI(), 'persist' => false]; $options += $defaults; if (!$this->cli) { $options['log'] = null; } $this->opts = $options; if (!empty($this->opts['dbtype'])) { $this->dbSystem = strtolower($this->opts['dbtype']); } if (!$this->pdo instanceof \PDO) { $this->initialiseDatabase(); } $this->cacheEnabled = defined('nZEDb_CACHE_TYPE') && nZEDb_CACHE_TYPE > 0 ? true : false; if ($this->cacheEnabled) { try { $this->cacheServer = new Cache(); } catch (CacheException $error) { $this->cacheEnabled = false; $this->echoError($error->getMessage(), '__construct', 4); } } $this->ct = $this->opts['ct']; $this->log = $this->opts['log']; $this->_debug = nZEDb_DEBUG || nZEDb_LOGGING; if ($this->_debug) { try { $this->debugging = new Logger(['ColorCLI' => $this->log]); } catch (LoggerException $error) { $this->_debug = false; } } if ($this->opts['checkVersion']) { $this->fetchDbVersion(); } if (defined('nZEDb_SQL_DELETE_LOW_PRIORITY') && nZEDb_SQL_DELETE_LOW_PRIORITY) { $this->DELETE_LOW_PRIORITY = ' LOW_PRIORITY '; } if (defined('nZEDb_SQL_DELETE_QUICK') && nZEDb_SQL_DELETE_QUICK) { $this->DELETE_QUICK = ' QUICK '; } return $this->pdo; }
<?php require_once './config.php'; use nzedb\NZBExport; use nzedb\Releases; use nzedb\utility\Misc; if (Misc::isCLI()) { exit('This script is only for exporting from the web, use the script in misc/testing' . PHP_EOL); } $page = new AdminPage(); $rel = new Releases(['Settings' => $page->settings]); $folder = $group = $fromDate = $toDate = $gzip = $output = ''; if ($page->isPostBack()) { $folder = $_POST["folder"]; $fromDate = isset($_POST["postfrom"]) ? $_POST["postfrom"] : ''; $toDate = isset($_POST["postto"]) ? $_POST["postto"] : ''; $group = $_POST["group"]; $gzip = $_POST["gzip"]; if ($folder != '') { $output = (new NZBExport(['Browser' => true, 'Settings' => $page->settings, 'Releases' => $rel]))->beginExport([$folder, $fromDate, $toDate, $_POST["group"] === '-1' ? 0 : (int) $_POST["group"], $_POST["gzip"] === '1' ? true : false]); } else { $output = 'Error, a path is required!'; } } else { $fromDate = $rel->getEarliestUsenetPostDate(); $toDate = $rel->getLatestUsenetPostDate(); } $page->title = "Export Nzbs"; $page->smarty->assign(['output' => $output, 'folder' => $folder, 'fromdate' => $fromDate, 'todate' => $toDate, 'group' => $group, 'gzip' => $gzip, 'gziplist' => [1 => 'True', 0 => 'False'], 'grouplist' => $rel->getReleasedGroupsForSelect(true)]); $page->content = $page->smarty->fetch('nzb-export.tpl'); $page->render();
* 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 2015 nZEDb */ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'indexer.php'; use nzedb\db\DbUpdate; use nzedb\utility\Git; use nzedb\utility\Misc; if (!Misc::isCLI()) { exit; } $error = false; $git = new Git(); $branch = $git->active_branch(); if (in_array($branch, $git->mainBranches())) { // Only update patches, etc. on specific branches to lessen conflicts try { // Run DbUpdates to make sure we're up to date. $DbUpdater = new DbUpdate(['git' => $git]); $DbUpdater->newPatches(['safe' => false]); } catch (\Exception $e) { $error = 1; echo "Error while checking patches!\n"; echo $e->getMessage() . "\n";
case $fields['unrarpath'] != '' && !is_file($fields['unrarpath']): $error = Settings::ERR_BADUNRARPATH; break; case empty($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH_UNSET; break; case !file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH; break; case !is_readable($fields['nzbpath']): $error = Settings::ERR_BADNZBPATH_UNREADABLE; break; case $fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath']): $error = Settings::ERR_DEEPNOUNRAR; break; case $fields['tmpunrarpath'] != '' && !file_exists($fields['tmpunrarpath']): $error = Settings::ERR_BADTMPUNRARPATH; break; case $fields['yydecoderpath'] != '' && $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && !file_exists($fields['yydecoderpath']): $error = Settings::ERR_BAD_YYDECODER_PATH; } return $error; } } /* * Putting procedural stuff inside class scripts like this is BAD. Do not use this as an excuse to do more. * This is a temporary measure until a proper frontend for cli stuff can be implemented with li3. */ if (Misc::isCLI() && isset($argv[1])) { echo (new Settings())->getSetting($argv[1]); }
public function getValidVersionsFile($filepath = null) { $filepath = empty($filepath) ? $this->_filespec : $filepath; $temp = libxml_use_internal_errors(true); $this->_xml = simplexml_load_file($filepath); libxml_use_internal_errors($temp); if ($this->_xml === false) { if (Misc::isCLI()) { $this->out->error("Your versions XML file ({$filepath}) is broken, try updating from git."); } throw new \Exception("Failed to open versions XML file '{$filepath}'"); } if ($this->_xml->count() > 0) { $vers = $this->_xml->xpath('/nzedb/versions'); if ($vers[0]->count() == 0) { $this->out->error("Your versions XML file ({nZEDb_VERSIONS}) does not contain version info, try updating from git."); throw new \Exception("Failed to find versions node in XML file '{$filepath}'"); } else { $this->out->primary("Your versions XML file ({nZEDb_VERSIONS}) looks okay, continuing."); $this->_vers =& $this->_xml->versions; } } else { throw new \RuntimeException("No elements in file!\n"); } return $this->_xml; }