2018-02-11 14:52:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Setup script
|
|
|
|
* @todo Move this into a CLI commands system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
use Misuzu\Database;
|
2018-02-11 14:52:28 +00:00
|
|
|
|
|
|
|
require_once __DIR__ . '/misuzu.php';
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$db = Database::connection();
|
2018-02-11 14:52:28 +00:00
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$mainRoleId = (int)$db->query('
|
|
|
|
SELECT `role_id`
|
|
|
|
FROM `msz_roles`
|
|
|
|
WHERE `role_id` = 1
|
|
|
|
')->fetchColumn();
|
|
|
|
|
|
|
|
if ($mainRoleId !== 1) {
|
|
|
|
$db->query("
|
|
|
|
REPLACE INTO `msz_roles`
|
|
|
|
(`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `created_at`)
|
|
|
|
VALUES
|
|
|
|
(1, 'Member', 1, 1073741824, NULL, NOW())
|
|
|
|
");
|
|
|
|
|
|
|
|
$mainRoleId = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$notInMainRole = $db->query('
|
|
|
|
SELECT `user_id`
|
|
|
|
FROM `msz_users` as u
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM `msz_user_roles` as ur
|
|
|
|
WHERE `role_id` = 1
|
|
|
|
AND u.`user_id` = ur.`user_id`
|
|
|
|
)
|
|
|
|
')->fetchAll();
|
|
|
|
|
|
|
|
if (count($notInMainRole) < 1) {
|
|
|
|
exit;
|
2018-02-11 14:52:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
$addToMainRole = $db->prepare('
|
|
|
|
INSERT INTO `msz_user_roles`
|
|
|
|
(`user_id`, `role_id`)
|
|
|
|
VALUES
|
|
|
|
(:user_id, 1)
|
|
|
|
');
|
|
|
|
|
|
|
|
foreach ($notInMainRole as $user) {
|
|
|
|
$addToMainRole->execute($user);
|
2018-02-11 14:52:28 +00:00
|
|
|
}
|