public function StreamWrapper::rename in AmazonS3 7.2
Override rename() to handle setting the URI on move.
File
- src/
StreamWrapper.php, line 559 - Drupal stream wrapper implementation for Amazon S3
Class
- StreamWrapper
- @file Drupal stream wrapper implementation for Amazon S3
Namespace
Drupal\amazons3Code
public function rename($path_from, $path_to) {
$this
->setUri($path_from);
$partsFrom = $this
->getParams($path_from);
$this
->setUri($path_to);
$partsTo = $this
->getParams($path_to);
// We ignore testing this block since it is copied directly from the parent
// method which is covered by the AWS SDK tests.
// @codeCoverageIgnoreStart
$this
->clearStatInfo($path_from);
$this
->clearStatInfo($path_to);
if (!$partsFrom['Key'] || !$partsTo['Key']) {
return $this
->triggerError('The Amazon S3 stream wrapper only supports copying objects');
}
try {
// Copy the object and allow overriding default parameters if desired, but by default copy metadata
static::$client
->copyObject($this
->getOptions() + array(
'Bucket' => $partsTo['Bucket'],
'Key' => $partsTo['Key'],
'CopySource' => '/' . $partsFrom['Bucket'] . '/' . rawurlencode($partsFrom['Key']),
'MetadataDirective' => 'COPY',
));
// Delete the original object
static::$client
->deleteObject(array(
'Bucket' => $partsFrom['Bucket'],
'Key' => $partsFrom['Key'],
) + $this
->getOptions());
} catch (\Exception $e) {
return $this
->triggerError($e
->getMessage());
}
// @codeCoverageIgnoreEnd
return true;
}