The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit d58c4c22 authored by Demian Katz's avatar Demian Katz
Browse files

Inject configuration into File stats driver; throw exception if unable to open file.

parent d0acb00e
No related merge requests found
......@@ -532,9 +532,16 @@ $config = array(
),
'statistics_driver' => array(
'abstract_factories' => array('VuFind\Statistics\Driver\PluginFactory'),
'factories' => array(
'file' => function ($sm) {
$config = \VuFind\Config\Reader::getConfig();
$folder = isset($config->Statistics->file)
? $config->Statistics->file : sys_get_temp_dir();
return new \VuFind\Statistics\Driver\File($folder);
},
),
'invokables' => array(
'db' => 'VuFind\Statistics\Driver\Db',
'file' => 'VuFind\Statistics\Driver\File',
'solr' => 'VuFind\Statistics\Driver\Solr',
),
'aliases' => array(
......
......@@ -26,7 +26,6 @@
* @link http://vufind.org Main Site
*/
namespace VuFind\Statistics\Driver;
use VuFind\Config\Reader as ConfigReader;
/**
* Writer to put statistics into an XML File
......@@ -39,7 +38,22 @@ use VuFind\Config\Reader as ConfigReader;
*/
class File extends AbstractBase
{
protected $folder = null;
/**
* Folder where stats will be written.
*
* @var string
*/
protected $folder;
/**
* Constructor
*
* @param string $folder Folder where stats will be written.
*/
public function __construct($folder)
{
$this->folder = $folder;
}
/**
* Get the name of the folder for storing statistics.
......@@ -48,10 +62,6 @@ class File extends AbstractBase
*/
protected function getFolder()
{
if (null === $this->folder) {
$configs = ConfigReader::getConfig();
$this->folder = $configs->Statistics->file;
}
return $this->folder;
}
......@@ -61,6 +71,7 @@ class File extends AbstractBase
* @param array $data Data specific to what we're saving
* @param array $userData Browser, IP, urls, etc
*
* @throws \Exception
* @return void
*/
public function write($data, $userData)
......@@ -81,6 +92,9 @@ class File extends AbstractBase
$xml .= "\n</xml>";
}
$file = fopen($filename, 'w');
if (!$file) {
throw new \Exception('Cannot write to log file.');
}
fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $xml);
fclose($file);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment