Watchdog messages saying Failed to create directory public://print_pdf/print_pdf_tcpdf/cache
This is caused by an error in file_prepare_directory (core) See https://drupal.org/node/2102905#comment-7925581

A workaround until core is fixed is to alter line 66 onwards of print_pdf.module:

    if (isset($info['public_dirs'])) {
      foreach ($info['public_dirs'] as $dir) {
        $directory = drupal_realpath('public://print_pdf/' . $tool[0] . '/' . $dir);
        $result = file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
        if (!$result) {
          watchdog('print_pdf', 'Failed to create directory "%dir" for %tool.', array('%dir' => $directory, '%tool' => $tool[0]), WATCHDOG_CRITICAL);
        }
      }
    }
  }
  if (variable_get('print_pdf_cache_enabled', PRINT_PDF_CACHE_ENABLED_DEFAULT)) {
    $directory = print_pdf_cache_dir();
    $result = file_prepare_directory(drupal_realpath($directory), FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
    if (!$result) {
      watchdog('print_pdf', 'Failed to create directory "%dir" for print_pdf cache.', array('%dir' => $directory), WATCHDOG_CRITICAL);
    }

Patch to follow

Comments

carlhinton’s picture

Status: Active » Needs review
StatusFileSize
new1.26 KB

And here is the patch

carlhinton’s picture

StatusFileSize
new1.24 KB

A better patch attached

carlhinton’s picture

StatusFileSize
new1.25 KB

An even better patch attached

alexandrezia’s picture

Hi, thanks for the patch.
I've made an adjustment because the patch was passing a function by reference and generating a strict warning:
Strict warning: Only variables should be passed by reference in print_pdf_init() (line 69 of /Library/WebServer/Documents/sites/all/modules/contrib/print/print_pdf/print_pdf.module).
Regards

alexandrezia’s picture

Issue summary: View changes
StatusFileSize
new1.36 KB

Hi, thanks for the patch.
I've made an adjustment because the patch was passing a function by reference and generating a strict warning:
Strict warning: Only variables should be passed by reference in print_pdf_init() (line 69 of /Library/WebServer/Documents/sites/all/modules/contrib/print/print_pdf/print_pdf.module).
Regards

alexandrezia’s picture

StatusFileSize
new1.36 KB

Oops, seems like my last patch is not applying, this should work.

alexandrezia’s picture

StatusFileSize
new1.57 KB

In fact, the path proposed here does not worked for me, it was failing with drush.

As stated by drupal documentation:
The use of drupal_realpath() is discouraged, because it does not work for remote URIs. Except in rare cases, URIs should not be manually resolved.

So I made a new patch that actually works even with drush, using stream wrapper function getDirectoryPath()

jkopel’s picture

The patch in #7 worked for me!
Finally creating the directory properly.
Thanks @alexandrezia!

jcnventura’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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