<commit_before><?php

namespace Milax\Mconsole\API;

use Milax\Mconsole\Contracts\API\RepositoryAPI;
use Milax\Mconsole\Contracts\DataManager;

class Options extends RepositoryAPI implements DataManager
{
    
    public $model = \Milax\Mconsole\Models\MconsoleOption::class;
    
    /**
     * Get option value by its key
     * 
     * @param  string $key
     * @return mixed
     */
    public function getByKey($key)
    {
        $model = $this->model;
        return $model::getByKey($key);
    }
    
    /**
     * Store a new option value by key
     * 
     * @param  string $key
     * @param  string $value
     * @return mixed
     */
    public function setByKey($key, $value)
    {
        $model = $this->model;
        return $model::where('key', $key)->update([
            'value' => $value,
        ]);
    }
    
    /**
     * Create or update options
     *
     * @param array $options [Options array]
     * @return void
     */
    public function install($options)
    {
        $model = $this->model;
        
        $this->uninstall($options);
        
        foreach ($options as $key => $option) {
            foreach ($option as $col => $val) {
                if (is_array($val)) {
                    $option[$col] = json_encode($val);
                }
            }
            $option['created_at'] = date('Y-m-d H:i:s');
            $option['updated_at'] = date('Y-m-d H:i:s');
            $options[$key] = $option;
        }
        
        $model::insert($options);
        $model::dropCache();
    }
        
    /**
     * Remove options from database
     *
     * @param array $options [Options array]
     * @return void
     */
    public function uninstall($options)
    {
        $model = $this->model;
        $model::whereIn('key', collect($options)->lists('key'))->delete();
        $model::dropCache();
    }
}
<commit_msg>Fix options cache after saving new values<commit_after><?php

namespace Milax\Mconsole\API;

use Milax\Mconsole\Contracts\API\RepositoryAPI;
use Milax\Mconsole\Contracts\DataManager;

class Options extends RepositoryAPI implements DataManager
{
    
    public $model = \Milax\Mconsole\Models\MconsoleOption::class;
    
    /**
     * Get option value by its key
     * 
     * @param  string $key
     * @return mixed
     */
    public function getByKey($key)
    {
        $model = $this->model;
        return $model::getByKey($key);
    }
    
    /**
     * Store a new option value by key
     * 
     * @param  string $key
     * @param  string $value
     * @return mixed
     */
    public function setByKey($key, $value)
    {
        $model = $this->model;
        $result = $model::where('key', $key)->update([
            'value' => $value,
        ]);
        $model::dropCache();
        return $result;
    }
    
    /**
     * Create or update options
     *
     * @param array $options [Options array]
     * @return void
     */
    public function install($options)
    {
        $model = $this->model;
        
        $this->uninstall($options);
        
        foreach ($options as $key => $option) {
            foreach ($option as $col => $val) {
                if (is_array($val)) {
                    $option[$col] = json_encode($val);
                }
            }
            $option['created_at'] = date('Y-m-d H:i:s');
            $option['updated_at'] = date('Y-m-d H:i:s');
            $options[$key] = $option;
        }
        
        $model::insert($options);
        $model::dropCache();
    }
        
    /**
     * Remove options from database
     *
     * @param array $options [Options array]
     * @return void
     */
    public function uninstall($options)
    {
        $model = $this->model;
        $model::whereIn('key', collect($options)->lists('key'))->delete();
        $model::dropCache();
    }
}

{'fraction_non_alphanumeric': 0.14672216441207075, 'fraction_numerical': 0.0, 'mean_word_length': 1.772170151405912, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3291999', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1152, 'n_words': 249}