FluxBB\Models\ConfigRepository::save PHP Method

save() public method

public save ( )
    public function save()
    {
        // New and changed keys
        $changed = array_diff_assoc($this->data, $this->original);
        $insertValues = array();
        foreach ($changed as $name => $value) {
            if (!array_key_exists($name, $this->original)) {
                $insertValues[] = array('conf_name' => $name, 'conf_value' => $value);
                unset($changed[$name]);
            }
        }
        if (!empty($insertValues)) {
            $this->database->table('config')->insert($insertValues);
        }
        foreach ($changed as $name => $value) {
            $this->database->table('config')->where('conf_name', '=', $name)->update(array('conf_value' => $value));
        }
        // Deleted keys
        $deletedKeys = array_keys(array_diff_key($this->original, $this->data));
        if (!empty($deletedKeys)) {
            $this->database->table('config')->whereIn('conf_name', $deletedKeys)->delete();
        }
        // No need to cache old values anymore
        $this->original = $this->data;
        // Delete the cache so that it will be regenerated on the next request
        $this->cache->forget('fluxbb.config');
    }