public function run()
 {
     $bars = [];
     if (BackendAccessControl::checkPermissionAccess(UserController::BACKEND_PERMISSION)) {
         $usersCount = User::find()->where(['status' => User::STATUS_ACTIVE])->count();
         $bars[] = ['bgClass' => 'bg-blue', 'label' => Yii::t('b/radiata/common', 'Total users'), 'data' => $usersCount, 'icon' => 'fa-user', 'url' => Url::to(['user/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(NewsController::BACKEND_PERMISSION)) {
         $newsCount = News::find()->count();
         $bars[] = ['bgClass' => 'bg-olive', 'label' => Yii::t('b/news', 'Total news'), 'data' => $newsCount, 'icon' => 'fa-bars', 'url' => Url::to(['/news/news/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(VoteController::BACKEND_PERMISSION)) {
         $newsCount = Vote::find()->count();
         $bars[] = ['bgClass' => 'bg-aqua', 'label' => Yii::t('b/vote', 'Total votes'), 'data' => $newsCount, 'icon' => 'fa-question-circle', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(BannerController::BACKEND_PERMISSION)) {
         $newsCount = Banner::find()->count();
         $bars[] = ['bgClass' => 'bg-maroon', 'label' => Yii::t('b/banner', 'Total banners'), 'data' => $newsCount, 'icon' => 'fa-flag', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkRoleAccess('developer')) {
         $migrator = new Migrator();
         $migrations = $migrator->findNewMigrations();
         if (count($migrations) > 0) {
             $bars[] = ['bgClass' => 'bg-gold', 'label' => Yii::t('b/radiata/common', 'New migrations'), 'data' => count($migrations), 'icon' => 'fa-database', 'url' => Url::to(['radiata/apply-migrations']), 'more' => Yii::t('b/radiata/common', 'Apply migrations')];
         }
     }
     if (count($bars) > 0) {
         return $this->render('SiteStatsBars', ['bars' => $bars]);
     }
 }
Esempio n. 2
0
 /**
  * Drop table by name (need to manually drop all tables from DB since phpunit clears only data)
  *
  * @param array $tables
  * @throws \yii\base\NotSupportedException
  * @throws \yii\db\Exception
  */
 public function dropTables($tables)
 {
     foreach ($tables as $table) {
         if ($table[0] == '{') {
             $this->migrator->getDbConnection()->createCommand("DROP TABLE IF EXISTS " . $table)->execute();
         } else {
             $this->migrator->getDbConnection()->createCommand("DROP TABLE IF EXISTS " . $this->migrator->getDbConnection()->getSchema()->quoteTableName($table))->execute();
         }
     }
 }
Esempio n. 3
0
 /**
  * Migrations perform
  *
  * @param array $config
  * @return array
  */
 public function migrate($config = [])
 {
     $migrator = new Migrator($config);
     $migrations = $migrator->migrate();
     if (is_object($migrator->error)) {
         return ['error' => $migrator->error->getMessage()];
     } else {
         return ['migrations' => $migrations];
     }
 }
Esempio n. 4
0
 public function actionApplyMigrations()
 {
     if (Yii::$app->request->isAjax) {
         $migrator = new Migrator();
         $migrator->migrate();
         Yii::$app->response->format = Response::FORMAT_JSON;
         $result = [];
         if ($migrator->error) {
             $result['error'] = $migrator->error->getMessage();
         } else {
             $result['success'] = Yii::t('b/radiata/common', 'Migrations were applied successfully');
         }
         return $result;
     }
 }