User content subscription views handling does not work at all.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

czigor’s picture

User content views integration cleaned up a bit.

czigor’s picture

Status: Active » Needs review
czigor’s picture

Typo fix in one of the array keys.

Rob230’s picture

Can you clarify what you fixed in this patch?

I don't know whether a separate issue is needed for this, but I have found the Views integration to be very sketchy.

For example, when trying to create a block View that shows users subscribed to current node. First of all I tried it in the logical way:

  • Show: Users
  • Relationship: Notifications Fields: Content
  • Contextual filter: (Content) Content: Nid: provide default value from URL

This fails immediately on the relationship with the following SQL error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= notifications_subscription_fields.usid LEFT JOIN node node_notifications_subsc' at line 1

The query:

SELECT users.name AS users_name, users.uid AS uid, users.created AS users_created
FROM 
{users} users
LEFT JOIN {notifications_subscription_fields} notifications_subscription_fields ON users. = notifications_subscription_fields.usid
LEFT JOIN {node} node_notifications_subscription_fields ON notifications_subscription_fields.value = node_notifications_subscription_fields.nid AND notifications_subscription_fields.type = 'node:nid'
WHERE (( (users.status <> '0') ))
ORDER BY users_created DESC
LIMIT 5 OFFSET 0

Note the error: it has users. for the join condition. This is because in notifications_views.views.inc it is specified as:

$data['notifications_subscription_fields']['table']['join'] = array(
    'users' => array(
      'field' => 'usid',
    ),

Views requires 'left_field' to be specified for a join. Furthermore, there is no such field as notifications_subscription_fields.usid. I don't think it's possible to join to this table on uid, only to notifications_subscription, which contains the field uid.

The second problem I discovered when trying to approach it in a different way. I created a View like this:

  • Show: Notifications
  • Relationship: Notifications Fields: Content
  • Relationship: Notifications: Subscriber UID
  • Contextual filter: (Content) Content: Nid
  • Field: (subscriber) User: Name
  • Sort criteria: Notifications: Updated date (asc)

This fails on the sort criteria:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'notifications_subscription.changed' in 'field list'

Indeed, there is no such field. The correct field name is notifications_subscription.updated. This is easily fixed in notifications_views.views.inc by changing this line:

$data['notifications_subscription']['changed'] = array(

I wonder how many other things like this slipped through and haven't been noticed since 2011. Also, is this module abandoned?

czigor’s picture

In our site users can subscribe other users. I used this patch for to purposes:
#1: to display the users a given user is following.
#2: to display the users who follow a given user.
For example the view for #1 goes:
- User type view
- contextual filter: user uid
- 2 relationships: 1. user subscriptions 2. (subscriptions) Notifications Fields: Author
- 1 field: (Author) User: Rendered User

I think the patch in https://drupal.org/node/1268970#comment-6831516 is also needed.

My patch does not fix the whole views integration at all, just the bit I needed, that's why you see those SQLSTATE errors.

According to the project page the module is not abandoned, only seeking a new maintainer.