You are here

function s3fs_copy_system_images_save_batch in S3 File System 7.3

Same name and namespace in other branches
  1. 7.2 s3fs.module \s3fs_copy_system_images_save_batch()

Save system images to S3.

Parameters

string $wrapper: Default file system stream wrapper.

array $directory: A directory of a module, theme, or library where system images are to be saved.

1 string reference to 's3fs_copy_system_images_save_batch'
s3fs_copy_system_images_batch_set in ./s3fs.module
Set batch process to perform copy of system images.

File

./s3fs.module, line 1122
Hook implementations and other primary functionality for S3 File System.

Code

function s3fs_copy_system_images_save_batch($wrapper, $directory) {

  // Scan for images in the relevant directories.
  $local_files = file_scan_directory($directory, '/^.*\\.(png|gif|jpe?g|svg|bmp)$/');

  // Loop through each local file. "local_file_uri" is path + filename (ex: 'misc/farbtastic/marker.png')
  foreach ($local_files as $local_file_uri => $local_file) {

    // Determine file path for each selected file.
    $remote_file_path = str_replace('/' . $local_file->filename, '', $local_file_uri);

    // Use file path to make directories. Only create if it doesn't exist.
    if (!is_dir($wrapper . $remote_file_path)) {
      drupal_mkdir($wrapper . $remote_file_path, NULL, TRUE, NULL);
    }

    // Copy file from the original file path to its location in the stream wrapper.
    file_unmanaged_copy($local_file_uri, $wrapper . $local_file_uri, FILE_EXISTS_REPLACE);
  }
}