Exemple #1
0
 public function updateSchemaData(array $options = [])
 {
     $changed = false;
     $default = ['file' => '10-settings.tsv', 'path' => 'resources' . DS . 'db' . DS . 'schema' . DS . 'data' . DS, 'regex' => '#^(?P<section>.*)\\t(?P<subsection>.*)\\t(?P<name>.*)\\t(?P<value>.*)\\t(?P<hint>.*)\\t(?P<setting>.*)$#', 'value' => function (array $matches) {
         return "{$matches['section']}\t{$matches['subsection']}\t{$matches['name']}\t{$matches['value']}\t{$matches['hint']}\t{$matches['setting']}";
     }];
     $options += $default;
     $file = [];
     $filespec = Utility::trailingSlash($options['path']) . $options['path'];
     if (file_exists($filespec) && ($file = file($filespec, FILE_IGNORE_NEW_LINES))) {
         $count = count($file);
         $index = 0;
         while ($index < $count) {
             if (preg_match($options['regex'], $file[$index], $matches)) {
                 if (VERBOSE) {
                     echo $this->log->primary("Matched: " . $file[$index]);
                 }
                 $index++;
                 if (is_callable($options['value'])) {
                     $file[$index] = $options['value']($matches);
                 } else {
                     $file[$index] = $options['value'];
                 }
                 $changed = true;
             }
         }
     }
     if ($changed) {
         if (file_put_contents($filespec, implode("\n", $file)) === false) {
             echo $this->log->error("Error writing file to disc!!");
         }
     }
 }
Exemple #2
0
 protected function _validate(array $fields)
 {
     ksort($fields);
     // Validate settings
     $fields['nzbpath'] = Utility::trailingSlash($fields['nzbpath']);
     $error = null;
     switch (true) {
         case $fields['mediainfopath'] != "" && !is_file($fields['mediainfopath']):
             $error = Settings::ERR_BADMEDIAINFOPATH;
             break;
         case $fields['ffmpegpath'] != "" && !is_file($fields['ffmpegpath']):
             $error = Settings::ERR_BADFFMPEGPATH;
             break;
         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;
 }