silverstripe-fulltextsearch/code/utils/WebDAV.php
Elliot Sawyer 1728a62af5 WIP: Silverstripe 4 compatibility
Thanks to Marco Hermo and Brett Tasker for helping with this
* Bump framework/cms to ^4.0@dev
* WIP Silverstripe 4 compatibility fixes
* more replacements and patches to migrate this module to 4.0
* Update composer.json
* remove php <5.5 from travis.yml
* WIP more SS4 compatibility fixes
* WIP fix solr path to use DIR, avoid hardcoded module name
* WIP respect current include path
* WIP Namespacing and use on SearchIndex class
* Namespacing for tests
* WIP add namespaces to all classes
* Second push of Test changes + namespacing
* WIP split Solr files with multiple classes into single file / single class. Adjust namespaces
* Fix PHP errors in test
* break out search components with multiple classes into individual files and change namespaces
* Update namespacing for Search indexes and variants in tests
* Batch fixes for tests #2
* Update _config.php to use namespace
* Use root namespace in referencing Apache_Solr_Document
* Migrate task names so that the name is not fully qualified
2017-04-25 20:46:35 +12:00

77 lines
1.8 KiB
PHP

<?php
namespace SilverStripe\FullTextSearch\Utils;
class WebDAV
{
public static function curl_init($url, $method)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
return $ch;
}
public static function exists($url)
{
// WebDAV expects that checking a directory exists has a trailing slash
if (substr($url, -1) != '/') {
$url .= '/';
}
$ch = self::curl_init($url, 'PROPFIND');
$res = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code == 404) {
return false;
}
if ($code == 200 || $code == 207) {
return true;
}
user_error("Got error from webdav server - ".$code, E_USER_ERROR);
}
public static function mkdir($url)
{
$ch = self::curl_init(rtrim($url, '/').'/', 'MKCOL');
$res = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $code == 201;
}
public static function put($handle, $url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_INFILE, $handle);
$res = curl_exec($ch);
fclose($handle);
return curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
public static function upload_from_string($string, $url)
{
$fh = tmpfile();
fwrite($fh, $string);
fseek($fh, 0);
return self::put($fh, $url);
}
public static function upload_from_file($string, $url)
{
return self::put(fopen($string, 'rb'), $url);
}
}