mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Merge pull request #295 from andrewandante/feature/add_post_config_store
[CMS3] Add POST config store
This commit is contained in:
commit
c1eeaca2a0
@ -27,7 +27,7 @@ class Solr
|
||||
*
|
||||
* indexstore => an array with
|
||||
*
|
||||
* mode - a classname which implements SolrConfigStore, or 'file' or 'webdav'
|
||||
* mode - a classname which implements SolrConfigStore, or 'file', 'webdav' or 'post'
|
||||
*
|
||||
* When mode == SolrConfigStore_File or file (indexes should be written on a local filesystem)
|
||||
* path - The (locally accessible) path to write the index configurations to.
|
||||
@ -38,6 +38,13 @@ class Solr
|
||||
* path (default: /solrindex) - The suburl on the solr host that is set up to accept index configurations via webdav
|
||||
* port (default: none) - The port for WebDAV if different from the Solr port
|
||||
* remotepath - The path that the Solr server will read the index configurations from
|
||||
*
|
||||
* When mode == SolrConfigStore_POST or 'post' (indexes should stored on a remote Solr server via post)
|
||||
* This mode will require custom software on the remote solr server which handles receiving the post and
|
||||
* passing on that information to solr. It is up to the user of this mode to write such software.
|
||||
* path (default: /solrindex) - The suburl on the solr host that is set up to accept index configurations
|
||||
* port (default: none) - The port on the remote server which is set up to receive the post information
|
||||
*
|
||||
*/
|
||||
protected static $solr_options = array();
|
||||
|
||||
@ -298,6 +305,8 @@ class Solr_Configure extends Solr_BuildTask
|
||||
return new SolrConfigStore_File($indexstore);
|
||||
} elseif ($mode == 'webdav') {
|
||||
return new SolrConfigStore_WebDAV($indexstore);
|
||||
} elseif ($mode == 'post') {
|
||||
return new SolrConfigStore_POST($indexstore);
|
||||
} elseif (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, 'SolrConfigStore')) {
|
||||
return new $mode($indexstore);
|
||||
} else {
|
||||
|
@ -30,105 +30,3 @@ interface SolrConfigStore
|
||||
*/
|
||||
public function instanceDir($index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
$this->remote = isset($config['remotepath']) ? $config['remotepath'] : $config['path'];
|
||||
}
|
||||
|
||||
public function getTargetDir($index)
|
||||
{
|
||||
$targetDir = "{$this->local}/{$index}/conf";
|
||||
|
||||
if (!is_dir($targetDir)) {
|
||||
$worked = @mkdir($targetDir, 0770, true);
|
||||
|
||||
if (!$worked) {
|
||||
throw new RuntimeException(
|
||||
sprintf('Failed creating target directory %s, please check permissions', $targetDir)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $targetDir;
|
||||
}
|
||||
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
copy($file, $targetDir.'/'.basename($file));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
file_put_contents("$targetDir/$filename", $string);
|
||||
}
|
||||
|
||||
public function instanceDir($index)
|
||||
{
|
||||
return $this->remote.'/'.$index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class SolrConfigStore_WebDAV
|
||||
*
|
||||
* A ConfigStore that uploads files to a Solr instance via a WebDAV server
|
||||
*/
|
||||
class SolrConfigStore_WebDAV implements SolrConfigStore
|
||||
{
|
||||
public function __construct($config)
|
||||
{
|
||||
$options = Solr::solr_options();
|
||||
|
||||
$this->url = implode('', array(
|
||||
'http://',
|
||||
isset($config['auth']) ? $config['auth'].'@' : '',
|
||||
$options['host'].':'.(isset($config['port']) ? $config['port'] : $options['port']),
|
||||
$config['path']
|
||||
));
|
||||
$this->remote = $config['remotepath'];
|
||||
}
|
||||
|
||||
public function getTargetDir($index)
|
||||
{
|
||||
$indexdir = "{$this->url}/$index";
|
||||
if (!WebDAV::exists($indexdir)) {
|
||||
WebDAV::mkdir($indexdir);
|
||||
}
|
||||
|
||||
$targetDir = "{$this->url}/$index/conf";
|
||||
if (!WebDAV::exists($targetDir)) {
|
||||
WebDAV::mkdir($targetDir);
|
||||
}
|
||||
|
||||
return $targetDir;
|
||||
}
|
||||
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
WebDAV::upload_from_file($file, $targetDir.'/'.basename($file));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
WebDAV::upload_from_string($string, "$targetDir/$filename");
|
||||
}
|
||||
|
||||
public function instanceDir($index)
|
||||
{
|
||||
return $this->remote ? "{$this->remote}/$index" : $index;
|
||||
}
|
||||
}
|
||||
|
50
code/solr/configstore/SolrConfigStore_File.php
Normal file
50
code/solr/configstore/SolrConfigStore_File.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
$this->remote = isset($config['remotepath']) ? $config['remotepath'] : $config['path'];
|
||||
}
|
||||
|
||||
public function getTargetDir($index)
|
||||
{
|
||||
$targetDir = "{$this->local}/{$index}/conf";
|
||||
|
||||
if (!is_dir($targetDir)) {
|
||||
$worked = @mkdir($targetDir, 0770, true);
|
||||
|
||||
if (!$worked) {
|
||||
throw new RuntimeException(
|
||||
sprintf('Failed creating target directory %s, please check permissions', $targetDir)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $targetDir;
|
||||
}
|
||||
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
copy($file, $targetDir.'/'.basename($file));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
file_put_contents("$targetDir/$filename", $string);
|
||||
}
|
||||
|
||||
public function instanceDir($index)
|
||||
{
|
||||
return $this->remote.'/'.$index;
|
||||
}
|
||||
}
|
51
code/solr/configstore/SolrConfigStore_POST.php
Normal file
51
code/solr/configstore/SolrConfigStore_POST.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Class SolrConfigStore_POST
|
||||
*
|
||||
* A ConfigStore that uploads files to a Solr instance via a WebDAV server
|
||||
*/
|
||||
class SolrConfigStore_POST implements SolrConfigStore
|
||||
{
|
||||
protected $url = '';
|
||||
|
||||
protected $remote = '';
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$options = Solr::solr_options();
|
||||
|
||||
$this->url = implode('', array(
|
||||
'http://',
|
||||
isset($config['auth']) ? $config['auth'].'@' : '',
|
||||
$options['host'].':'.(isset($config['port']) ? $config['port'] : $options['port']),
|
||||
$config['path']
|
||||
));
|
||||
|
||||
if (isset($config['remotepath'])) {
|
||||
$this->remote = $config['remotepath'];
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$this->uploadString($index, basename($file), file_get_contents($file));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
{
|
||||
$targetDir = "{$this->url}/config/$index";
|
||||
|
||||
file_get_contents($targetDir . '/' . $filename, false, stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/octet-stream',
|
||||
'content' => (string) $string
|
||||
]
|
||||
]));
|
||||
}
|
||||
|
||||
public function instanceDir($index)
|
||||
{
|
||||
return $this->remote ? "{$this->remote}/$index" : $index;
|
||||
}
|
||||
}
|
53
code/solr/configstore/SolrConfigStore_WebDAV.php
Normal file
53
code/solr/configstore/SolrConfigStore_WebDAV.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Class SolrConfigStore_WebDAV
|
||||
*
|
||||
* A ConfigStore that uploads files to a Solr instance via a WebDAV server
|
||||
*/
|
||||
class SolrConfigStore_WebDAV implements SolrConfigStore
|
||||
{
|
||||
public function __construct($config)
|
||||
{
|
||||
$options = Solr::solr_options();
|
||||
|
||||
$this->url = implode('', array(
|
||||
'http://',
|
||||
isset($config['auth']) ? $config['auth'].'@' : '',
|
||||
$options['host'].':'.(isset($config['port']) ? $config['port'] : $options['port']),
|
||||
$config['path']
|
||||
));
|
||||
$this->remote = $config['remotepath'];
|
||||
}
|
||||
|
||||
public function getTargetDir($index)
|
||||
{
|
||||
$indexdir = "{$this->url}/$index";
|
||||
if (!WebDAV::exists($indexdir)) {
|
||||
WebDAV::mkdir($indexdir);
|
||||
}
|
||||
|
||||
$targetDir = "{$this->url}/$index/conf";
|
||||
if (!WebDAV::exists($targetDir)) {
|
||||
WebDAV::mkdir($targetDir);
|
||||
}
|
||||
|
||||
return $targetDir;
|
||||
}
|
||||
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
WebDAV::upload_from_file($file, $targetDir.'/'.basename($file));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
WebDAV::upload_from_string($string, "$targetDir/$filename");
|
||||
}
|
||||
|
||||
public function instanceDir($index)
|
||||
{
|
||||
return $this->remote ? "{$this->remote}/$index" : $index;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user