I am using the S3 File System module https://www.drupal.org/project/s3fs

When I upload a PDF Template file on the PDF Templates setting or on the PDF Fields Settings, I can see the file is uploaded to a views_pdf_templates folder on the S3 bucket, but I cannot see the template in the drop downs (all I can select is 'None')

I realise that very few people will be using these two modules together so I'm looking for a work around rather than a fix. Is there any way to work around this or force the list to be populated?

CommentFileSizeAuthor
#9 compatible_with_S3-2933485-9.patch1.16 KBshadab ahmad

Comments

Matt B created an issue. See original summary.

matt b’s picture

I notice this module uses a variable 'views_pdf_template_stream' so I'm trying variations of
drush vset views_pdf_template_stream s3://public/views_pdf_templates

No success so far....!

matt b’s picture

Title: Cannot view template files when using S3 File System » Make compatible with S3 File System

so in the end I've just hacked the getAvailableTemplates and getTemplatePath functions in views_pdf_template.pdf - it's dirty and not nice, so my request is - can this module be made compatible with the S3FS module please.

vegansupreme’s picture

Since you've got a working solution, can you submit a patch as a start?

matt b’s picture

No, my hack is to insert the template manually into the templates list produced by getAvailableTemplates and to add an if statement to getTemplatePath to return the path. I've had to load the template to the web server (not S3) and use the full path. It's a real dirty have that has enabled me to see if the modules functionality meets my use case, but it's specific to my needs, and not really for production use!

shadab ahmad’s picture

Status: Active » Needs review

I am facing the same problem and looking for any possible solution so that we can configure S3 file path with views_pdf.

shadab ahmad’s picture

I have fixed this issue. Please follow the steps below:
1. Go to views_pdf/views_pdf_template.php
2. Replace function getTemplatePath() with the function below:

public static function getTemplatePath($template, $row = NULL, $view = NULL) {
    if (empty($template)) {
      return '';
    }
    if ($row != NULL && $view != NULL && !preg_match('/\.pdf/', $template)) {
      return drupal_realpath($row->field_data_field_file_node_values[0]['uri']);
    }
    $template_dir = variable_get('views_pdf_template_stream', 'public://views_pdf_templates');
    if(module_exists('s3fs')){
      $file_url = file_create_url($template_dir . '/' . $template);
      $pdf_data = file_get_contents($file_url);
      $filepath = str_replace('public', 'temporary',  $template_dir);   
      file_prepare_directory($filepath, FILE_CREATE_DIRECTORY || FILE_MODIFY_PERMISSIONS);
      $pdf_path = drupal_realpath($filepath).'/'.$template;	
      if(!file_exists($pdf_path)){
        file_put_contents($pdf_path, $pdf_data);
      }
      return $pdf_path;
    }
    else{
      return drupal_realpath($template_dir . '/' . $template);
    }
  }
matt b’s picture

Status: Needs review » Needs work

Please provide a patch

shadab ahmad’s picture

Status: Needs work » Needs review
StatusFileSize
new1.16 KB

I have created patch for the same. I have tested on my localhost and it works. Please review and apply the same.

shadab ahmad’s picture

Any news on this patch being pushed? Thanks.

papagrande’s picture

Status: Needs review » Needs work
+++ b/views_pdf_template.php
@@ -1020,13 +1020,24 @@ class PdfTemplate extends FPDI {
+    if(module_exists('s3fs')){

I haven't tested the patch, but at first glance, the changes need to be run through the PHP code sniffer to match Drupal coding standards.

matt b’s picture

I've tested the patch. The template files in the S3 bucket are not being listed, and now my public folder has some wierd permission issue where I cannot view it in IMCE, but I still can in S3.

killua99’s picture

is this feature still relevant ? if yes, could you re-write this patch for Drupal 7.x-3-x ?

If not, I will close it

matt b’s picture

I think it can be closed :-). I can't even remember why I needed this (it was clearly important at the time!)

matt b’s picture

Status: Needs work » Closed (outdated)