this patch allows advagg to store aggregate files using stream wrappers other than the default "public" wrapper. i developed this in order to use with the amazon s3 file stream wrapper provided by the amazons3 module, and it should work with any properly implemented stream wrapper.

The patch creates a text field in the admin page where you can set the stream wrapper, and then uses the stream wrapper when writing drupal file records. It defines "public" as the default stream wrapper, and will always use "public" unless a different value is set in the admin form.

I also found that drupal's record of MIME types in file_managed were getting lost in certain contexts when temporary files were used, so i made it write temporary files with the same file extension as the original file name, which allows drupal to preserve the MIME type all the way through the process.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aviindub’s picture

Issue summary: View changes
aviindub’s picture

Issue summary: View changes
mikeytown2’s picture

Status: Active » Needs review
aviindub’s picture

Status: Needs review » Needs work

im seeing some issues after running this patch with the advagg 2.3, so I'm going to work on this a little more and resubmit.

mikeytown2’s picture

Usage of hook_advagg_get_root_files_dir_alter($css_paths, $js_paths) is the preferred way to change the css and js paths. I want to keep the admin section as clean as possible so if the alter hook is a no go, creating a "hidden" setting would be ideal. Document the hidden setting in the readme as well.

aviindub’s picture

thanks, i will make that change and see if i can make it work.

mikeytown2’s picture

Also noted is hook_advagg_save_aggregate_alter($files_to_save, $aggregate_settings, $other_parameters). This will allow you to modify the full path before saving or even saving the file in 2 locations. I use this hook for saving .gz files and using packer js compression on non gzip files.

http://drupalcode.org/project/advagg.git/blob/refs/heads/7.x-2.x:/advagg...

aviindub’s picture

Status: Needs work » Needs review
FileSize
824 bytes

Thanks to your input, i was able to implement the functionality i need via hook_advagg_save_aggregate_alter and hook_advagg_get_root_files_dir_alter. There is only one remaining component that i need to submit a patch for, which is to add the file extension to the temporary file name when saving aggregates in order to preserve the MIME type in the alternate stream wrapper. Patch is attached.

aviindub’s picture

in case you are curious, here's what my implementation looks like:

/**
 * implements hook_advagg_save_aggregate_alter()
 */
function mymodule_advagg_save_aggregate_alter($files_to_save, $aggregate_settings, $other_parameters) {
  foreach ($files_to_save as $name => $file) {
    if (StringUtil::StartsWith($name, 'public')) {
      $new_name = preg_replace('/^public/', 's3', $name);
      ArrayUtil::ChangeKeyName($files_to_save, $name, $new_name);
    }
  }
}

/**
 * implements hook_advagg_get_root_files_dir_alter()
 */
function mymodule_advagg_get_root_files_dir_alter(&$css_paths, &$js_paths) {
  if ($css_paths[0] != 'public://advagg_css' || $js_paths[0] != 'public://advagg_js') {
    throw new Exception("unexpected value in the advagg css_paths or js_paths.");
  }
  $css_paths[0] = 's3://advagg_css';
  $js_paths[0] = 's3://advagg_js';
}
mikeytown2’s picture

Status: Needs review » Fixed

Nice work :)
Patch in #8 has been committed.

aviindub’s picture

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.