diff --git a/advancedqueue.info b/advancedqueue.info index 7697e17..aa174be 100644 --- a/advancedqueue.info +++ b/advancedqueue.info @@ -2,6 +2,7 @@ name = Advanced Queues description = Helper module for advanced queuing. package = Other core = 7.x +configure = admin/config/system/advancedqueue files[] = advancedqueue.queue.inc diff --git a/advancedqueue.module b/advancedqueue.module index 16c9450..a971261 100644 --- a/advancedqueue.module +++ b/advancedqueue.module @@ -50,3 +50,66 @@ function advancedqueue_entity_info() { ); return $entity_info; } + +/** + * Implements hook_menu(). + */ +function advancedqueue_menu() { + $items = array(); + + $items['admin/config/system/advancedqueue'] = array( + 'title' => 'Advanced Queue configuration', + 'description' => 'Configuration for the Advanced Queue module.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('advancedqueue_settings'), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + + return $items; +} + +/** + * Form builder; Advanced Queue form. + * + * @see system_settings_form() + */ +function advancedqueue_settings() { + $form['description'] = array( + '#markup' => '

' . t('Advanced Queue replaces the standard Queue and enhances it.') . '

', + ); + + $form['advancedqueue'] = array( + '#type' => 'fieldset', + ); + $form['advancedqueue']['advancedqueue_threshold'] = array( + '#type' => 'select', + '#title' => t('Number of successfully completed jobs to keep in the database.'), + '#default_value' => variable_get('advancedqueue_threshold', 0), + '#options' => array(0 => t('All'), 100, 1000, 10000, 100000, 1000000), + ); + return system_settings_form($form); +} + +/** + * Implements hook_cron(). + */ +function advancedqueue_cron() { + // Cleanup the advancedqueue table + $row_limit = variable_get('advancedqueue_threshold', 0); + if ($row_limit > 0) { + $min_row = db_select('advancedqueue', 'a') + ->fields('a', array('item_id')) + ->condition('status', ADVANCEDQUEUE_STATUS_SUCCESS) + ->orderBy('item_id', 'DESC') + ->range($row_limit - 1, 1) + ->execute()->fetchField(); + // Delete all table entries after the nth row, if nth row was found. + if ($min_row) { + db_delete('advancedqueue') + ->condition('item_id', $min_row, '<') + ->condition('status', ADVANCEDQUEUE_STATUS_SUCCESS) + ->execute(); + } + } +}