On a project using nodequeue we had a need for keeping a subqueues content unique, i.e. to make sure that the same node could not be added twice. I have attached a patch with the changes we made. We're using 2.0 so the initial patch is against 2.x. If it is of any interrest I'll be happy to do a 3.x patch as well.

The patch introduces a configuration the nodequeue to "Enforce uniqueness" (default is false). If set any attempts to add nodes that are already present in a queue via nodequeue_subqueue_add will be ignored (and the attempt logged).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danquah’s picture

Status: Active » Needs review
FileSize
5.06 KB
mian3010’s picture

Great patch.

It seems that the nodequeue-module has several ways of adding nodes to a queue. We have to handle when people call the nodequeue_save_subqueue_order-function, as it manually clears queue and adds entries, in database. I have attached a revised patch.

alansaviolobo’s picture

I have used this patch and tested the case of adding nodes from the ui. the patch works fine.

fizk’s picture

Status: Needs review » Needs work

The last submitted patch, 5: nodequeue-2.x-enforce-uniqueness-2530742-5.patch, failed testing.

The last submitted patch, 5: nodequeue-2.x-enforce-uniqueness-2530742-5.patch, failed testing.

The last submitted patch, 5: nodequeue-2.x-enforce-uniqueness-2530742-5.patch, failed testing.

The last submitted patch, 5: nodequeue-2.x-enforce-uniqueness-2530742-5.patch, failed testing.

fizk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: nodequeue-2.x-enforce-uniqueness-2530742-10.patch, failed testing.

The last submitted patch, 10: nodequeue-2.x-enforce-uniqueness-2530742-10.patch, failed testing.

The last submitted patch, 10: nodequeue-2.x-enforce-uniqueness-2530742-10.patch, failed testing.

The last submitted patch, 10: nodequeue-2.x-enforce-uniqueness-2530742-10.patch, failed testing.

fizk’s picture

Any ideas why this error is showing up in the tests?

exception: [Notice] Line 1009 of sites/all/modules/nodequeue/nodequeue.module:
Undefined property: stdClass::$unique_entries
ramprassad’s picture

I also had a similar use case for implementing uniqueness in the queue. My patch also has a similar approach by having the 'unique_items' field but with much less code to evaluate uniqueness as I used the already available nodequeue_get_subqueue_position() to check if an item is available in the queue instead of a DB query. Also nodequeue_subqueue_add() will only be called only when the uniqueness check is passed.

ramprassad’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: nodequeue-2.x-enforce-uniqueness-2530742-17.patch, failed testing.

ramprassad’s picture

Status: Needs work » Active

Status: Active » Needs work

The last submitted patch, 17: nodequeue-2.x-enforce-uniqueness-2530742-17.patch, failed testing.

The last submitted patch, 17: nodequeue-2.x-enforce-uniqueness-2530742-17.patch, failed testing.

The last submitted patch, 17: nodequeue-2.x-enforce-uniqueness-2530742-17.patch, failed testing.

danquah’s picture

The way the test-nodequeue is being build in createNodequeue in http://cgit.drupalcode.org/nodequeue/tree/tests/nodequeue.test#n59 means that any defaults in the nodequeue_queue has to be duplicated there as well.

This updated patch should fix the notice.

dgale’s picture

I get this error when trying to apply the patch in #25 or #24

error: patch failed: nodequeue.module:582
error: nodequeue.module: patch does not apply
error: tests/nodequeue.test: No such file or directory
fizk’s picture

Status: Needs review » Reviewed & tested by the community

@danquah Thanks, this works for me now and passes the tests.

It would be great to write a test for this new feature. If anyone has time to write a test, that would be great. Otherwise, I might commit this as-is.

fizk’s picture

Issue tags: +Needs tests
shaktik’s picture

applied patch in #25, its works fine...
attached screenshot

  • jenlampton committed c95f2f9 on 7.x-2.x authored by danquah
    Issue #2530742 by danquah, fizk, ramprassad, mian3010, shaktik: Option...
jenlampton’s picture

Status: Reviewed & tested by the community » Fixed

Merged into 7.x-2.x

Status: Fixed » Closed (fixed)

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