public function SearchApiServer::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/
server_entity.inc, line 94 - Contains SearchApiServer.
Class
- SearchApiServer
- Class representing a search server.
Code
public function update(array $fields) {
$changeable = array(
'name' => 1,
'enabled' => 1,
'description' => 1,
'options' => 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;
}
return $this
->save();
}