Exemplo n.º 1
0
 public static function isWindows()
 {
     return Utility::isWin();
 }
<?php

/* TODO better tune the queries for performance, including using prepared statements and
   pre-fetching groupid and other data for faster inclusion in the main query.
*/
use newznab\db\Settings;
use newznab\utility\Utility;
$config = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php';
if (!is_file($config)) {
    exit('Place this script in the testing folder of tmux.' . PHP_EOL);
}
require_once dirname(__FILE__) . '/../../www/config.php';
unset($config);
if (!Utility::isWin()) {
    $fullPath = DS;
    $paths = preg_split('#/#', NN_RES);
    foreach ($paths as $path) {
        if ($path !== '') {
            $fullPath .= $path . DS;
            if (!is_readable($fullPath) || !is_executable($fullPath)) {
                exit('The (' . $fullPath . ') folder must be readable and executable by all.' . PHP_EOL);
            }
        }
    }
    unset($fullPath, $paths, $path);
}
if (!is_writable(NN_RES)) {
    exit('The (' . NN_RES . ') folder must be writable.' . PHP_EOL);
}
$progress = rw_progress(settings_array());
if (!isset($argv[1]) || !is_numeric($argv[1]) && $argv[1] != 'progress' || !isset($argv[2]) || !in_array($argv[2], ['local', 'remote']) || !isset($argv[3]) || !in_array($argv[3], ['true', 'false'])) {
Exemplo n.º 3
0
 public function loadTables(array $options = [])
 {
     $defaults = ['ext' => 'tsv', 'files' => [], 'path' => NN_RES . 'db' . DS . 'schema' . DS . 'data', 'regex' => '#^' . Utility::PATH_REGEX . '(?P<order>\\d+)-(?P<table>\\w+)\\.tsv$#'];
     $options += $defaults;
     $files = empty($options['files']) ? Utility::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) {
         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);
                     echo "Inserting data into table: '{$table}'\n";
                     if (Utility::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}'");
         }
     }
 }