/**
* Update a specific piece of metadata.
*
* @param int $id ID of the metadata to update
* @param string $name Metadata name
* @param string $value Metadata value
* @param string $value_type Value type
* @param int $owner_guid Owner guid
* @param int $access_id Access ID
*
* @return bool
*/
function update($id, $name, $value, $value_type, $owner_guid, $access_id)
{
$id = (int) $id;
if (!($md = $this->get($id))) {
return false;
}
if (!$md->canEdit()) {
return false;
}
$value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
$owner_guid = (int) $owner_guid;
if ($owner_guid == 0) {
$owner_guid = $this->session->getLoggedInUserGuid();
}
$access_id = (int) $access_id;
// Support boolean types (as integers)
if (is_bool($value)) {
$value = (int) $value;
}
// If ok then add it
$query = "UPDATE {$this->table}\n\t\t\tSET name = :name,\n\t\t\t value = :value,\n\t\t\t\tvalue_type = :value_type,\n\t\t\t\taccess_id = :access_id,\n\t\t\t owner_guid = :owner_guid\n\t\t\tWHERE id = :id";
$result = $this->db->updateData($query, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':id' => $id]);
if ($result !== false) {
$this->cache->clear($md->entity_guid);
// @todo this event tells you the metadata has been updated, but does not
// let you do anything about it. What is needed is a plugin hook before
// the update that passes old and new values.
$obj = $this->get($id);
$this->events->trigger('update', 'metadata', $obj);
}
return $result;
}