You are here

public function UltimateCronDatabaseLogger::settingsForm in Ultimate Cron 7.2

Settings form.

Overrides UltimateCronPlugin::settingsForm

File

plugins/ultimate_cron/logger/database.class.php, line 152
Database logger for Ultimate Cron.

Class

UltimateCronDatabaseLogger
Class for using database as log storage.

Code

public function settingsForm(&$form, &$form_state, $job = NULL) {
  $elements =& $form['settings'][$this->type][$this->name];
  $defaults =& $form_state['default_values']['settings'][$this->type][$this->name];
  $values =& $form_state['values']['settings'][$this->type][$this->name];
  $elements['method'] = array(
    '#type' => 'select',
    '#title' => t('Log entry cleanup method'),
    '#description' => t('Select which method to use for cleaning up logs.'),
    '#options' => $this->options['method'],
    '#default_value' => $values['method'],
    '#fallback' => TRUE,
    '#required' => TRUE,
  );
  $states = array(
    'expire' => array(),
    'retain' => array(),
  );
  if ($job) {
    $states['expire'] = array(
      '#states' => array(
        'visible' => array(
          ':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]' => array(
            'value' => ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_EXPIRE,
          ),
        ),
        'enabled' => array(
          ':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]' => array(
            'value' => ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_EXPIRE,
          ),
        ),
      ),
    );
    $states['retain'] = array(
      '#states' => array(
        'visible' => array(
          ':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]' => array(
            'value' => ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_RETAIN,
          ),
        ),
        'enabled' => array(
          ':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]' => array(
            'value' => ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_RETAIN,
          ),
        ),
      ),
    );
  }
  $elements['method_expire'] = array(
    '#type' => 'fieldset',
    '#title' => t('Remove logs older than a specified age'),
  ) + $states['expire'];
  $elements['method_expire']['expire'] = array(
    '#parents' => array(
      'settings',
      $this->type,
      $this->name,
      'expire',
    ),
    '#type' => 'textfield',
    '#title' => t('Log entry expiration'),
    '#description' => t('Remove log entries older than X seconds.'),
    '#default_value' => $values['expire'],
    '#fallback' => TRUE,
    '#required' => TRUE,
  ) + $states['expire'];
  $elements['method_retain'] = array(
    '#type' => 'fieldset',
    '#title' => t('Retain only a specific amount of log entries'),
  ) + $states['retain'];
  $elements['method_retain']['retain'] = array(
    '#parents' => array(
      'settings',
      $this->type,
      $this->name,
      'retain',
    ),
    '#type' => 'textfield',
    '#title' => t('Retain logs'),
    '#description' => t('Retain X amount of log entries; this value is per cron job. Setting this to 1000 on sites with 15 cron jobs will store a total of 15000 entries. High values can result in slower log performance.'),
    '#default_value' => $values['retain'],
    '#fallback' => TRUE,
    '#required' => TRUE,
  ) + $states['retain'];
  if ($job) {
    if ($defaults['method'] == ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_EXPIRE) {
      $elements['method_default'] = $elements['method_expire'];
      $elements['method_default']['#states']['visible'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['#states']['enabled'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['expire']['#states']['visible'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['expire']['#states']['enabled'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
    }
    if ($defaults['method'] == ULTIMATE_CRON_DATABASE_LOGGER_CLEANUP_METHOD_RETAIN) {
      $elements['method_default'] = $elements['method_retain'];
      $elements['method_default']['#states']['visible'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['#states']['enabled'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['retain']['#states']['visible'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
      $elements['method_default']['retain']['#states']['enabled'][':input[name="settings[' . $this->type . '][' . $this->name . '][method]"]']['value'] = '';
    }
  }
}