function nodequeue_subqueue_add in Nodequeue 7.2
Same name and namespace in other branches
- 5.2 nodequeue.module \nodequeue_subqueue_add()
- 6.2 nodequeue.module \nodequeue_subqueue_add()
- 7.3 nodequeue.module \nodequeue_subqueue_add()
Add a node to a subqueue.
Parameters
$queue: The parent queue of the subqueue. This is required so that we can pop nodes out if the queue breaks size limits.
$subqueue: The subqueue to add the node to.
$nid: The node ID. Defaults to NULL.
Throws
Exception
13 calls to nodequeue_subqueue_add()
- action_nodequeue_add in includes/
nodequeue.actions.inc - Old-style action to add a node to a queue.
- NodequeueAPISubqueueUnitTest::testNodequeueQueueClear in tests/
nodequeue.test - NodequeueAPISubqueueUnitTest::testNodequeueSubqueueAdd in tests/
nodequeue.test - NodequeueAPISubqueueUnitTest::testNodequeueSubqueueRemove in tests/
nodequeue.test - NodequeueAPISubqueueUnitTest::testNodequeueSubqueueRemoveNode in tests/
nodequeue.test
File
- ./
nodequeue.module, line 1378 - Maintains queues of nodes in arbitrary order.
Code
function nodequeue_subqueue_add($queue, &$subqueue, $nid = NULL) {
if (!empty($nid)) {
// Don't add the node if the queue is configured to enforce uniqueness.
if (!empty($queue->unique_entries)) {
$result = db_query("SELECT nid FROM {nodequeue_nodes} WHERE sqid = :sqid AND qid = :qid AND nid = :nid", array(
':sqid' => $subqueue->sqid,
':qid' => $queue->qid,
':nid' => $nid,
));
if (empty($result) || $result
->rowCount() > 0) {
// We have no way of telling the caller that the node was not added, so
// log the event and return.
watchdog('nodequeue', 'The queue does not allow duplicated entries and already contained the node with nid !nid', array(
'!nid' => $nid,
));
return;
}
}
$transaction = db_transaction();
try {
if ($queue->insert_at_front) {
db_update('nodequeue_nodes')
->expression('position', 'position + 1')
->condition('sqid', $subqueue->sqid)
->execute();
$position = 1;
}
else {
$position = db_query("SELECT COALESCE((SELECT MAX(position) + 1 FROM {nodequeue_nodes} WHERE sqid = :sqid), 1)", array(
':sqid' => $subqueue->sqid,
))
->fetchField();
}
db_insert('nodequeue_nodes')
->fields(array(
'sqid' => $subqueue->sqid,
'qid' => $queue->qid,
'nid' => $nid,
'position' => $position,
'timestamp' => REQUEST_TIME,
))
->execute();
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('nodequeue', $e);
throw $e;
}
$subqueue->count = db_query("SELECT COUNT(nid) FROM {nodequeue_nodes} WHERE sqid = :sqid", array(
':sqid' => $subqueue->sqid,
))
->fetchField();
// If adding this would make the queue too big, pop the front node
// (or nodes) out.
if (!empty($queue->size)) {
// 0 means infinity so never do this if FALSE.
nodequeue_check_subqueue_size($queue, $subqueue, $queue->size);
}
if (module_exists('apachesolr')) {
apachesolr_mark_entity('node', $nid);
}
// Invoke the hook to notify other modules of the node addition.
module_invoke_all('nodequeue_add', $subqueue->sqid, $nid);
}
}