/** * Allow synchronization of NodeQueues. */ function qsync_form_nodequeue_arrange_subqueue_form_alter(&$form, &$form_state) { $form['custom-sync'] = array( '#type' => 'fieldset', '#title' => t('Synchronize queues'), '#collapsible' => TRUE, '#collapsed' => ($form['#queue']['qid'] == 5) ? FALSE : TRUE, // Custom code here. ); $form['custom-sync']['active_subqueue'] = array( '#type' => 'value', '#value' => $form['#subqueue']['sqid'], ); $form['custom-sync']['active_queue'] = array( '#type' => 'value', '#value' => $form['#queue']['qid'], ); // Construct a matching query by allowed node types. $in = ''; foreach ($form['#queue']['types'] as $type) { $in .= "'". check_plain($type) ."',"; } $result = db_query("SELECT nq.title, nq.sqid, nq.qid FROM {nodequeue_subqueue} nq INNER JOIN {nodequeue_types} nt ON nt.qid = nq.qid WHERE nq.sqid <> %d AND nq.qid <> %d AND nt.type IN (". trim($in, ',') .")", $form['#subqueue']['sqid'], $form['#queue']['qid']); $options = array(); while($data = db_fetch_object($result)) { $options[$data->qid .':'. $data->sqid] = $data->title; } $form['custom-sync']['target_queue'] = array( '#title' => t('Target queue'), '#type' => 'select', '#default_value' => ($form['#queue']['qid'] == 5) ? '1:1' : '5:5', // This part is custom. '#options' => $options, ); $form['custom-sync']['target_action'] = array( '#title' => t('Action'), '#type' => 'radios', '#default_value' => 0, '#options' => array(t('Pull changes from target'), t('Push changes to target')), ); $form['custom-sync']['submit'] = array( '#value' => t('Synchronize queues'), '#type' => 'submit', '#submit' => array('nodequeue_arrange_subqueue_form_submit', 'queue_sync_nodequeue_submit'), ); } /** * Process a synchronization submission. */ function qsync_sync_nodequeue_submit($form, &$form_state) { $values = $form_state['values']; if ($values['op'] != $values['custom-sync']['submit']) { return; } $sync = $values['custom-sync']; list($qid, $sqid) = explode(':', $sync['target_queue']); if (empty($sync['target_action'])) { db_query("DELETE FROM {nodequeue_nodes} WHERE qid = %d AND sqid = %d", $sync['active_queue'], $sync['active_subqueue']); $result = db_query("SELECT * FROM {nodequeue_nodes} WHERE qid = %d AND sqid = %d", $qid, $sqid); while ($data = db_fetch_array($result)) { $data['qid'] = $sync['active_queue']; $data['sqid'] = $sync['active_subqueue']; $data['timestamp'] = $_SERVER['REQUEST_TIME']; drupal_write_record('nodequeue_nodes', $data); } drupal_set_message(t('Changes have been updated from the target queue')); } else { db_query("DELETE FROM {nodequeue_nodes} WHERE qid = %d AND sqid = %d", $qid, $sqid); $result = db_query("SELECT * FROM {nodequeue_nodes} WHERE qid = %d AND sqid = %d", $sync['active_queue'], $sync['active_subqueue']); while ($data = db_fetch_array($result)) { $data['qid'] = $qid; $data['sqid'] = $sqid; $data['timestamp'] = $_SERVER['REQUEST_TIME']; drupal_write_record('nodequeue_nodes', $data); drupal_set_message(t('Changes have been pushed to the target queue')); } } cache_clear_all(); }