Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F21201
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Authored By
stwalkerster
Jun 5 2017, 12:20 AM
2017-06-05 00:20:24 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
<?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;"
);
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
19408
Default Alt Text
(2 KB)
Attached To
Mode
P136 (An Untitled Masterwork)
Attached
Detach File
Event Timeline
Log In to Comment