/**
  * Tests mirror
  *
  * @param string  $error
  * @return bool
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $results = array();
     $files = array(array('local_path' => '', 'remote_path' => 'purge_test_' . time()));
     if (!$this->purge($files, $results) && isset($results[0]['error'])) {
         $error = $results[0]['error'];
         return false;
     }
     return true;
 }
 /**
  * Tests S3
  *
  * @param string  $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_azure_' . md5(time());
     if (!$this->_init($error)) {
         return false;
     }
     try {
         $containers = $this->_client->listContainers();
     } catch (\Exception $exception) {
         $error = sprintf('Unable to list containers (%s).', $exception->getMessage());
         return false;
     }
     $container = null;
     foreach ((array) $containers as $_container) {
         if ($_container->Name == $this->_config['container']) {
             $container = $_container;
             break;
         }
     }
     if (!$container) {
         $error = sprintf('Container doesn\'t exist: %s.', $this->_config['container']);
         return false;
     }
     try {
         $this->_client->putBlobData($this->_config['container'], $string, $string);
     } catch (\Exception $exception) {
         $error = sprintf('Unable to put blob data (%s).', $exception->getMessage());
         return false;
     }
     try {
         $data = $this->_client->getBlobData($this->_config['container'], $string);
     } catch (\Exception $exception) {
         $error = sprintf('Unable to get blob data (%s).', $exception->getMessage());
         return false;
     }
     if ($data != $string) {
         try {
             $this->_client->deleteBlob($this->_config['container'], $string);
         } catch (\Exception $exception) {
         }
         $error = 'Blob datas are not equal.';
         return false;
     }
     try {
         $this->_client->deleteBlob($this->_config['container'], $string);
     } catch (\Exception $exception) {
         $error = sprintf('Unable to delete blob (%s).', $exception->getMessage());
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * Tests S3
  *
  * @param string  $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_s3_' . md5(time());
     if (!$this->_init($error)) {
         return false;
     }
     $this->_set_error_handler();
     $buckets = @$this->_s3->listBuckets();
     if ($buckets === false) {
         $error = sprintf('Unable to list buckets (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if (!in_array($this->_config['bucket'], (array) $buckets)) {
         $error = sprintf('Bucket doesn\'t exist: %s.', $this->_config['bucket']);
         $this->_restore_error_handler();
         return false;
     }
     if (!@$this->_s3->putObjectString($string, $this->_config['bucket'], $string, \S3::ACL_PUBLIC_READ)) {
         $error = sprintf('Unable to put object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if (!($object = @$this->_s3->getObject($this->_config['bucket'], $string))) {
         $error = sprintf('Unable to get object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if ($object->body != $string) {
         $error = 'Objects are not equal.';
         @$this->_s3->deleteObject($this->_config['bucket'], $string);
         $this->_restore_error_handler();
         return false;
     }
     if (!@$this->_s3->deleteObject($this->_config['bucket'], $string)) {
         $error = sprintf('Unable to delete object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     $this->_restore_error_handler();
     return true;
 }
Example #4
0
 /**
  * Tests FTP server
  *
  * @param string  $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $rand = md5(time());
     $tmp_dir = 'test_dir_' . $rand;
     $tmp_file = 'test_file_' . $rand;
     $tmp_path = W3TC_CACHE_TMP_DIR . '/' . $tmp_file;
     if (!@file_put_contents($tmp_path, $rand)) {
         $error = sprintf('Unable to create file: %s.', $tmp_path);
         return false;
     }
     if (!$this->_connect($error)) {
         return false;
     }
     $this->_set_error_handler();
     if (!@ftp_mkdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (file_exists($this->_config['docroot'] . '/' . $tmp_dir)) {
         $error = sprintf('Test directory was made in your site root, not on separate FTP host or path. Change path or FTP information: %s.', $tmp_dir);
         @unlink($tmp_path);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_chdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to change directory to: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
         $error = sprintf('Unable to upload file: %s (%s).', $tmp_path, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @unlink($tmp_path);
     if (!@ftp_delete($this->_ftp, $tmp_file)) {
         $error = sprintf('Unable to delete file: %s (%s).', $tmp_path, $this->_get_last_error());
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @ftp_cdup($this->_ftp);
     if (!@ftp_rmdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     $this->_restore_error_handler();
     $this->_disconnect();
     return true;
 }
 /**
  * Tests S3
  *
  * @param string  $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_s3_' . md5(time());
     $this->_set_error_handler();
     if (!@$this->_s3->putObjectString($string, $this->_config['bucket'], $string, \S3::ACL_PUBLIC_READ)) {
         $error = sprintf('Unable to put object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     $object = @$this->_s3->getObject($this->_config['bucket'], $string);
     if (!$object) {
         $error = sprintf('Unable to get object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if ($object->body != $string) {
         $error = 'Objects are not equal.';
         @$this->_s3->deleteObject($this->_config['bucket'], $string);
         $this->_restore_error_handler();
         return false;
     }
     if (!@$this->_s3->deleteObject($this->_config['bucket'], $string)) {
         $error = sprintf('Unable to delete object (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     $this->_restore_error_handler();
     return true;
 }