|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\FullTextSearch\Solr\Stores; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\FullTextSearch\Solr\Solr; |
|
6
|
|
|
use SilverStripe\FullTextSearch\Utils\WebDAV; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class SolrConfigStore_WebDAV |
|
10
|
|
|
* |
|
11
|
|
|
* A ConfigStore that uploads files to a Solr instance via a WebDAV server |
|
12
|
|
|
*/ |
|
13
|
|
|
class SolrConfigStore_WebDAV implements SolrConfigStore |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct($config) |
|
16
|
|
|
{ |
|
17
|
|
|
$options = Solr::solr_options(); |
|
18
|
|
|
|
|
19
|
|
|
$this->url = implode('', array( |
|
|
|
|
|
|
20
|
|
|
'http://', |
|
21
|
|
|
isset($config['auth']) ? $config['auth'] . '@' : '', |
|
22
|
|
|
$options['host'] . ':' . (isset($config['port']) ? $config['port'] : $options['port']), |
|
23
|
|
|
$config['path'] |
|
24
|
|
|
)); |
|
25
|
|
|
$this->remote = $config['remotepath']; |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getTargetDir($index) |
|
29
|
|
|
{ |
|
30
|
|
|
$indexdir = "{$this->url}/$index"; |
|
31
|
|
|
if (!WebDAV::exists($indexdir)) { |
|
|
|
|
|
|
32
|
|
|
WebDAV::mkdir($indexdir); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$targetDir = "{$this->url}/$index/conf"; |
|
36
|
|
|
if (!WebDAV::exists($targetDir)) { |
|
|
|
|
|
|
37
|
|
|
WebDAV::mkdir($targetDir); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $targetDir; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function uploadFile($index, $file) |
|
44
|
|
|
{ |
|
45
|
|
|
$targetDir = $this->getTargetDir($index); |
|
46
|
|
|
WebDAV::upload_from_file($file, $targetDir . '/' . basename($file)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function uploadString($index, $filename, $string) |
|
50
|
|
|
{ |
|
51
|
|
|
$targetDir = $this->getTargetDir($index); |
|
52
|
|
|
WebDAV::upload_from_string($string, "$targetDir/$filename"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function instanceDir($index) |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->remote ? "{$this->remote}/$index" : $index; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|