Esempio n. 1
0
 /**
  * Return search specs
  *
  * @param string $filename config file name
  *
  * @return array
  */
 public function get($filename)
 {
     // Load data if it is not already in the object's cache:
     if (!isset($this->searchSpecs[$filename])) {
         // Connect to searchspecs cache:
         $cache = null !== $this->cacheManager ? $this->cacheManager->getCache('searchspecs') : false;
         // Determine full configuration file path:
         $fullpath = Locator::getBaseConfigPath($filename);
         $local = Locator::getLocalConfigPath($filename);
         // Generate cache key:
         $cacheKey = $filename . '-' . (file_exists($fullpath) ? filemtime($fullpath) : 0);
         if (!empty($local)) {
             $cacheKey .= '-local-' . filemtime($local);
         }
         $cacheKey = md5($cacheKey);
         // Generate data if not found in cache:
         if ($cache === false || !($results = $cache->getItem($cacheKey))) {
             $results = file_exists($fullpath) ? Yaml::parse(file_get_contents($fullpath)) : [];
             if (!empty($local)) {
                 $localResults = Yaml::parse(file_get_contents($local));
                 foreach ($localResults as $key => $value) {
                     $results[$key] = $value;
                 }
             }
             if ($cache !== false) {
                 $cache->setItem($cacheKey, $results);
             }
         }
         $this->searchSpecs[$filename] = $results;
     }
     return $this->searchSpecs[$filename];
 }
Esempio n. 2
0
 /**
  * Return search specs
  *
  * @param string $filename config file name
  *
  * @return array
  */
 public function get($filename)
 {
     // Load data if it is not already in the object's cache:
     if (!isset($this->searchSpecs[$filename])) {
         $this->searchSpecs[$filename] = $this->getFromPaths(Locator::getBaseConfigPath($filename), Locator::getLocalConfigPath($filename));
     }
     return $this->searchSpecs[$filename];
 }
Esempio n. 3
0
 /**
  * Configuration management
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function homeAction()
 {
     $view = $this->createViewModel();
     $view->setTemplate('admin/config/home');
     $view->baseConfigPath = \VuFind\Config\Locator::getBaseConfigPath('');
     $conf = $this->getConfig();
     $view->showInstallLink = isset($conf->System->autoConfigure) && $conf->System->autoConfigure;
     return $view;
 }
Esempio n. 4
0
 /**
  * Support method for changeConfig; act on a single file.
  *
  * @param string $configName Configuration to modify.
  * @param array  $settings   Settings to change.
  * @param bool   $replace    Should we replace the existing config entirely
  * (as opposed to extending it with new settings)?
  *
  * @return void
  */
 protected function changeConfigFile($configName, $settings, $replace = false)
 {
     $file = $configName . '.ini';
     $local = ConfigLocator::getLocalConfigPath($file, null, true);
     if (file_exists($local)) {
         // File exists? Make a backup!
         copy($local, $local . '.bak');
     } else {
         // File doesn't exist? Make a baseline version.
         copy(ConfigLocator::getBaseConfigPath($file), $local);
     }
     // If we're replacing the existing file, wipe it out now:
     if ($replace) {
         file_put_contents($local, '');
     }
     $writer = new ConfigWriter($local);
     foreach ($settings as $section => $contents) {
         foreach ($contents as $key => $value) {
             $writer->set($section, $key, $value);
         }
     }
     $writer->save();
 }
Esempio n. 5
0
 /**
  * Upgrade the configuration files.
  *
  * @return mixed
  */
 public function fixconfigAction()
 {
     $localConfig = dirname(ConfigLocator::getLocalConfigPath('config.ini', null, true));
     $confDir = $this->cookie->oldVersion < 2 ? $this->cookie->sourceDir . '/web/conf' : $localConfig;
     $upgrader = new \VuFind\Config\Upgrade($this->cookie->oldVersion, $this->cookie->newVersion, $confDir, dirname(ConfigLocator::getBaseConfigPath('config.ini')), $localConfig);
     try {
         $upgrader->run();
         $this->cookie->warnings = $upgrader->getWarnings();
         $this->cookie->configOkay = true;
         return $this->forwardTo('Upgrade', 'Home');
     } catch (\Exception $e) {
         $extra = is_a($e, 'VuFind\\Exception\\FileAccess') ? '  Check file permissions.' : '';
         $this->flashMessenger()->addMessage('Config upgrade failed: ' . $e->getMessage() . $extra, 'error');
         return $this->forwardTo('Upgrade', 'Error');
     }
 }
Esempio n. 6
0
 /**
  * Display repair instructions for ILS problems.
  *
  * @return mixed
  */
 public function fixilsAction()
 {
     // Process incoming parameter -- user may have selected a new driver:
     $newDriver = $this->params()->fromPost('driver');
     if (!empty($newDriver)) {
         $configPath = ConfigLocator::getLocalConfigPath('config.ini', null, true);
         $writer = new ConfigWriter($configPath);
         $writer->set('Catalog', 'driver', $newDriver);
         if (!$writer->save()) {
             return $this->forwardTo('Install', 'fixbasicconfig');
         }
         // Copy configuration, if applicable:
         $ilsIni = ConfigLocator::getBaseConfigPath($newDriver . '.ini');
         $localIlsIni = ConfigLocator::getLocalConfigPath("{$newDriver}.ini", null, true);
         if (file_exists($ilsIni) && !file_exists($localIlsIni)) {
             if (!copy($ilsIni, $localIlsIni)) {
                 return $this->forwardTo('Install', 'fixbasicconfig');
             }
         }
         return $this->redirect()->toRoute('install-home');
     }
     // If we got this far, check whether we have an error with a real driver
     // or if we need to warn the user that they have selected a fake driver:
     $config = $this->getConfig();
     $view = $this->createViewModel();
     if (in_array($config->Catalog->driver, ['Sample', 'Demo'])) {
         $view->demo = true;
         // Get a list of available drivers:
         $dir = opendir(APPLICATION_PATH . '/module/VuFind/src/VuFind/ILS/Driver');
         $drivers = [];
         $blacklist = ['Sample.php', 'Demo.php', 'DriverInterface.php', 'AbstractBase.php', 'PluginManager.php', 'PluginFactory.php'];
         while ($line = readdir($dir)) {
             if (stristr($line, '.php') && !in_array($line, $blacklist)) {
                 $drivers[] = str_replace('.php', '', $line);
             }
         }
         closedir($dir);
         sort($drivers);
         $view->drivers = $drivers;
     } else {
         $view->configPath = ConfigLocator::getLocalConfigPath("{$config->Catalog->driver}.ini", null, true);
     }
     return $view;
 }