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
Comment #1
carlhinton commentedAnd here is the patch
Comment #2
carlhinton commentedA better patch attached
Comment #3
carlhinton commentedAn even better patch attached
Comment #4
alexandrezia commentedHi, 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
Comment #5
alexandrezia commentedHi, 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
Comment #6
alexandrezia commentedOops, seems like my last patch is not applying, this should work.
Comment #7
alexandrezia commentedIn 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()
Comment #8
jkopel commentedThe patch in #7 worked for me!
Finally creating the directory properly.
Thanks @alexandrezia!
Comment #9
jcnventuraThanks for the patches!
http://drupalcode.org/project/print.git/commit/44a5a5e