/**
* Add or update a config setting.
*
* Plugin authors should use elgg_set_config().
*
* If the config name already exists, it will be updated to the new value.
*
* @note Internal: These settings are stored in the dbprefix_config table and read
* during system boot into $CONFIG.
*
* @note Internal: The value is serialized so we maintain type information.
*
* @param string $name The name of the configuration value
* @param mixed $value Its value
*
* @return bool
*/
function set($name, $value)
{
$name = trim($name);
// cannot store anything longer than 255 characters in db, so catch before we set
if (elgg_strlen($name) > 255) {
$this->logger->error("The name length for configuration variables cannot be greater than 255");
return false;
}
$this->CONFIG->{$name} = $value;
$dbprefix = $this->CONFIG->dbprefix;
$sql = "\n\t\t\tINSERT INTO {$dbprefix}config\n\t\t\tSET name = :name,\n\t\t\t\tvalue = :value\n\t\t\tON DUPLICATE KEY UPDATE value = :value\n\t\t";
$params = [':name' => $name, ':value' => serialize($value)];
$version = (int) $this->CONFIG->version;
if (!empty($version) && $version < 2016102500) {
// need to do this the old way as long as site_guid columns have not been dropped
$sql = "\n\t\t\t\tINSERT INTO {$dbprefix}config\n\t\t\t\tSET name = :name,\n\t\t\t\t\tvalue = :value,\n\t\t\t\t\tsite_guid = :site_guid\n\t\t\t\tON DUPLICATE KEY UPDATE value = :value\n\t\t\t";
$params[':site_guid'] = 1;
}
$result = $this->db->insertData($sql, $params);
$this->boot->invalidateCache();
return $result !== false;
}