You are here

public function AmazonS3StreamWrapper::rename in AmazonS3 7

Support for rename().

If $to_uri exists, this file will be overwritten. This behavior is identical to the PHP rename() function.

Parameters

string $from_uri: The uri to the file to rename.

string $to_uri: The new uri for file.

Return value

bool TRUE if file was successfully renamed.

Overrides StreamWrapperInterface::rename

See also

http://php.net/manual/en/streamwrapper.rename.php

File

./AmazonS3StreamWrapper.inc, line 721
Drupal stream wrapper implementation for Amazon S3

Class

AmazonS3StreamWrapper
@file Drupal stream wrapper implementation for Amazon S3

Code

public function rename($from_uri, $to_uri) {
  $this
    ->assertConstructorCalled();
  $from = $this
    ->getLocalPath($from_uri);
  $to = $this
    ->getLocalPath($to_uri);
  try {
    $s3 = $this
      ->getS3();
    $response = $s3
      ->copy_object(array(
      'bucket' => $this->bucket,
      'filename' => $from,
    ), array(
      'bucket' => $this->bucket,
      'filename' => $to,
    ), array(
      'acl' => AmazonS3::ACL_PUBLIC,
    ));

    // Check the response and then remove the original.
    return $response
      ->isOK() && $this
      ->unlink($from_uri);
  } catch (Exception $e) {
    watchdog('amazons3', 'Unable to copy file from @from to @to', array(
      '@from' => $from,
      '@to' => $to,
    ), WATCHDOG_NOTICE);
  }
  return FALSE;
}