Typo, clean and use statements

This commit is contained in:
Carlos Ferreira 2017-10-23 03:27:09 +02:00 committed by GitHub
parent 057e7d57ee
commit c6dbb51543

View File

@ -1,12 +1,15 @@
<?php
use yii\db\Schema;
use yii\db\Query;
use yii\db\Expression;
use humhub\components\Migration;
class m160229_162959_multiusergroups extends \humhub\components\Migration
class m160229_162959_multiusergroups extends Migration
{
public function up()
{
$this->createTable('group_user', array(
$this->createTable('group_user', [
'id' => 'pk',
'user_id' => 'int(11) NOT NULL',
'group_id' => 'int(11) NOT NULL',
@ -15,7 +18,7 @@ class m160229_162959_multiusergroups extends \humhub\components\Migration
'created_by' => 'int(11) DEFAULT NULL',
'updated_at' => 'datetime DEFAULT NULL',
'updated_by' => 'int(11) DEFAULT NULL',
), '');
], '');
// Add indexes and foreign keys
$this->createIndex('idx-group_user', 'group_user', ['user_id', 'group_id'], true);
@ -38,24 +41,24 @@ class m160229_162959_multiusergroups extends \humhub\components\Migration
'is_admin_group' => '1',
'show_at_registration' => '0',
'show_at_directory' => '0',
'created_at' => new \yii\db\Expression('NOW()')
'created_at' => new Expression('NOW()')
]);
// Determine administration group id
$adminGroupId = (new \yii\db\Query())
$adminGroupId = (new Query())
->select('id')
->from('group')
->where(['is_admin_group' => '1'])
->scalar();
// Load current super_admin user
$rows = (new \yii\db\Query())
$rows = (new Query())
->select("id")
->from('user')
->where(['super_admin' => '1'])
->all();
//Insert group_user for administartion groups for all current super_admins
// Insert group_user for administration groups for all current super_admins
foreach ($rows as $adminUserRow) {
$this->insertSilent('group_user', ['user_id' => $adminUserRow['id'], 'group_id' => $adminGroupId, 'is_group_admin' => '1']);
}