Enables versioning support for the specified Amazon S3 bucket.
Access
Parameters
Parameter |
Type |
Required |
Description |
$bucket
|
string
|
Required
|
The name of the bucket to use. |
$opt
|
array
|
Optional
|
An associative array of parameters that can have the following keys:
MFASerial - string (Optional) The serial number on the back of the Gemalto device. MFASerial , MFAToken and MFAStatus must all be set for MFA to work.MFAToken - string (Optional) The current token displayed on the Gemalto device. MFASerial , MFAToken and MFAStatus must all be set for MFA to work.MFAStatus - string (Optional) The MFA Delete status. Can be Enabled or Disabled . MFASerial , MFAToken and MFAStatus must all be set for MFA to work.curlopts - array - Optional - A set of values to pass directly into curl_setopt() , where the key is a pre-defined CURLOPT_* constant.returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests. |
Returns
Examples
Enable versioning on a bucket.
// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
$response = $s3->enable_versioning($bucket);
sleep(1);
$status = $s3->get_versioning_status($bucket);
// Success?
var_dump($response->isOK());
var_dump((string) $status->body->Status);
Result:
bool(true)
string(7) "Enabled"
Enable versioning and Multi-Factor Authentication on a bucket.
// Instantiate the class
$s3 = new AmazonS3();
$response = $s3->enable_versioning('my-bucket', array(
'MFASerial' => CFCredentials::get()->mfa_serial, // Custom property in the config file.
'MFAToken' => '12345678',
'MFAStatus' => 'Enabled'
));
// Success?
var_dump($response->isOK());
Result:
bool(true)
See Also
Source
Method defined in services/s3.class.php | Toggle source view (28 lines) | View on GitHub
public function enable_versioning($bucket, $opt = null)
{
if (!$opt) $opt = array();
// Add this to our request
$opt['verb'] = 'PUT';
$opt['sub_resource'] = 'versioning';
$opt['headers'] = array(
'Content-Type' => 'application/xml'
);
$xml = simplexml_load_string($this->base_versioning_xml);
$xml->addChild('Status', 'Enabled');
// Enable MFA delete?
// @codeCoverageIgnoreStart
if (isset($opt['MFASerial']) && isset($opt['MFAToken']) && isset($opt['MFAStatus']))
{
$xml->addChild('MfaDelete', $opt['MFAStatus']);
$opt['headers']['x-amz-mfa'] = ($opt['MFASerial'] . ' ' . $opt['MFAToken']);
}
// @codeCoverageIgnoreEnd
$opt['body'] = $xml->asXML();
// Authenticate to S3
return $this->authenticate($bucket, $opt);
}