abort_multipart_uploads_by_date ( $bucket, $when )

Aborts all multipart uploads initiated before the specified date. This operation cannot be reversed.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$when

string
integer

Optional

The time and date to use for comparison. Accepts any value that strtotime() understands.

Returns

Type

Description

CFArray

A CFArray containing a series of 0 or more CFResponse objects, containing a parsed HTTP response.

Examples

Abort all multipart uploads that were initiated before a given date.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Delete everything before right now.
$response = $s3->abort_multipart_uploads_by_date($bucket);

// Delete everything before 20 minutes ago
$response = $s3->abort_multipart_uploads_by_date($bucket, '20 minutes ago');

// Delete everything before yesterday
$response = $s3->abort_multipart_uploads_by_date($bucket, 'yesterday');

// Delete everything before a specific date.
$response = $s3->abort_multipart_uploads_by_date($bucket, '1 November 2010');

// Delete everything before a specific date.
$response = $s3->abort_multipart_uploads_by_date('my-bucket-doesnotexist', '1 November 2010');

// Success?
var_dump($response->areOK());
Result:
bool(true)

Related Methods

Source

Method defined in services/s3.class.php | Toggle source view (57 lines) | View on GitHub

public function abort_multipart_uploads_by_date($bucket, $when = null)
{
    if ($this->use_batch_flow)
    {
        // @codeCoverageIgnoreStart
        throw new S3_Exception(__FUNCTION__ . '() cannot be batch requested');
        // @codeCoverageIgnoreEnd
    }

    $when = $when ? $when : time();
    $handles = array();
    $data = $this->list_multipart_uploads($bucket)->body;
    $when = is_int($when) ? $when : strtotime($when);

    if (!($data instanceof CFSimpleXML))
    {
        return false;
    }

    $list = $data->query('descendant-or-self::Upload/Initiated');

    if (count($list) > 0)
    {
        foreach ($list as $node)
        {
            if (strtotime((string) $node) < $when)
            {
                $q = new CFBatchRequest();
                $parent = $node->parent();

                $upload_id = $parent
                    ->query('descendant-or-self::UploadId')
                    ->first()
                    ->to_string();

                $filename = $parent
                    ->query('descendant-or-self::Key')
                    ->first()
                    ->to_string();

                $handles[] = $this->abort_multipart_upload($bucket, $filename, $upload_id, array(
                    'returnCurlHandle' => true
                ));
            }
        }

        $http = new CFRequest();
        $responses = $http->send_multi_request($handles);

        if (is_array($responses) && count($responses) > 0)
        {
            return new CFArray($responses);
        }
    }

    return new CFArray();
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback