예제 #1
0
 public function save()
 {
     if ($this->validate()) {
         $container = new \yii\di\Container();
         $config = (require MultisiteHelper::getDbConfig(Yii::getAlias('@app/config/'), $this->domain));
         $container->set('db', $config);
         $configCopy = (require MultisiteHelper::getDbConfig(Yii::getAlias('@app/config/'), $this->domainCopy));
         $container->set('dbCopy', $configCopy);
         /** @var Connection $db */
         $db = $container->get('db');
         /** @var Connection $dbCopy */
         $dbCopy = $container->get('dbCopy');
         $transaction = $db->beginTransaction();
         try {
             // rename tables if database not empty
             $tables = $db->createCommand('SHOW TABLES')->queryAll(PDO::FETCH_COLUMN);
             $key = rand(1, 100000);
             foreach ($tables as $table) {
                 $db->createCommand('RENAME TABLE ' . $table . ' TO ' . $key . '_' . $table)->query();
             }
             $tables = $dbCopy->createCommand('SHOW TABLES')->queryAll(PDO::FETCH_COLUMN);
             foreach ($tables as $table) {
                 $sql = 'CREATE TABLE ' . $this->getDatabase($config['dsn']) . '.' . $table . ' LIKE  ' . $this->getDatabase($configCopy['dsn']) . '.' . $table;
                 $dbCopy->createCommand($sql)->query();
                 $sql = 'INSERT INTO ' . $this->getDatabase($config['dsn']) . '.' . $table . ' SELECT * FROM ' . $this->getDatabase($configCopy['dsn']) . '.' . $table;
                 $dbCopy->createCommand($sql)->query();
             }
             $transaction->commit();
             return true;
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
     }
     return false;
 }
예제 #2
0
 public function delete()
 {
     return \yii\easyii\helpers\Multisite::deleteDomain($this->domain);
 }
예제 #3
0
<?php

$params = (require __DIR__ . '/params.php');
$basePath = dirname(__DIR__);
$webroot = dirname($basePath);
$config = ['id' => 'app', 'basePath' => $basePath, 'bootstrap' => ['log'], 'language' => 'en-US', 'runtimePath' => $webroot . '/runtime', 'vendorPath' => $webroot . '/vendor', 'components' => ['request' => ['cookieValidationKey' => ''], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'errorHandler' => ['errorAction' => 'site/error'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer'], 'assetManager' => ['bundles' => ['yii\\web\\JqueryAsset' => ['js' => [YII_DEBUG ? 'jquery.js' : 'jquery.min.js']], 'yii\\bootstrap\\BootstrapAsset' => ['css' => [YII_DEBUG ? 'css/bootstrap.css' : 'css/bootstrap.min.css']], 'yii\\bootstrap\\BootstrapPluginAsset' => ['js' => [YII_DEBUG ? 'js/bootstrap.js' : 'js/bootstrap.min.js']]]], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => require \yii\easyii\helpers\Multisite::getDbConfig(__DIR__), 'view' => require \yii\easyii\helpers\Multisite::getThemeConfig(__DIR__)], 'params' => $params];
if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\\debug\\Module';
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\\gii\\Module';
    $config['components']['db']['enableSchemaCache'] = false;
}
return array_merge_recursive($config, require dirname(__FILE__) . '/../../vendor/vitalik74/easyii/config/easyii.php');
예제 #4
0
파일: main.php 프로젝트: vitalik74/easyii
echo $asset->baseUrl;
?>
/img/logo_20.png">
                    EasyiiCMS
                </div>
                <div class="nav">
                    <a href="<?php 
echo Url::to(['/']);
?>
" class="pull-left"><i class="glyphicon glyphicon-home"></i> <?php 
echo Yii::t('easyii', 'Open site');
?>
</a>
                    <div class="pull-left nav-multisite">
                        <?php 
echo Html::dropDownList('', \yii\easyii\helpers\Multisite::getDomainFromCookie(), ArrayHelper::map(\yii\easyii\helpers\Multisite::getDomains(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => Yii::t('easyii', 'Select site'), 'onChange' => 'location.href = "/admin/default/change-site?domain=" + this.value']);
?>
                    </div>

                    <a href="<?php 
echo Url::to(['/admin/sign/out']);
?>
" class="pull-right"><i class="glyphicon glyphicon-log-out"></i> <?php 
echo Yii::t('easyii', 'Logout');
?>
</a>

                </div>
            </div>
            <div class="main">
                <div class="box sidebar">
예제 #5
0
파일: _form.php 프로젝트: vitalik74/easyii
<?php

use yii\easyii\widgets\DateTimePicker;
use yii\easyii\helpers\Image;
use yii\easyii\widgets\TagsInput;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\easyii\widgets\Redactor;
use yii\easyii\widgets\SeoForm;
$module = $this->context->module->id;
$form = ActiveForm::begin(['enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']]);
?>

<?php 
echo $form->field($model, 'domain')->dropDownList(ArrayHelper::map(\yii\easyii\helpers\Multisite::getDomains(), 'domain', 'domain'), ['prompt' => Yii::t('easyii/multisite', 'Select site')]);
?>

<?php 
echo $form->field($model, 'domainCopy')->dropDownList(ArrayHelper::map(\yii\easyii\helpers\Multisite::getDomains(), 'domain', 'domain'), ['prompt' => Yii::t('easyii/multisite', 'Select site')]);
?>

<?php 
echo Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']);
?>

<?php 
ActiveForm::end();