You are here

function Resource::copy in D7 Media 6

Create a copy a Resource.

Parameters

string $destination (optional) @see file_copy.:

int $replace (optional) @see file_destination:

Return value

object|bool drupal_file if the copy is successful, or FALSE

File

resource/resource.module, line 192
Resource API for Drupal, a replacement for files.

Class

Resource
Base Resource class.

Code

function copy($destination, $replace = FILE_EXISTS_RENAME) {
  $destination = $this
    ->_destination($destination, $replace);
  if (copy($this->url, $destination)) {
    $copy = clone $this;
    $copy->rid = NULL;
    $copy->url = $destination;
    if ($copy
      ->save()) {
      module_invoke_all('resource_copy', $this, $copy);
      return ResourceFactory::loadId($copy->rid);
    }
  }
  return FALSE;
}