webvimark / user-management

154 stars 163 forks source link

Error migrate m141207_001649_create_basic_user_permissions #135

Closed sallfris closed 8 years ago

sallfris commented 8 years ago

Yii2 version 2.0.9

*\ applying m141207_001649_create_basic_user_permissions Exception: Setting unknown property: yii\rbac\PhpManager::modelClass (D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\Component.php:197)

0 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\BaseYii.php(521): yii\base\Component->__set('modelClass', 'app\models\user...')

1 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\rbac\PhpManager), Array)

2 [internal function]: yii\base\Object->__construct(Array)

3 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\di\Container.php(379): ReflectionClass->newInstanceArgs(Array)

4 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\di\Container.php(154): yii\di\Container->build('yii\rbac\PhpMan...', Array, Array)

5 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\rbac\PhpMan...', Array, Array)

6 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\di\ServiceLocator.php(133): yii\BaseYii::createObject(Array)

7 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\di\ServiceLocator.php(71): yii\di\ServiceLocator->get('authManager')

8 D:\OpenServer\domains\s-san.dev\vendor\webvimark\module-user-management\models\rbacDB\AbstractItem.php(88): yii\di\ServiceLocator->__get('authManager')

9 D:\OpenServer\domains\s-san.dev\vendor\webvimark\module-user-management\migrations\m141207_001649_create_basic_user_permissions.php(65): webvimark\modules\UserManagement\models\rbacDB\AbstractItem::addChildren('assignRolesToUs...', Array)

10 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\db\Migration.php(93): m141207_001649_create_basic_user_permissions->safeUp()

11 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(509): yii\db\Migration->up()

12 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(130): yii\console\controllers\BaseMigrateController->migrateUp('m141207001649...')

13 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)

14 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)

15 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)

16 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\console\Controller.php(119): yii\base\Controller->runAction('', Array)

17 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\Module.php(454): yii\console\Controller->runAction('', Array)

18 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)

19 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)

20 D:\OpenServer\domains\s-san.dev\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))

21 D:\OpenServer\domains\s-san.dev\yii(25): yii\base\Application->run()

22 {main}

*\ failed to apply m141207_001649_create_basic_user_permissions (time: 0.150s)

0 from 1 migrations were applied.

Migration failed. The rest of the migrations are canceled.

szabozoltan69 commented 4 years ago

I had similar problem.

For me the SELECT EXISTS(SELECT * FROM "auth_item" WHERE "name"='viewUserRoles') gives error, so m141207_001649_create_basic_user_permissions.php(58), Permission::create('viewUserRoles', 'View user roles', $group->code); )

Until this the $this->pdoStatement contained the $rawSql and the rowCount, but a few records before the erroneous one this object became empty. I don't know the reason.

I had to get ideas from the mysql.schema.sql. To get date integers:

 select * from auth_item where name='viewUsers';
   name    | type | description | rule_name | data | created_at | updated_at |   group_code
-----------+------+-------------+-----------+------+------------+------------+----------------
 viewUsers |    2 | View users  |           |      | 1583316060 | 1583316060 | userManagement
                                                     ----------   ----------

Then with this:

insert into auth_item (name, type, created_at, updated_at, group_code) values ('viewVisitLog', 2, 'View visit log', 1583316060, 1583316060, 'userManagement');

insert into auth_item (name, type, created_at, updated_at, group_code) values
('/user-management/user-visit-log/*', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/bulk-activate', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/bulk-deactivate', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/bulk-delete', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/create', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/delete', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/grid-page-size', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/grid-sort', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/index', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/toggle-attribute', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/update', 3, 1583316060, 1583316060, NULL),
('/user-management/user-visit-log/view', 3, 1583316060, 1583316060, NULL);

 insert into auth_item_child (parent, child) values 
('viewVisitLog', '/user-management/user-visit-log/grid-page-size'),
('viewVisitLog', '/user-management/user-visit-log/index'),
('viewVisitLog', '/user-management/user-visit-log/view');
unrealmach commented 3 years ago

I think that for some reason the ORM is freezing the transaction with each entry of authitemgroup and its children.

I fix the error: 1.- customizing migrations, copying from the vendor, and placing them in a directory in my project.

  1. spliting the problematic migration (create_basic_user_permission) in each authitemgroup having in total 3 files. So far it works fine in PostgreSQL