I have a fresh drupal 7(7.12) installation
with the following modules installed
Pathauto 7.x-1.0
FileField Sources 7.x-1.4
File (Field) Paths 7.x-1.0-beta3
File Aliases 7.x-1.0-beta1
Once i set up the content type with images I was getting the error message below when trying to create a new node
PHP Fatal error: Cannot use object of type stdClass as array in ../public_html/sites/all/modules/file_aliases/modules/filefield_paths.inc on line 33
I decided to delve into the module to take a look at the code, and discovered that it was not upto date
the function in the filefield_paths.inc read,
file_aliases_filefield_paths_process_file($new, &$file, $settings, &$entity, $type, &$update)
whereas the the method called in the the /modules/filefield_paths/filefield_paths.module ln : 245 reads.
$function($type, $entity, $field, $instance, $langcode, $files);
note the mismatch in the parameter list.
In the attempt to fix the module i decided to change the all/modules/file_aliases/modules/filefield_paths.inc's file_aliases_filefield_paths_process_file function ln: 32
Ive attached my whole all/modules/file_aliases/modules/filefield_paths.inc in this ticket,
Please review a better view.
Regards,
MRister
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | paths_process_file-1492978-32.patch | 1.77 KB | Anonymous (not verified) |
Comments
Comment #1
dmcmeans commentedI downgraded to beta 1 from beta 3. Unfortunately, beta 2 or 3 removes the filefield_paths table required by beta 1. Restoring that was a real bear. I wish I had made a db backup. This is the first time in 4 years of drupal I've experienced a module update for which I should have made a db backup.
Comment #2
Vc Developer commentedHi,
Is there a patch for this, I'm still getting this error? Wouldn't allow me to publish an Article for some reason. I do have "Display Suite" layout configured, but when I removed "File Aliase" I was able to publish.
Thanks!...
Comment #3
dandaman commentedFor me, replacing the file with the code above did work well so far on my test site. There were a number of errors because the files weren't actually there, but it seemed to work, yeah. I'll try to roll a patch sometime.
Comment #4
Vc Developer commentedHi,
I also applied the patch above and so far I have not found any problems!
Thanks mrister!..
Comment #5
greg.1.anderson commentedThe code attached to #0 does not seem to match the description in #0. The parameters for hook_filefield_paths_process_file does appear to be as described (
$function($type, $entity, $field, $instance, $langcode, $files);), but the provided fix does not use the same parameter list, leaving me wondering what the intention was. The purpose of the hook seems to be to call path_save to map from filefield_paths/alias/{$value['fid']}, but the code above maps it to an empty string.I started to work on this, but $settings is no longer passed in to the function, so I could not find a couple of needed values.
Oddly enough, the URL for my objects came out correctly, even though this function seems to be a no-op at the moment.
Comment #6
greg.1.anderson commentedHere is a patch against 1.x-dev that I believe correctly conforms to the new API for hook_filefield_paths_process_file.
Comment #7
neRok commented#6 works, but not as intended. It pulls the tokens/settings from the Field Path and Field Name boxes that come with the filefield_paths module, not from the File Alias box that comes with this module.
I have mucked around with the /file_aliases/modules/filefield_paths.inc and got it to work properly. Unfortunately, creating patch files is beyond my skills, so if someone else could. This is the whole contents of that file (as part of the current dev).
This will create the alias and everything, but an error does come up when you use the Retroactive update feature. This error is
Where xxxxxxxx is the base url and yyyyyyyy.zzz is the filename alias (with or without subfolders). I will briefly look into this now, but I'm not going to spend a lot of time on it because it doesnt effect the website I am working on.
Comment #8
neRok commentedGot it! Took me HOURS and HOURS, and in the end, only an underscore was required (lol).
Line 33 of file_aliases.module needs changing to the following;
Making this a private function (add the underscore prefix) fixed everything, and it all seems to work on my system. The problem was this function was setting the file->uri to the aliased path, and then the filefield_path module could not move it (needed actual path, not alias). Making this function private means the filefield_path module does not use the file_alias hook.
There maybe another fix required, but I am not too knowledgeable. Line 93 of file_aliases.module reads
$results = db_select('file_managed', 'f')but I am wondering if it should read$results = db_select('{file_managed}', 'f').A tweak may also be required to my code above (post #7). The code in $token_data array is created slightly different in the filefield_path modules code, so we should probably keep it the same. It should change to
Comment #9
konopko commentedComment #10
konopko commentedTo #8 — great job, it almost work!
But my original image alias doesn't works:
[host]/files/120529-2116488.jpg?large — ok
[host]/files/120529-2116488.jpg — not open the image
Can you fix it? Thnx
Comment #11
neRok commentedI have used this for thousands of images now, and everything is working for me, so not sure what your problem could be. It could be that the 'source' image has moved or been deleted, but the styled image was left behind in the styles/large/.... folder. You would need to investigate.
Comment #12
konopko commentedBut my problem still actual:
The original image places normally, but alias doesn't works.
Your suggestions?
Comment #13
neRok commentedHave you checked your logs for clues? What are you file path and alias settings, post them here. Perhaps you should run a retroactive update, to fix any issues?
Comment #14
neRok commentedThere is a 'strict reference' error (or similar). Small tweak is required to fix. This code in post #7
Needs to be replaced with
Comment #15
mrfelton commentedPatch attached, compiled from comments above.
Comment #16
polHello,
I'm making a simple file sharing like system on my site.
I've applied the patch #15 successfully and the alias is not working.
I got a 'The requested page "/7bc19947aea2e5ab344302da696f1f0657ce7e99" could not be found.' when I click on the like to my file.
The tokens are:
The file alias is set to: [random:hash:sha1]
The file name is set to: [file:ffp-name-only-original].[file:ffp-extension-original]
Comment #17
sunchaser commented@pol : how did you successfully apply that patch while I get smacked in the face with "trailing whitespace" errors ? and a fatal error at line 56 ?
Comment #18
greg.1.anderson commentedI didn't try to run #15, but Drush IQ will apply it just fine. (
drush iq-apply-patch 1492978)Comment #19
sunchaser commenteddon't have drush on the server I'm working on :/ but thanks anyhow
Comment #20
sunchaser commentedmy bad - i wasn't patching against the dev version - terribly sorry.
Comment #21
arthur_drupal commentedHere is my patch but can't apply with git apply, i do it manually right now ...
Hope it helps
Comment #22
polYou should not use tabs, but spaces.
You should also remove trailing spaces.
I think it's not a good practice to use that kind of string concatenation. use
$var = 'string' . $var;Comment #23
arthur_drupal commentedHi Pol and thanx for your feedback.
I will do it again and post the new one ;)
For the syntax, i keep the original one.
Arthur
Comment #24
kclarkson commentedI had to apply the patch from #21 I by hand due to the whitespace errors.
After changing the code all of my directories are created, renaming of the file works and the directory alias works. Thanks a bunch !!!
Although everything looks to be working correctly I am now receiving the following error:
Notice: Undefined index: file_alias in file_aliases_filefield_paths_process_file() (line 39 of sites/all/modules/contrib/file_aliases/modules/filefield_paths.inc).
Looking forward to the patch.
Also could the Maintainer set up the GIT revision tab for 7.x-1.x as I really enjoy trying out patches with git :)
Comment #25
neRok commentedThe patch in #21 has different code to what I posted in #7 (which btw I am using on numerous servers without error), and it appears that is causing the problem.
I had in #7
$file['filealias'] = filefield_paths_process_string($settings['file_alias']['value'], $token_data, $settings['file_alias']['options']);Patch in #21 has
$file['filealias'] = filefield_paths_process_string($settings['file_alias']['file_alias'], $token_data, $settings['file_alias']['options']);Comment #26
kclarkson commented@neRok
Thanks for helping out with this code !!
The patch that was made from your comments did not include the changes to Line 33 of file_aliases.module
You have coding skills that the Drupal community would really benefit from. I can't write a line of code but know how to patch :) here is a link that helped me out. http://jacine.net/post/8419331209/patches#create
Comment #27
kclarkson commentedThe attached patch combines all of neRok's comments.
If anyone can help with the two whitespace errors and re-roll that would be helpful.
Comment #28
yannickooHad the same error and all is working fine now with patch from #27. Rerolled the patch because of the whitespaces.
Comment #29
koshi commentedYes, #28 works. It also will fix another bug (Files can no longer be deleted from server when deleting a node.). Bu there is another one. Version: 7.x-1.x-dev is still affected by "File Aliases remain after deleting/removing files from FileFields" bug.
Comment #30
neRok commentedI have made a patch to fix a bunch of issues with File Aliases module, including this issue, in the following issue.
#1896326: Combined patch for all known issues in D7 branch
Comment #31
deciphered commentedWhy change the function name? It will no longer trigger when the hook is invoked.
This is not valid, database tables are no longer wrapped with {}'s.
I note that these changes weren't implemented until #27, which is the 'combined patch'.... I suggest breaking those changes out and going back to the actual issue at hand here.
Comment #32
Anonymous (not verified) commentedHere's a clean patch that simply updates the file_aliases_filefield_paths_process_file() function to use the new parameters. Not sure if it works properly (though I can now save nodes without errors), so others should review.
Comment #33
Anonymous (not verified) commentedComment #34
lias commentedUsed patch from #32 and it fixed the fatal error - using filefield_paths 7x-1.0-rc1 and file_aliases 7x-1x-dev.
Comment #35
deciphered commentedThanks for the report, this module is still on my radar.
Comment #36
deciphered commentedLatest commit has re-written this whole section and it now works correctly.
Comment #38
cstalberg commenteddelete