First let me say that I am not in maintence mode when this happens. It effects all users including admin. When a user selects the option "New gallery of 'Gallery Image' images using plupload", after a user has selected images and attempts to upload them, a JS error window pop up that says 'Failed to create Gallery: Request failed', and when you close it the server throws an error. The server log says this "call to undefined function node_gallery_gallery_to_arg() in /home/includes/menu.inc on line 607" This error does not happen if you first create the gallery then upload images. I chose major because, while this has a work arround by creating the gallery first, it causes an actual 500 error.

It seems to have some relationship to this change http://drupal.org/node/1006076
"failed to create gallery: request failed"

CommentFileSizeAuthor
#12 clean-url-fix-1177286.patch3.5 KBjustintime

Comments

justintime’s picture

Have you tried clearing all of your caches?

alricsca’s picture

Yes, I have several times. I also uninstalled and reinstalled. I tried changing the performance settings as well.

justintime’s picture

I can't reproduce. I've tried on my local install, and on the public demo at http://ng3demo.sysadminsjourney.com - both of which run 3.0-beta1. Is this by chance an upgrade from 2.x? Is it possible that you have two node_gallery directories? I'm stumped, because the error you post says:

call to undefined function: node_gallery_gallery_to_arg()

but that function is clearly defined at line 983 in node_gallery.module.

If you can't duplicate it on the demo site, then it's likely a conflicting module or theme issue.

alricsca’s picture

Okay I changed the theme, which is cti_flex, that did not seem to help. I am currently trying to turn off and on various modules. Could you explain the load logic for the wizard page? Where and what loads the missing method after a user hits upload with Pupload? Keep in mind the image and its node are being created. The creation of the gallery node is what seems to be failing. I could examine that.

I do find it interesting that the other issue I referred to has a patch with the line below in it and the 12th commenter refers to my same issue. Could it be that do not have that module for additional access control modules installed?

+ var galleryCreationFailed = function () {
+ self.errorMessage = Drupal.t("Failed to create gallery: Request failed.");
+ self.uploader.stop();

justintime’s picture

It can't be node_access modules, because if it was, doing this as UID1 would succeed.

The general workflow is that just before the upload begins, the plupload makes a request to node-gallery/json/gallery/create/<gallery_type> which creates a new empty gallery to hold the images. That's what's failing.

If you're running with the stock content types, you should be able to login to your drupal site, and hit http://example.com/node-gallery/json/gallery/create/node_gallery_gallery and get back a json encoded node. Do you?

Also, you didn't mention if you had tried to reproduce this on the demo server linked above.

alricsca’s picture

That last message helped me diagnose the problem. It is caused by the URL
node-gallery/json/gallery/create/node_gallery_gallery does not work it throws the error.
?q=node-gallery/json/gallery/create/node_gallery_gallery works and returns JSON.
I tried the demo gallery but it uses Clean URLs.

It appears the code is not respecting the Clean Url settings.

justintime’s picture

Title: "New gallery of 'Gallery Image' images using plupload" fails » plupload AJAX callback fails with Clean URL's disabled
Priority: Major » Normal
Status: Active » Needs review

Ah, now we're onto something.

Not using Clean URL's puts you in a very small minority of Drupal users -- please make sure to bring up that fact when creating issues.

In node_gallery 2.x, we required Clean URL's, but it was inherent, because at the time we required ImageCache which required clean URL's. I didn't know this, but it seems that ImageCache now requires *either* Clean URL's *or* private files. I'm guessing you're using private files then?

If that's indeed the case, I don't see any reason why we can't support it. I'm pretty sure the bug is in the javascript.

Open up js/ng_plupload.js, and find on line 43 where it says:

        var url = Drupal.settings.basePath + 'node-gallery/json/gallery/create/' + self.galleryType;

Replace that entire line with:

        var url = Drupal.settings.basePath + '?q=node-gallery/json/gallery/create/' + self.galleryType;

If that works for you, let me know. I'll need to test it to make sure it doesn't break things for Clean URL-enabled sites.

Also, you're the first person that I know of to extensively test NG without Clean URL's, so beware there may be other bugs. If you're willing to find and report them, I'm willing to fix them!

alricsca’s picture

We were on the same page on that one. I was just about to write that on a hunch I tried what you just described to do and it did indeed work. Just a note, I saw two lines that used self.uploader.bind in that js file. If I have other trouble with the Gallery, I will take a look and report it. One thing that bothers me is that this seems like a kludge, I have been searching for a way to detect Clean Url with js with no luck so far, it may be that a quick parse of the current url for the "/?q=" portion and using a conditional is better than hard coding it.

alricsca’s picture

Just a quick second note on avoiding hard coding this. It would be best to detect the Clean URL, as I was thinking about another site I worked on that used a custom mod_rewrite and could not accept ? in the path as result. I know Drupal ordinarily may handle it but it may break some site's custom URL handling.

justintime’s picture

The one thought I had was that we could pass the value of $conf['clean_url'] into Drupal.settings and check it before creating the URL.

There's a few other places in the project we're using basePath in javascript, so I'm sure those are broken as well. I'll try to get a patch that fixes all of them whipped up later today.

alricsca’s picture

Great. When the update is released I will switch to it and test.

justintime’s picture

StatusFileSize
new3.5 KB

Sorry, I'm running short on time, but here's a completely untested patch.

alricsca’s picture

Uploading and creation of a new gallery work good with the patch. On a possibly related issue, I did notice that with the use of the Jquery option for sorting that it will let me drag the images to a new sort order but when I hit save it says nothing was changed. Might relate to this or might be new issue.

justintime’s picture

Status: Needs review » Fixed

I just tested on a clean-url enabled site, and things still work there too. Committed this to dev. Can you open a new issue for your jquery sort bug?

Status: Fixed » Closed (fixed)

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