public static function updateConfigurables() { Yii::$app->set('db', Yii::createObject(InstallerHelper::createDatabaseConfig(Yii::$app->session->get('db-config')))); Yii::$app->db->open(); $conf = Configurable::find()->all(); return ConfigurationUpdater::updateConfiguration($conf, false); }
/** * Lists configurables by tabs and saves configuration * @return string * @throws \Exception * @throws \yii\web\ServerErrorHttpException */ public function actionIndex() { /** @var Configurable[] $models */ $models = Configurable::getDb()->cache(function ($db) { return Configurable::find()->orderBy(['sort_order' => SORT_ASC])->all($db); }, 86400, new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Configurable::className())])); foreach ($models as $model) { $configurableModel = $model->getConfigurableModel(); $configurableModel->loadState(); } if (Yii::$app->request->isPost === true) { if (ConfigurationUpdater::updateConfiguration($models, true)) { return $this->refresh(); } } return $this->render('index', ['models' => $models]); }
/** * Remove module configuration from config files. */ public function removeConfig() { if ($this->getBehavior('configurableModule') !== null) { // This extension has config behavior // Find corresponding configurable $configurables = Configurable::find()->where('module!=:module', [':module' => $this->id])->all(); if ($configurables !== null) { // The trick is to use previous saved values from other configurables // and exclude current module from configuration // that is done by setting not to load existing configuration ConfigurationUpdater::updateConfiguration($configurables, false, false); } } \yii\caching\TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag(Configurable::className())]); }