/**
  * Adds or updates model item in the models storage
  *
  * @param Currency | CurrencyRateProvider $toUpdate
  * @throws InvalidParamException
  * @return bool
  */
 public static function updateStorage($toUpdate)
 {
     if (false === $toUpdate instanceof BaseFileModel) {
         throw new InvalidParamException(Yii::t('dotplant.currencies', 'Method {method} expects instance of {model}. {type} given', ['method' => __METHOD__, 'model' => BaseFileModel::className(), 'type' => gettype($toUpdate)]));
     }
     $current = CurrenciesModule::module()->getData($toUpdate::className(), true, false);
     $current[$toUpdate->name] = $toUpdate->attributes;
     return self::generateStorage($current, $toUpdate->getStorage(), $toUpdate::className());
 }
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     parent::afterDelete();
     $currencies = Currency::findAll();
     /** @var Currency $currency */
     foreach ($currencies as $currency) {
         if ($this->name == $currency->currency_rate_provider_name) {
             $currency->currency_rate_provider_name = null;
             $currency->save();
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (true === parent::beforeSave($insert)) {
         if (1 == $this->is_main) {
             $currencies = self::findAll();
             /** @var self $currency */
             foreach ($currencies as $currency) {
                 if ($this->name == $currency->name) {
                     continue;
                 }
                 $currency->is_main = 0;
                 $currency->save();
             }
         }
     }
     return true;
 }