diff --git a/src/Solr/Solr.php b/src/Solr/Solr.php index 3fd977e..905eb78 100644 --- a/src/Solr/Solr.php +++ b/src/Solr/Solr.php @@ -34,13 +34,19 @@ 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) + * 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. * remotepath (default: the same as indexpath) - The path that the Solr server will read the index configurations from * - * When mode == SolrConfigStore_WebDAV or webdav (indexes should stored on a remote Solr server via webdav) + * 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 + * + * When mode == SolrConfigStore_WebDAV or 'webdav' (indexes should stored on a remote Solr server via webdav) * auth (default: none) - A username:password pair string to use to auth against the webdav server * 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 diff --git a/src/Solr/Stores/SolrConfigStore_Post.php b/src/Solr/Stores/SolrConfigStore_Post.php new file mode 100644 index 0000000..7d40f68 --- /dev/null +++ b/src/Solr/Stores/SolrConfigStore_Post.php @@ -0,0 +1,74 @@ +url = implode('', [ + 'http://', + isset($config['auth']) ? $config['auth'] . '@' : '', + $options['host'] . ':' . $options['port'], + $config['path'] + ]); + $this->remote = $config['remotepath']; + } + + /** + * @param string $index + * @param string $file + * @return void + */ + public function uploadFile($index, $file) + { + $this->uploadString($index, basename($file), file_get_contents($file)); + } + + /** + * + * @param string $index + * @param string $filename + * @param string $string + * @return void + */ + 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 + ] + ])); + } + + /** + * @param string $index + * @return string + */ + public function instanceDir($index) + { + return $this->remote ? "{$this->remote}/$index" : $index; + } +} diff --git a/src/Solr/Tasks/Solr_Configure.php b/src/Solr/Tasks/Solr_Configure.php index 22bdb5c..05e1634 100644 --- a/src/Solr/Tasks/Solr_Configure.php +++ b/src/Solr/Tasks/Solr_Configure.php @@ -5,9 +5,10 @@ use Exception; use SilverStripe\Core\ClassInfo; use SilverStripe\FullTextSearch\Solr\Solr; use SilverStripe\FullTextSearch\Solr\SolrIndex; -use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_File; -use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_WebDAV; use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore; +use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_File; +use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_Post; +use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_WebDAV; class Solr_Configure extends Solr_BuildTask { @@ -93,6 +94,9 @@ class Solr_Configure extends Solr_BuildTask if ($mode === 'webdav') { return new SolrConfigStore_WebDAV($indexstore); } + if ($mode == 'post') { + return new SolrConfigStore_Post($indexstore); + } if (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, SolrConfigStore::class)) { return new $mode($indexstore); }