public function up() { // Creates the default platform config /** @var \gromver\platform\console\modules\main\Module $main */ $cmf = Yii::$app->grom; $paramsPath = Yii::getAlias($cmf->paramsPath); $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php'; $params = $cmf->params; $model = new \gromver\models\ObjectModel(\gromver\platform\common\models\PlatformParams::className()); $model->setAttributes($params); echo 'Setup application config: ' . PHP_EOL; $this->readStdinUser('Site Name (My Site)', $model, 'siteName', 'My Site'); $this->readStdinUser('Admin Email (admin@email.com)', $model, 'adminEmail', '*****@*****.**'); $this->readStdinUser('Support Email (support@email.com)', $model, 'supportEmail', '*****@*****.**'); $this->readStdinUser('Elasticsearch Index', $model, 'elasticsearchIndex'); if ($model->validate()) { \yii\helpers\FileHelper::createDirectory($paramsPath); file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';'); @chmod($paramsFile, 0777); } echo 'Setup complete.' . PHP_EOL; }
public function actionParams($modal = null) { $paramsPath = Yii::getAlias($this->module->paramsPath); $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php'; $params = $this->module->params; $model = new ObjectModel(PlatformParams::className()); $model->setAttributes($params); if ($model->load(Yii::$app->request->post())) { if ($model->validate() && Yii::$app->request->getBodyParam('task') !== 'refresh') { FileHelper::createDirectory($paramsPath); file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';'); @chmod($paramsFile, 0777); Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Configuration saved.')); if ($modal) { ModalIFrame::refreshPage(); } } } if ($modal) { $this->layout = 'modal'; } return $this->render('params', ['model' => $model]); }