Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just rolled this module out on a live site and it seems that somehow (on cron?) The PDF templates that we upload through the views interface (that get placed at sites/default/files/views_pdf) disappear/are deleted after some undetermined amount of time (may be related to cron). Have looked through the code and can't figure out where/how the views_pdf directory that holds the templates is created, and am wondering if this is getting reset somehow?
Comment | File | Size | Author |
---|---|---|---|
#23 | [views_pdf]-[fix_missing_template]-[1230098]-[23].patch | 565 bytes | FatherShawn |
#14 | file_status_perm-1230098-14.patch | 1.13 KB | FatherShawn |
Comments
Comment #1
hunziker CreditAttribution: hunziker commentedThis is really interesting, because we do not implement the hook_cron() in the Views PDF module. Additionally we have no delete method implemented for the template files, this means we have no UI / API implemented to delete any files.
Can you tell me a way how I can reproduce this? Is it possible that you can tell me what other modules you have activated in the environment?
Comment #2
FatherShawn@Kyle Jaster: Any light shed on this via complaints in the logs for protecting the directory via permissions?
Comment #3
kylejaster CreditAttribution: kylejaster commented@FatherShawn - unfortunately nothing listed in logs...
Comment #4
kylejaster CreditAttribution: kylejaster commentedOk - we've noticed that this appears to be happening when the view is part of a feature and the feature's views get reverted. Everytime a feature with a views_pdf view is reverted the sites/mysite/files/views_pdf_templates directory gets emptied.
Comment #5
hunziker CreditAttribution: hunziker commentedThis is really interesting. Is this a misbehavior or not? Should we fix something here or is it convenient?
Comment #6
Griso81 CreditAttribution: Griso81 commentedSubscribe, I have the same problem. After a PDF is generate via a triggered Rule the template gets deleted from the templates directory.
Comment #7
Bouke CreditAttribution: Bouke commentedSubscribe
Comment #8
hunziker CreditAttribution: hunziker commentedI can't reproduce this bug. Is it possible that someone can give more information about how this happened?
@Griso81: Is it really the "views_pdf_rules_action_save" action? Because there I don't invoke any delete method.
Comment #9
kylejaster CreditAttribution: kylejaster commented@hunziker - this is definitely amisbehavior, not convenient.
it looks like anytime a cache is cleared, or features are reverted etc.. the directory gets re-created - no idea how, but after looking through the code in views_pdf i'm not seeing how the directory is created in the first place? i imagine all that is needed would be a check to see if the directory already exists...
Comment #10
splash112 CreditAttribution: splash112 commentedSame problem here, don't think it is because of the triggered Rule.
Cache clearing could be a problem, but not sure how.
But is this the right place anyway to store a file? Think using the file system in Drupal with the files stored in the /files/ directory (or subdirectory) would be much better?
Thanks
Mark
Comment #11
Griso81 CreditAttribution: Griso81 commentedHi and sorry for delay but holidays couldn't wait :)
I've been trying to reproduce the problem, but did not manage. The only hint I have is that the problem occurred while I was having php timeout problems for other reasons, but I'm not sure this is related...
Comment #12
velpan CreditAttribution: velpan commentedsame problem.
I found a solution by changing the permission rights of "views_pdf_templates" folder, after the uploading of a template.
Comment #13
kylejaster CreditAttribution: kylejaster commentedany chance we can get this in the next release?
Comment #14
FatherShawnIt looks to me like #12 fixes the symptom, not the problem. Both of these code blocks properly use file_save_upload() to upload the file. But, as http://api.drupal.org/api/drupal/includes--file.inc/function/file_save_u... notes
A search on this modules code base does not find a call to file_set_status() anywhere, so whenever Drupal does garbage collection, this template file is purged from the files table and deleted from the file system. The attached patch adds this call below both lines referenced in #12.
Comment #15
kylejaster CreditAttribution: kylejaster commentedNicely done FatherShawn!
We've tested this and it appears to be working.
Comment #16
flipolopo CreditAttribution: flipolopo commentedDrupal 6:
file_set_status(&$file, FILE_STATUS_PERMANENT);
Drupal 7:
$file->status |= FILE_STATUS_PERMANENT;
Comment #17
FatherShawn@flipolopo True, the file is an object in d7 and so the property is set as you stated. A file_save() would also be required as noted http://api.drupal.org/api/drupal/includes--file.inc/function/file_save/7
Note however that this issue does relate to the 6x-1.0 branch. Setting this to RTBC per @Kyle Jaster testing...
Comment #18
FatherShawnHas this patch been committed?
Comment #19
splash112 CreditAttribution: splash112 commentedAs soon a s I patched the 1.0 version downloaded from the project page, I got the error:
"warning: Attempt to assign property of non-object in /home/dinilu/public_html/drupal6/includes/file.inc on line 840."
Hope it still works
Comment #20
FatherShawn@splash112 - I'll have a look and reroll the patch as needed...
Comment #21
splash112 CreditAttribution: splash112 commentedThe patch applied perfectly to the 1.0 downloaded from the project page. The error came later. Maybe because before I used a dev version that's now nowhere to be found...?
Also, all new PDF's have now very bold letters, old ones are still the same. Will try to delete some files and upload a fresh version.
Thanks
Mark
Comment #22
maikeru CreditAttribution: maikeru commentedI'm using 1.0, and received the same error as #19 after saving the view with a new template.
It seems to appear if you select 'none' as your template and hit save on the view.
Shouldn't the file_set_status call be within an if statement to check if a $file was uploaded? (Changing to the below removes the error, and should still make it permanent)
Comment #23
FatherShawnSetting this back to needs review as I added a conditional to check that a file object is returned. This fix is committed to the D7 branch via #1362058: 7.x patch for views_pdf templates disappearing from directory needed but is still not commited to the D6 branch. I've used the same conditional as the D7 branch for consistency.
Comment #24
alibama CreditAttribution: alibama commentedpatched successfully against the dev version - have uploaded a file will know in a few hours - thanks for the help with this - great module
for anyone too lazy to patch there's a link to the patched dev version at the top of this page
http://blog.hsl.virginia.edu/drupalpress/views-pdf-vbo-rule-sets-thousands-of-custom-forms/
Comment #25
alibama CreditAttribution: alibama commentedconfirm this patch fixes the deletion = merci to all
Comment #26
jawad.shah CreditAttribution: jawad.shah commentedGreat work!
Reference #14 :
This patch is also working for me. Thanks FatherShawn .
Comment #27
Nor4a CreditAttribution: Nor4a commentedYap - #14 fixes the issue!
Thanks!
Comment #28
Simon Georges CreditAttribution: Simon Georges commentedCommitted, thanks!