You are here

public function SearchApiSavedSearch::save in Search API Saved Searches 7

Permanently saves the entity.

Overrides Entity::save

See also

entity_save()

File

./search_api_saved_searches.search_entity.inc, line 119
Contains the entity class for saved searches.

Class

SearchApiSavedSearch
Class representing "Saved searches" settings.

Code

public function save() {
  $settings = $this
    ->settings();
  if (!$this->enabled && empty($this->options['key']) || !empty($settings->options['registered_user_delete_key'])) {
    $this->options['key'] = drupal_hash_base64(drupal_random_bytes(12));
  }
  $date_field = isset($settings->options['date_field']) ? $settings->options['date_field'] : NULL;
  if ($this->enabled && !isset($this->results) && !$date_field) {
    $results = array();
    $response = $this
      ->query()
      ->execute();
    $this->results = implode(',', array_keys($response['results']));
  }
  $ret = parent::save();
  if ($ret == SAVED_NEW && !$this->enabled) {
    $params = array(
      'user' => user_load($this->uid),
      'search' => $this,
    );
    drupal_mail('search_api_saved_searches', 'activate', $this->mail, user_preferred_language($params['user']), $params);
  }
  return $ret;
}