summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nodequeue.module17
1 files changed, 14 insertions, 3 deletions
diff --git a/nodequeue.module b/nodequeue.module
index 81698cb..452e33a 100644
--- a/nodequeue.module
+++ b/nodequeue.module
@@ -1001,11 +1001,22 @@ function nodequeue_remove_subqueue($sqid) {
* @param $subqueue
* The subqueue to add the node to.
* @param $nid
- * The node ID
+ * The node ID. Defaults to NULL.
*/
-function nodequeue_subqueue_add($queue, &$subqueue, $nid) {
+function nodequeue_subqueue_add($queue, &$subqueue, $nid = NULL) {
if (!empty($nid)) {
- db_query("INSERT INTO {nodequeue_nodes} (sqid, name, nid, position, timestamp) VALUES (:sqid, :name, :nid, IFNULL((SELECT MAX(position)+1 FROM (SELECT * from {nodequeue_nodes} WHERE sqid = :sqid) as nn), 1), :time)", array(':sqid' => $subqueue->sqid, ':name' => $queue->name, ':nid' => $nid, ':time' => REQUEST_TIME));
+ $transaction = db_transaction();
+ try {
+ $position = db_query("SELECT MAX(position) + 1 FROM (SELECT * FROM {nodequeue_nodes} WHERE sqid = :sqid) as nn", array(':sqid' => $subqueue->sqid))->fetchField();
+ $position = !empty($position) ? $position : 1;
+ db_query("INSERT INTO {nodequeue_nodes} (sqid, name, nid, position, timestamp) VALUES (:sqid, :name, :nid, :position, :time)", array(':sqid' => $subqueue->sqid, ':name' => $queue->name, ':nid' => $nid, ':position' => $position,':time' => REQUEST_TIME));
+ }
+ 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.