public function test_rename_via_stream_wrapper_fails_on_invalid_permission()
 {
     copy(dirname(__FILE__) . '/data/canola.jpg', 's3://' . S3_UPLOADS_BUCKET . '/canola.jpg');
     stream_wrapper_unregister('s3');
     $uploads = new S3_Uploads(S3_UPLOADS_BUCKET, S3_UPLOADS_KEY, '123', null, S3_UPLOADS_REGION);
     $uploads->register_stream_wrapper();
     $bucket_root = strtok(S3_UPLOADS_BUCKET, '/');
     $result = @rename('s3://' . S3_UPLOADS_BUCKET . '/canola.jpg', 's3://' . $bucket_root . '/canola.jpg');
     $this->assertFalse($result);
 }
 /**
  * As s3 doesn't have directories, we expect that mkdir does not cause any s3
  * connectivity.
  */
 public function test_file_exists_on_dir_does_not_cause_network_activity()
 {
     stream_wrapper_unregister('s3');
     $uploads = new S3_Uploads(S3_UPLOADS_BUCKET, S3_UPLOADS_KEY, '123');
     $uploads->register_stream_wrapper();
     $bucket_root = strtok(S3_UPLOADS_BUCKET, '/');
     // result would fail as we don't have permission to write here.
     $result = file_exists('s3://' . $bucket_root . '/some_dir');
     $this->assertTrue($result);
     $result = is_dir('s3://' . $bucket_root . '/some_dir');
     $this->assertTrue($result);
 }
 /**
  *
  * @return S3_Uploads
  */
 public static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new S3_Uploads(S3_UPLOADS_BUCKET, defined('S3_UPLOADS_KEY') ? S3_UPLOADS_KEY : null, defined('S3_UPLOADS_SECRET') ? S3_UPLOADS_SECRET : null, defined('S3_UPLOADS_BUCKET_URL') ? S3_UPLOADS_BUCKET_URL : null, S3_UPLOADS_REGION);
     }
     return self::$instance;
 }
 /**
  *
  * @return S3_Uploads
  */
 public static function get_instance()
 {
     if (!self::$instance) {
         $key = defined('S3_UPLOADS_KEY') ? S3_UPLOADS_KEY : null;
         $secret = defined('S3_UPLOADS_SECRET') ? S3_UPLOADS_SECRET : null;
         $url = defined('S3_UPLOADS_BUCKET_URL') ? S3_UPLOADS_BUCKET_URL : null;
         $region = defined('S3_UPLOADS_REGION') ? S3_UPLOADS_REGION : null;
         self::$instance = new S3_Uploads(S3_UPLOADS_BUCKET, $key, $secret, $url, $region);
     }
     return self::$instance;
 }
function s3_uploads_init()
{
    if (!defined('S3_UPLOADS_BUCKET') || !defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) {
        return;
    }
    $instance = S3_Uploads::get_instance();
    $instance->register_stream_wrapper();
    add_filter('upload_dir', array($instance, 'filter_upload_dir'));
    add_filter('wp_image_editors', array($instance, 'filter_editors'), 9);
    remove_filter('admin_notices', 'wpthumb_errors');
    add_action('wp_handle_sideload_prefilter', array($instance, 'filter_sideload_move_temp_file_to_s3'));
}
Beispiel #6
0
function s3_uploads_init()
{
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}
Beispiel #7
0
function s3_uploads_init()
{
    if (!s3_uploads_check_requirements()) {
        return;
    }
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    if (!defined('S3_UPLOADS_REGION')) {
        wp_die('S3_UPLOADS_REGION constant is required. Please define it in your wp-config.php');
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}
 /**
  * Delete files from S3
  *
  * @synopsis <path> [--regex=<regex>]
  */
 public function rm($args, $args_assoc)
 {
     $s3 = S3_Uploads::get_instance()->s3();
     $prefix = '';
     $regex = isset($args_assoc['regex']) ? $args_assoc['regex'] : '';
     if (strpos(S3_UPLOADS_BUCKET, '/')) {
         $prefix = trailingslashit(str_replace(strtok(S3_UPLOADS_BUCKET, '/') . '/', '', S3_UPLOADS_BUCKET));
     }
     if (isset($args[0])) {
         $prefix .= ltrim($args[0], '/');
         if (strpos($args[0], '.') === false) {
             $prefix = trailingslashit($prefix);
         }
     }
     try {
         $objects = $s3->deleteMatchingObjects(strtok(S3_UPLOADS_BUCKET, '/'), $prefix, $regex, array('before_delete', function () {
             WP_CLI::line(sprintf('Deleting file'));
         }));
     } catch (Exception $e) {
         WP_CLI::error($e->getMessage());
     }
     WP_CLI::success(sprintf('Successfully deleted %s', $prefix));
 }
 /**
  * Gets the path that the wrapper is responsible for.
  *
  * @return string
  *   String specifying the path.
  */
 static function getDirectoryPath()
 {
     $upload_dir = S3_Uploads::get_instance()->get_original_upload_dir();
     return $upload_dir['basedir'] . '/s3';
 }
Beispiel #10
0
 function test_get_s3_bucket()
 {
     $uploads = new S3_Uploads('hmn-uploads/something', S3_UPLOADS_KEY, S3_UPLOADS_SECRET, null, S3_UPLOADS_REGION);
     $this->assertEquals('hmn-uploads', $uploads->get_s3_bucket());
 }
Beispiel #11
0
 public function test_get_s3_client()
 {
     $s3 = S3_Uploads::get_instance()->s3();
     $this->assertInstanceOf('Aws\\S3\\S3Client', $s3);
 }