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).
Comment | File | Size | Author |
---|---|---|---|
#29 | Screen Shot 2017-01-11 at 9.59.52 PM.png | 21.99 KB | shaktik |
#25 | nodequeue-2.x-enforce-uniqueness-2530742-25.patch | 5.64 KB | danquah |
Comments
Comment #1
danquah CreditAttribution: danquah at Reload commentedComment #2
mian3010 CreditAttribution: mian3010 commentedGreat 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.Comment #3
alansaviolobo CreditAttribution: alansaviolobo at Axelerant commentedI have used this patch and tested the case of adding nodes from the ui. the patch works fine.
Comment #5
fizk CreditAttribution: fizk commentedResubmit for testing.
Comment #10
fizk CreditAttribution: fizk commentedShould apply to HEAD now.
Comment #11
fizk CreditAttribution: fizk commentedComment #16
fizk CreditAttribution: fizk commentedAny ideas why this error is showing up in the tests?
Comment #17
ramprassad CreditAttribution: ramprassad commentedI 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.
Comment #18
ramprassad CreditAttribution: ramprassad commentedComment #20
ramprassad CreditAttribution: ramprassad commentedComment #24
danquah CreditAttribution: danquah at Reload commentedThe 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.
Comment #25
danquah CreditAttribution: danquah at Reload commentedSorry about that, I fixed the wrong patch :)
While the patch in #17 does use a bit less code, it misses the feature of clearing the nodequeue of duplicates as the uniqueness constraint is switched on.
I've attached an opdated version of the patch from #10 that with the same fix I applied in #24
Comment #26
dgale CreditAttribution: dgale commentedI get this error when trying to apply the patch in #25 or #24
Comment #27
fizk CreditAttribution: fizk commented@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.
Comment #28
fizk CreditAttribution: fizk commentedComment #29
shaktikapplied patch in #25, its works fine...
attached screenshot
Comment #31
jenlamptonMerged into 7.x-2.x