Hi,

after upgrading from image module 5.x-2.0-alpha3 to 6.x-1.0-alpha4 I lost access to the image galleries.

Symptom: access to a gallery, e.g. image/tid/1917, results in "Zugriff verweigert" (= Access denied) for user #1 as well as for anonymous users; this error is displayed for users on the screen as well as in the watchdog log. The menu entry "Image galleries" points to www.mysite.org/image and lists the available galleries as well as the number of image nodes and an "last updated" timstamp.

As mentioned in 470720, during the upgrade from Drupal 5.18 to 6.12 the connections between image module and the gallery vocabulary are lost (as well as the connections between other vocabularies and custom content types; when upgrading, I followed the instructions from Drupal.org and disabled all modules before running update.php, then re-enabled the D6 versions of the modules again and re-run update.php several times, until no database updates were pending).

I restored the connection between the image content type and the "gallery" vocabulary at ./admin/content/taxonomy, however, the access problem remained. Individual image nodes can be displayed. ./admin/reports/status indicates no problems (all records "green"), e.g. "The imagemagick toolkit is installed", and "Galleries defined".

Any ideas or suggestions?

Greetings, -asb

Comments

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

Sounds very weird.
The only access checks in the module at in hook_menu, so if you can get to /image, you can get to the galleries.
Do you have any access modules installed, such as access by taxonomy?
Are you sure your translation is working correctly? Is there any chance it is actually translating 'Page not found'?

asb’s picture

> The only access checks in the module at in hook_menu, so if you can get to /image, you can get to the galleries.

Hmm... I rebuilt permissions through ./admin/content/node-settings, that changed nothing regarding to the image gallery.

> Do you have any access modules installed, such as access by taxonomy?

No access control module is running/enabled, and no access control module was installed (except Drupal core and CCK; even the "Content Permissions" module is disabled) - this is a very fresh site (about one week old ;), and it's pretty simple, not even stuff like pathauto is running yet.

> Are you sure your translation is working correctly? Is there any chance it is actually translating 'Page not found'?

Checked that by setting the default language back to English:

Access denied
You are not authorized to access this page.

Also I tried to disable and re-enable the "image gallery" and "image" modules, and to run update.php just once more; this showed no errors, and it had no noticeable effect.

Available permissions at ./admin/user/permissions for "image_gallery module": just "administer images".

The "Gallery" vocabulary is configured for Freetagging and Multiple Selections, but not Required. For the "Image" content type, there are also three other vocabularies enabled.

Overview:

  • access to www.mysite.org/image : Displays 6 Galleries with one image for each plus a text like "There are 14526 images in this gallery. Last updated: 19. May 2009 - 11:04"
  • access to www.mysite.org/image/tid/1918 (the first gallery) : gives "Access denied"; the same with all other root-level galleries
  • access to www.mysite.org/node/9674 (a random image node created in the last days) : Displays the full image node, including taxonomy terms, author, creation date, image preview, etc.

Is there anything that I could enable for debugging or verbose error logging?

Thanks & greetings, -asb

joachim’s picture

Check you have 'access content' granted to users. That's the check on gallery pages.

If that isn't the problem, and if you're comfortable messing with code, can you install devel module and do a test dsm() output in the image_gallery_page function please, to check the code gets there?

asb’s picture

> Check you have 'access content' granted to users. That's the check on gallery pages.

Granted to all users; and "Access denied for user #1" which should have all permissions anyway.

> If that isn't the problem, and if you're comfortable messing with code, can you install devel module and do a test dsm() output in the
> image_gallery_page function please, to check the code gets there?

If you can instruct me where to put what, I hope can do this. "Devel" is installed, but nothing enabled but "Devel" itself and a block with features like devel/elements, and devel/variable. In sites/all/modules/image/contrib/image_gallery/image_gallery.module, I located this function:

/**
 * Image gallery callback, displays an image gallery
 */
function image_gallery_page($type = NULL, $tid = 0) {
  $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
  for ($i=0; $i < count($galleries); $i++) {
    $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
    $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
    $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
    // The values of $descendant_tids should be safe for raw inclusion in the
    // SQL since they're all loaded from integer fields in the database.
    $sql = "SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (". implode(',', $descendant_tids) ."$
    if ($nid = db_result(db_query(db_rewrite_sql($sql)))) {
      $galleries[$i]->latest = node_load(array('nid' => $nid));
    }
  }

What to do now?

Thanks & greetings, asb

joachim’s picture

Just add a test output line at the top of that function, like this:

function image_gallery_page($type = NULL, $tid = 0) {
  dsm('the code gets to the gallery page function');
  $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
asb’s picture

Well, if I insert dsm('the code gets to the gallery page function'); into image_gallery.module, and access ./image, it prints "the code gets to the gallery page function" at the top of the image gallery page. When clicking on gallery like ./image/tid/1918, it prints nothing and outputs the "access denied" error. That's all, no nifty Krumo page or something helpful for a non-coder like me.

In "Pro Drupal Development", VanDyke writes about "Creating a Module-Based Vocabulary" and uses the image gallery module as an example: "It creates its vocabulary programmatically [...], and assumes ownership of the vocabulary by setting the module key of the $vocabulary array to the module name [...]" (p. 337 s). That makes me suscpicious since I do not understand that "assume ownership" part. If I query the database, I get:

mysql> select * from vocabulary where module='image_gallery';
+-----+---------+-------------+------+-----------+-----------+----------+----------+------+---------------+--------+
| vid | name    | description | help | relations | hierarchy | multiple | required | tags | module        | weight |
+-----+---------+-------------+------+-----------+-----------+----------+----------+------+---------------+--------+
|   5 | Galerie |             |      |         1 |         0 |        1 |        0 |    1 | image_gallery |      8 |
+-----+---------+-------------+------+-----------+-----------+----------+----------+------+---------------+--------+
1 row in set (0.02 sec)

That's pretty much the array from _image_gallery_get_vid(); is this vocabulary ownership somewhere evaluated? Could this have changed between image modules for D5 and D6, or have been malformed during the upgrade process?

Digging further in muddy water (meaning: not knowing what I'm talking about): Why generates "image gallery" module a path to it's galleries like ./image/tid/1918? Normal/other taxonomy paths look like so: ./taxonomy/term/1977. Funny: ./image/term/1918 does work, and displays the (sub-) galleries! (and also prints "the code gets to the gallery page function")

Clicking on the first gallery (./image/tid/2133) again results in the "access denied" error; changing the url in the browser location bar to ./image/term/2133 gives me "the code gets to the gallery page function" - and the gallery!!!

Greetings and a good night,
-asb

matthiassamwald’s picture

I also get the "access denied" error described by asb. I also set all of the necessary permissions, but it does not help. I can also subsitue 'tid' with 'term' in the URL, which makes it work.

joachim’s picture

Firstly, the term/tid thing. It's a historical quirk of this module that the path 'tid' is used. In fact, this piece of the path is completely unused and ignored. You could access your galleries at 'image/boogaloo/1918' just as well. It's actually fairly primitive code, as you could use it to show images with terms from any other vocabulary.

#6 shows that when at the path /image/tid/1918, it's not actually image module that's handling the request.
My guess is that both of you have another module whose hook_menu is defining something more specific than the path 'image'. Or you've set up a URL alias, or something like that.

sun’s picture

Views?

asb’s picture

@sun (#9):

I checked this by disabling Views (and everything depending on it); the "access denied" error remains.

@joachim (#8):

> #6 shows that when at the path /image/tid/1918, it's not actually image module that's handling the request.

I checked this, also, by disabling as much contributed modules as possible. And once again you're right. Full list of enabled modules when image_gallery started to handle galleries/sub-galleries:

  Block (block)                                                                 Aktiviert               Controls the boxes that are displayed$
  Blog (blog)                                                                   Aktiviert               Enables keeping easily and regularly $
  Book (book)                                                                   Aktiviert               Allows users to structure site pages $
  Color (color)                                                                 Aktiviert               Allows the user to change the color s$
  Comment (comment)                                                             Aktiviert               Allows users to comment on and discus$
  Contact (contact)                                                             Aktiviert               Enables the use of both personal and $
  Contact link (contactlink)                                                    Deaktiviert             Adds an author contact link to conten$
  Content (content)                                                             Aktiviert               Allows administrators to define new c$
  Database logging (dblog)                                                      Aktiviert               Logs and records system events to the$
  Date API (date_api)                                                           Aktiviert               A Date API that can be used by other $
  Database logging (dblog)                                                      Aktiviert               Logs and records system events to the$
  Date API (date_api)                                                           Aktiviert               A Date API that can be used by other $
  Filter (filter)                                                               Aktiviert               Handles the filtering of content in p$
  Help (help)                                                                   Aktiviert               Manages the display of online help.  $
  Image (image)                                                                 Aktiviert               Allows uploading, resizing and viewin$
  Image Attach (image_attach)                                                   Aktiviert               Allows easy attaching of image nodes $
  Image Gallery (image_gallery)                                                 Aktiviert               Allows sorting and displaying of imag$
  Image Import (image_import)                                                   Aktiviert               Allows batches of images to be import$
  Image Publishing (image_pub)                                                  Aktiviert               Supports image uploads using third pa$
  ImageMagick Advanced Options (image_im_advanced)                              Aktiviert               Adds advanced options to the ImageMag$
  Locale (locale)                                                               Aktiviert               Adds language handling functionality $
  Menu (menu)                                                                   Aktiviert               Allows administrators to customize th$
  Node (node)                                                                   Aktiviert               Allows content to be submitted to the$
  Path (path)                                                                   Aktiviert               Allows users to rename URLs.         $
  PEAR Wiki filter (pearwiki_filter)                                            Aktiviert               Filter which uses Text/Wiki package o$
  PHP filter (php)                                                              Aktiviert               Allows embedded PHP code/snippets to $
  Ping (ping)                                                                   Aktiviert               Alerts other sites when your site has$
  Profile (profile)                                                             Aktiviert               Supports configurable user profiles. $
  Search (search)                                                               Aktiviert               Enables site-wide keyword searching. $
  Statistics (statistics)                                                       Aktiviert               Logs access statistics for your site.$
  System (system)                                                               Aktiviert               Handles general site configuration fo$
  Taxonomy (taxonomy)                                                           Aktiviert               Enables the categorization of content$
  Taxonomy Manager (taxonomy_manager)                                           Aktiviert               Tool for administrating taxonomy term$
  Throttle (throttle)                                                           Aktiviert               Handles the auto-throttling mechanism$
  Token (token)                                                                 Aktiviert               Provides a shared API for replacement$
  Tracker (tracker)                                                             Aktiviert               Enables tracking of recent posts for $
  Trigger (trigger)                                                             Aktiviert               Enables actions to be fired on certai$
  Update status (update)                                                        Aktiviert               Checks the status of available update$
  Update status advanced settings (update_advanced)                             Deaktiviert             Adds advanced settings and extra func$
  Upload (upload)                                                               Aktiviert               Allows users to upload and attach fil$
  User (user)                                                                   Aktiviert               Manages the user registration and log$

Now I'll enable the other modules one by one, until I can spot the path hijacker.

Edit: Found the bad guy; in my case, it's the Edit Term module (related issue: 474200). Should we close this issue since "image gallery" seems not to cause the problem?

Greetings, -asb

asb’s picture

Priority: Critical » Normal
Status: Postponed (maintainer needs more info) » Closed (works as designed)

Changing status to "by design" (we need an status like "incompatibility")

joachim’s picture

Status: Closed (works as designed) » Active

from edit_term_menu():

    // Add an edit tab to gallery pages for easy access
    // Needs default view tabs for the advanced tab to show :-/
    $items['image/tid/%'] = array(
      'type' => MENU_CALLBACK,
    );
    $items['image/tid/%/view'] = array(
      'title' => t('View'),
      'weight' => 0,
      'type' => MENU_DEFAULT_LOCAL_TASK
    );
    $items['image/tid/%/edit-term'] = array(
      'title' => t('Edit Gallery'),
      'page callback' => 'edit_term_edit_taxonomy_term',
      'page arguments' => array(1),
      'access callback' => 'node_access',
      'access arguments' => 'administer images',
      'weight' => 1,
      'type' => MENU_LOCAL_TASK
    );

The problem is that edit term is trying to be helpful and integrate with image_gallery. It's doing this the proper way by using the cool stuff in the D6 menu system -- using the loading system with the % wildcard.
Meanwhile, image_gallery is still using ancient code that just registers the path at /image and then does the rest itself by looking at the arguments.
So edit_term registers the path 'image/tid/%' for the tabs to work, but doesn't supply the callback, and image_gallery hasn't given any 'real' data for that path to get handled. Result: access denied, for various complex reasons in the menu system (maybe because there's no user access callback?)

We could probably fix this by rewriting the menu code to use a loader.
The thing is, I want to move this module towards making galleries with views (#405456: Galleries made with views -- testers needed!), so I don't see that fixing the menu stuff here is a particularly good use of time. But I'll set this to active anyway -- if someone wants to provide a patch, we can commit it.

asb’s picture

Hi,

Dan already provided an updated version of "edit term" which solves the issue - I don't know if fixing something that is doing it the proper way to make something work that uses ancient code is a good thing, but "edit term" and "image gallery" is working again for me.

However, #405456 sounds really interesting and I'll have a look at this ;)

Greetings, -asb

joachim’s picture

Status: Active » Closed (works as designed)

Ok in which case let's close this again. Efforts are best concentrated on views integration.