2017-04-21 03:08:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\FullTextSearch\Solr\Stores;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SolrConfigStore_File
|
|
|
|
*
|
|
|
|
* A ConfigStore that uploads files to a Solr instance on a locally accessible filesystem
|
|
|
|
* by just using file copies
|
|
|
|
*/
|
|
|
|
class SolrConfigStore_File implements SolrConfigStore
|
|
|
|
{
|
|
|
|
public function __construct($config)
|
|
|
|
{
|
|
|
|
$this->local = $config['path'];
|
2021-08-23 13:55:13 +02:00
|
|
|
$this->remote = !empty($config['remotepath']) ? $config['remotepath'] : $config['path'];
|
2017-04-21 03:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTargetDir($index)
|
|
|
|
{
|
|
|
|
$targetDir = "{$this->local}/{$index}/conf";
|
|
|
|
|
2022-04-13 01:24:03 +02:00
|
|
|
if (!is_dir($targetDir ?? '')) {
|
|
|
|
$worked = @mkdir($targetDir ?? '', 0770, true);
|
2017-04-21 03:08:14 +02:00
|
|
|
|
|
|
|
if (!$worked) {
|
2017-04-26 13:23:37 +02:00
|
|
|
throw new \RuntimeException(
|
2017-04-21 03:08:14 +02:00
|
|
|
sprintf('Failed creating target directory %s, please check permissions', $targetDir)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $targetDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadFile($index, $file)
|
|
|
|
{
|
|
|
|
$targetDir = $this->getTargetDir($index);
|
2022-04-13 01:24:03 +02:00
|
|
|
copy($file ?? '', $targetDir . '/' . basename($file ?? ''));
|
2017-04-21 03:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadString($index, $filename, $string)
|
|
|
|
{
|
|
|
|
$targetDir = $this->getTargetDir($index);
|
|
|
|
file_put_contents("$targetDir/$filename", $string);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function instanceDir($index)
|
|
|
|
{
|
2018-06-27 06:50:54 +02:00
|
|
|
return $this->remote . '/' . $index;
|
2017-04-21 03:08:14 +02:00
|
|
|
}
|
2017-11-14 21:48:52 +01:00
|
|
|
}
|