mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
* Create StyleCI config file * Disable `phpdoc_separation` * Apply fixes from StyleCI (#3476) Co-authored-by: StyleCI Bot <bot@styleci.io> * style: styleci fixes --------- Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Sam <samerton@users.noreply.github.com>
42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
class MinecraftPlaceholderDataSeeder extends Seeder
|
|
{
|
|
public array $tables = [
|
|
'nl2_users_placeholders',
|
|
];
|
|
|
|
protected function run(DB $db, \Faker\Generator $faker): void
|
|
{
|
|
$placeholders = $db->get('placeholders_settings', ['server_id', '<>', 0])->results();
|
|
$users = $db->get('users', ['id', '<>', 0])->results();
|
|
$saved = [];
|
|
$user_uuids = [];
|
|
|
|
$this->times(1000, function () use ($db, $faker, $placeholders, $users, &$saved, &$user_uuids) {
|
|
$placeholder = $faker->randomElement($placeholders);
|
|
$user = $faker->randomElement($users);
|
|
|
|
if (!array_key_exists($user->id, $user_uuids)) {
|
|
$uuid = hex2bin($db->query('SELECT identifier FROM nl2_users_integrations WHERE user_id = ?', [$user->id])->first()->identifier);
|
|
$user_uuids[$user->id] = $uuid;
|
|
} else {
|
|
$uuid = $user_uuids[$user->id];
|
|
}
|
|
|
|
if (in_array($placeholder->server_id.$uuid.$placeholder->name, $saved)) {
|
|
return;
|
|
}
|
|
|
|
$db->insert('users_placeholders', [
|
|
'server_id' => $placeholder->server_id,
|
|
'uuid' => $uuid,
|
|
'name' => $placeholder->name,
|
|
'value' => $faker->numberBetween(0, 1000),
|
|
'last_updated' => $this->since($user->joined, $faker)->format('U'),
|
|
]);
|
|
|
|
$saved[] = $placeholder->server_id.$uuid.$placeholder->name;
|
|
});
|
|
}
|
|
}
|