Closed Aresenka closed 4 years ago
@Aresenka What database are you using?
@darkdef mysql Ver 14.14 Distrib 5.7.30, for Linux (x86_64)
yii migrate
yii migrate --migrationPath=@yii/rbac/migrations
yii my-rbac/init
$userId = 1;
$role = 'admin';
$auth = new DbManager();
$auth->init();
$userRole = $auth->getRole($role);
$auth->assign($userRole, $userId);
Did you do the same?
@darkdef no, insted of my-rbac/init I've used c-rbac/init Is that a fault?
my-rbac/init - it's my test code for create rules (role, permission and etc.) for example from:
$auth = Yii::$app->authManager;
//Create our 4 Roles
$admin = $auth->createRole('admin');
$auth->add($admin);
Yeah, sorry. It works ok: all roles and permissions are created. But when I try to assign any role to any user - it causes error I wrote before.
Please show structure of table auth_assignment
(dump)
And you version of yii?
It's strange, but at fresh installed app it is int type of created_at field of auth_assignment table. Maybe it was an mistake from my side, but now it has been a migration that altered the table, so I can't just dump it to show what is going on. So, if I'll catch that situation again - I'll reopen the issue. Sorry.
What steps will reproduce the problem?
I'm trying to assign role to user with both of these methods: 1)
$userRole = Yii::$app->authManager->getRole($role); Yii::$app->authManager->assign($userRole, $user->getId());
2)$auth = new DbManager(); $auth->init(); $userRole = $auth->getRole($role); $auth->assign($userRole, $user->getId());
What is the expected result?
New line in auth_assignment table, created by default yii migrate --migrationPath=@yii/rbac/migrations console command
What do you get instead?
Error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1593448642' for column 'created_at' at row 1 The SQL being executed was: INSERT INTO
auth_assignment(
user_id,
item_name,
created_at) VALUES (32, 'admin', '1593448642')
Additional info
As I can see, it is
$assignment = new Assignment([ 'userId' => $userId, 'roleName' => $role->name, 'createdAt' => time(), ]);
code in assign method of DbManager class. auth_assignment table described created_at field as timestamp, so it is incorrect to insert integer in timestamp field, isn't it?