Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P136
(An Untitled Masterwork)
Active
Public
Actions
Authored by
stwalkerster
on Jun 5 2017, 12:20 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Tags
None
Referenced Files
F21201:
Jun 5 2017, 12:20 AM
2017-06-05 00:20:24 (UTC+0)
Subscribers
None
<?php
/******************************************************************************
* Wikipedia Account Creation Assistance tool *
* *
* All code in this file is released into the public domain by the ACC *
* Development Team. Please see team.json for a list of contributors. *
******************************************************************************/
namespace
Waca\ConsoleTasks
;
use
PDO
;
use
Waca\DataObjects\Log
;
use
Waca\DataObjects\User
;
use
Waca\DataObjects\UserRole
;
use
Waca\Tasks\ConsoleTaskBase
;
class
MigrateToRoles
extends
ConsoleTaskBase
{
public
function
execute
()
{
$communityUser
=
User
::
getCommunity
();
$database
=
$this
->
getDatabase
();
$statement
=
$database
->
query
(
'SELECT id, status, checkuser FROM user;'
);
$update
=
$database
->
prepare
(
"UPDATE user SET status = 'Active' WHERE id = :id;"
);
$users
=
$statement
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
foreach
(
$users
as
$user
)
{
$toAdd
=
array
(
'user'
);
if
(
$user
[
'status'
]
===
'Admin'
){
$toAdd
[]
=
'admin'
;
}
if
(
$user
[
'checkuser'
]
==
1
){
$toAdd
[]
=
'checkuser'
;
}
foreach
(
$toAdd
as
$x
)
{
$a
=
new
UserRole
();
$a
->
setUser
(
$user
[
'id'
]);
$a
->
setRole
(
$x
);
$a
->
setDatabase
(
$database
);
$a
->
save
();
}
$logData
=
serialize
(
array
(
'added'
=>
$toAdd
,
'removed'
=>
array
(),
'reason'
=>
'Initial migration'
));
$log
=
new
Log
();
$log
->
setDatabase
(
$database
);
$log
->
setAction
(
'RoleChange'
);
$log
->
setObjectId
(
$user
[
'id'
]);
$log
->
setObjectType
(
'User'
);
$log
->
setUser
(
$communityUser
);
$log
->
setComment
(
$logData
);
$log
->
save
();
if
(
$user
[
'status'
]
===
'Admin'
||
$user
[
'status'
]
===
'User'
){
$update
->
execute
(
array
(
'id'
=>
$user
[
'id'
]));
}
}
$database
->
exec
(
"UPDATE schemaversion SET version = 25;"
);
}
}
Event Timeline
stwalkerster
created this paste.
Jun 5 2017, 12:20 AM
2017-06-05 00:20:24 (UTC+0)
stwalkerster
created this object with visibility "Public (No Login Required)".
Log In to Comment