<commit_before><?php

namespace app\models\forms;

use Yii;
use yii\base\Model;
use app\models\Store;
use app\models\Option;

class OptionsForm extends Model
{
    public $snowfall_enable;
    public $welcome_popup_enable;
    public $welcome_popup_title;
    public $welcome_popup_content;
    public $add_to_cart_counter_enable;
    public $payment_enable;

    protected $store;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [$this->attributes(), 'safe'],
        ];
    }

    public function attributeLabels()
    {
        return [
            'snowfall_enable' => __('Enable snowfall on storefront'),
            'welcome_popup_enable' => __('Enable welcome popup'),
            'welcome_popup_title' => __('Welcome popup title'),
            'welcome_popup_content' => __('Welcome popup content'),
            'add_to_cart_counter_enable' => __('Enable "add to cart" counter'),
            'payment_enable' => __('Enable payment'),
        ];
    }

    public function init()
    {
        parent::init();

        // Setting default values
        $this->welcome_popup_title = 'Welcome';
        $this->welcome_popup_content = 'Welcome content';
    }

    public function setStore(Store $store)
    {
        $this->store = $store;
        
        $attributes = $this->attributes();
        $options = $store->options;
        foreach ($options as $option) {
            if (in_array($option->name, $attributes)) {
                $this->{$option->name} = $option->value;
            }
        }
    }

    public function saveOptions()
    {
        if ($this->store->id) {
            $options = $this->store->getOptionsByName();

            foreach ($this->attributes() as $attribute) {
                if (!empty($options[$attribute])) {
                    $option = $options[$attribute];
                } else {
                    $option = new Option;
                    $option->link('store', $this->store);
                    $option->name = $attribute;
                }
                $option->value = $this->{$attribute};
                $option->save();
            }

            return true;
        } 
        return false;
    }

}<commit_msg>SQLite IntegrityException was fixed.<commit_after><?php

namespace app\models\forms;

use Yii;
use yii\base\Model;
use app\models\Store;
use app\models\Option;

class OptionsForm extends Model
{
    public $snowfall_enable;
    public $welcome_popup_enable;
    public $welcome_popup_title;
    public $welcome_popup_content;
    public $add_to_cart_counter_enable;
    public $payment_enable;

    protected $store;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [$this->attributes(), 'safe'],
        ];
    }

    public function attributeLabels()
    {
        return [
            'snowfall_enable' => __('Enable snowfall on storefront'),
            'welcome_popup_enable' => __('Enable welcome popup'),
            'welcome_popup_title' => __('Welcome popup title'),
            'welcome_popup_content' => __('Welcome popup content'),
            'add_to_cart_counter_enable' => __('Enable "add to cart" counter'),
            'payment_enable' => __('Enable payment'),
        ];
    }

    public function init()
    {
        parent::init();

        // Setting default values
        $this->welcome_popup_title = 'Welcome';
        $this->welcome_popup_content = 'Welcome content';
    }

    public function setStore(Store $store)
    {
        $this->store = $store;
        
        $attributes = $this->attributes();
        $options = $store->options;
        foreach ($options as $option) {
            if (in_array($option->name, $attributes)) {
                $this->{$option->name} = $option->value;
            }
        }
    }

    public function saveOptions()
    {
        if ($this->store->id) {
            $options = $this->store->getOptionsByName();

            foreach ($this->attributes() as $attribute) {
                if (!empty($options[$attribute])) {
                    $option = $options[$attribute];
                } else {
                    $option = new Option;
                    $option->name = $attribute;
                    $option->link('store', $this->store);
                }
                $option->value = $this->{$attribute};
                $option->save();
            }

            return true;
        } 
        return false;
    }

}
{'fraction_non_alphanumeric': 0.13177257525083613, 'fraction_numerical': 0.0, 'mean_word_length': 1.819610307982401, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '5368169', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1207, 'n_words': 257}