Move storage backend tests from constructor to test function

This commit is contained in:
Michael Gapczynski 2012-12-28 12:00:48 -05:00
parent d9ff3b6860
commit ad902a9848
9 changed files with 26 additions and 26 deletions

View File

@ -36,10 +36,6 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
if (isset($params['key']) && isset($params['secret']) && isset($params['bucket'])) {
$this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret']));
$this->bucket = $params['bucket'];
$test = $this->s3->get_canonical_user_id();
if (!isset($test['id']) || $test['id'] == '') {
throw new Exception();
}
} else {
throw new Exception();
}
@ -250,4 +246,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
return $response->isOK();
}
public function test() {
$test = $this->s3->get_canonical_user_id();
if (isset($test['id']) && $test['id'] != '') {
return true;
}
return false;
}
}

View File

@ -192,8 +192,8 @@ class OC_Mount_Config {
}
if (class_exists($class)) {
try {
new $class($options);
return true;
$storage = new $class($options);
return $storage->test();
} catch (Exception $exception) {
return false;
}

View File

@ -41,10 +41,6 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
$oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
$oauth->setToken($params['token'], $params['token_secret']);
$this->dropbox = new Dropbox_API($oauth, 'dropbox');
$test = $this->stat('');
if (!$test) {
throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
}
} else {
throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
}

View File

@ -33,10 +33,6 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
if ( ! $this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
$test = $this->stat('');
if (!$test) {
throw new Exception();
}
//create the root folder if necesary
if ( ! $this->is_dir('')) {
$this->mkdir('');

View File

@ -42,10 +42,6 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$this->oauth_token = new OAuthToken($params['token'], $params['token_secret']);
$this->sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->entries = array();
$test = $this->free_space('');
if (!$test) {
throw new Exception();
}
} else {
throw new Exception('Creating OC_Filestorage_Google storage failed');
}
@ -594,4 +590,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
public function test() {
if ($this->free_space('')) {
return true;
}
return false;
}
}

View File

@ -34,10 +34,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
if (substr($this->share, -1, 1)=='/') {
$this->share=substr($this->share, 0, -1);
}
$test = $this->stat('');
if (!$test) {
throw new Exception();
}
//create the root folder if necesary
if ( ! $this->is_dir('')) {
$this->mkdir('');

View File

@ -60,10 +60,6 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->client->addTrustedCertificates($certPath);
}
}
$test = $this->stat('');
if (!$test) {
throw new Exception();
}
//create the root folder if necesary
$this->mkdir('');
} else {

View File

@ -64,4 +64,5 @@ abstract class OC_Filestorage{
*/
abstract public function hasUpdated($path, $time);
abstract public function getOwner($path);
abstract public function test();
}

View File

@ -288,4 +288,12 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
public function getOwner($path) {
return OC_User::getUser();
}
public function test() {
if ($this->stat('')) {
return true;
}
return false;
}
}