You are here

public function SearchApiIndex::update in Search API 7

Helper method for updating entity properties.

NOTE: You shouldn't change any properties of this object before calling this method, as this might lead to the fields not being saved correctly.

Parameters

array $fields: The new field values.

Return value

int|false SAVE_UPDATED on success, FALSE on failure, 0 if the fields already had the specified values.

File

includes/index_entity.inc, line 292
Contains SearchApiIndex.

Class

SearchApiIndex
Class representing a search index.

Code

public function update(array $fields) {
  $changeable = array(
    'name' => 1,
    'enabled' => 1,
    'description' => 1,
    'server' => 1,
    'options' => 1,
    'read_only' => 1,
  );
  $changed = FALSE;
  foreach ($fields as $field => $value) {
    if (isset($changeable[$field]) && $value !== $this->{$field}) {
      $this->{$field} = $value;
      $changed = TRUE;
    }
  }

  // If there are no new values, just return 0.
  if (!$changed) {
    return 0;
  }

  // Reset the index's internal property cache to correctly incorporate new
  // settings.
  $this
    ->resetCaches();
  return $this
    ->save();
}