You are here

function encrypt_save_config in Encrypt 7.3

Same name and namespace in other branches
  1. 7.2 encrypt.module \encrypt_save_config()

Save a configuration.

Parameters

array $fields: The fields of the configuration to save.

bool $messages: TRUE if messages should be displayed.

2 calls to encrypt_save_config()
encrypt_config_features_rebuild in includes/encrypt.features.inc
Implements hook_features_rebuild().
encrypt_config_form_submit in includes/encrypt.admin.inc
Form submission handler for encrypt_config_form().

File

./encrypt.module, line 345
Main Encrypt Drupal File

Code

function encrypt_save_config($fields, $messages = TRUE) {

  // Serialize any field that is an array.
  foreach ($fields as $key => $field) {
    if (is_array($field)) {
      $fields[$key] = serialize($field);
    }
  }

  // If the created field is empty, set it to the request time.
  if (empty($fields['created'])) {
    $fields['created'] = REQUEST_TIME;
  }

  // If the changed field is empty, set it to the request time.
  if (empty($fields['changed'])) {
    $fields['changed'] = REQUEST_TIME;
  }

  // Save the configuration.
  $merge_status = db_merge('encrypt_config')
    ->key(array(
    'name' => $fields['name'],
  ))
    ->fields($fields)
    ->execute();

  // Display message and log to watchdog.
  if ($messages) {
    $t_args = array(
      '%label' => $fields['label'],
    );
    switch ($merge_status) {
      case MergeQuery::STATUS_INSERT:
        drupal_set_message(t('The configuration %label has been added.', $t_args));
        watchdog('encrypt', 'Added encryption configuration %label.', $t_args, WATCHDOG_NOTICE, l(t('view'), ENCRYPT_MENU_PATH . '/list'));
        break;
      case MergeQuery::STATUS_UPDATE:
        drupal_set_message(t('The configuration %label has been updated.', $t_args));
        watchdog('encrypt', 'Updated encryption configuration %label.', $t_args, WATCHDOG_NOTICE, l(t('view'), ENCRYPT_MENU_PATH . '/list'));
        break;
    }
  }
}