Closed (fixed)
Project:
File (Field) Paths
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Jul 2009 at 20:38 UTC
Updated:
25 Jan 2010 at 08:50 UTC
In PHP 5.1 and lower, the [filefield-onlyname-original] token doesn't work since the PHP pathinfo() function doesn't set a value for 'filename' in its returned array. Possible patch below:
--- /nfs/home/D/dwong/filefield_paths.module 2009-07-09 16:29:43.432792000 -0400
+++ filefield_paths.module 2009-07-09 16:32:11.200918000 -0400
@@ -645,7 +645,13 @@ function filefield_paths_token_values($t
if (!empty($object[0]['origname'])) {
$orig = pathinfo($object[0]['origname']);
}
- $tokens['filefield-onlyname-original'] = $orig['filename'];
+ if (!isset($orig['filename'])) {
+ // < PHP 5.2
+ $tokens['filefield-onlyname-original'] = substr($object[0]['filename'], 0, strpos($object[0]['filename'], '.'));
+ }
+ else {
+ $tokens['filefield-onlyname-original'] = $orig['filename'];
+ }
$tokens['filefield-extension-original'] = $orig['extension'];
return $tokens;
}
Comments
Comment #1
decipheredHi dwong127,
Thanks for picking up on that one.
I had to make some changes to the code as it was only grabbing the current filename, not the original filename, but it has been fixed and committed to DRUPAL-5 and DRUPAL-6--1.
Dev release should be available in about two hours or so.
Cheers,
Deciphered.
Comment #2
decipheredComment #3
sp3boy commentedSorry to be a real pain, but hopefully there is a quick answer to this which (despite spending some hours searching) I've missed:
The {files}.origname column is added by Filefield_paths, yes?
It is referenced in
filefield_paths_token_values(), (as seen in the patch above)?Where is it loaded to the node object? As far as I can see (having done some step-by-step debugging in Eclipse) it is not populated on the $object[0]. So any re-creation of a filepath or filename from the original filename will not know the original name and fall back on the current (possibly post-tokenised) filename?
Comment #4
sp3boy commentedHa, I was indeed being a pain! After some more hours of testing Image with Filefield_paths I have found why Uploaded files have the "origname" node property populated on load but Images don't -
upload_load()performs a SELECT * on {files} which pulls in the column.image_load()only takes specific columns from {files}.Now I just need to figure out what should be done in Image...
Comment #5
decipheredHI sp3boy,
Sorry I didn't reply, but I really haven't been able to give much time to my Drupal projects of late.
I did see this issue, but I wanted to just confirm it before responding, but you are absolutely correct, it isn't FileField Paths that reads in the column.
If you are unable to fix the issue on Image's side, it would be possible to make a Image module specific change to fix this in the modules/image.inc file of FileField Paths.
Let me know how you go.
Cheers,
Deciphered.
Comment #6
emok commentedBack to the original issue: It is not just filefield-onlyname-original that needs fixing. Also a few lines up where filefield-onlyname is set you need to handle the quirks of old PHP versions. In
filefield_paths_token_values(), I suggest you changeinto
Comment #7
decipheredEmok,
You're absolutely correct, oversight on my behalf. That's why I don't like fixing issues that I can't reproduce.
Will fix shortly.
Cheers,
Deciphered.
Comment #8
decipheredThis has been committed and is available in 6.x-1.4.
Cheers,
Deciphered.