mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 20:20:41 -05:00
Sync User About Us Text
This commit is contained in:
parent
a3c4fed437
commit
7eed2e6a07
@ -30,6 +30,7 @@ use Illuminate\Support\Facades\Validator;
|
|||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use League\HTMLToMarkdown\HtmlConverter;
|
use League\HTMLToMarkdown\HtmlConverter;
|
||||||
use Stevebauman\Purify\Facades\Purify;
|
use Stevebauman\Purify\Facades\Purify;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
||||||
{
|
{
|
||||||
@ -40,6 +41,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
// Stream some data locally so that we don't have to keep accessing the Hub's database. Use MySQL temporary
|
// Stream some data locally so that we don't have to keep accessing the Hub's database. Use MySQL temporary
|
||||||
// tables to store the data to save on memory; we don't want this to be a hog.
|
// tables to store the data to save on memory; we don't want this to be a hog.
|
||||||
$this->bringUserAvatarLocal();
|
$this->bringUserAvatarLocal();
|
||||||
|
$this->bringUserOptionsLocal();
|
||||||
$this->bringFileAuthorsLocal();
|
$this->bringFileAuthorsLocal();
|
||||||
$this->bringFileOptionsLocal();
|
$this->bringFileOptionsLocal();
|
||||||
$this->bringFileContentLocal();
|
$this->bringFileContentLocal();
|
||||||
@ -98,6 +100,35 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bring the user options table from the Hub database to the local database temporary table.
|
||||||
|
*/
|
||||||
|
private function bringUserOptionsLocal(): void
|
||||||
|
{
|
||||||
|
DB::statement('DROP TEMPORARY TABLE IF EXISTS temp_user_options_values');
|
||||||
|
DB::statement('CREATE TEMPORARY TABLE temp_user_options_values (
|
||||||
|
userID INT,
|
||||||
|
about LONGTEXT
|
||||||
|
) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci');
|
||||||
|
|
||||||
|
DB::connection('mysql_hub')
|
||||||
|
->table('wcf1_user_option_value')
|
||||||
|
->orderBy('userID')
|
||||||
|
->chunk(200, function ($options) {
|
||||||
|
$insertData = [];
|
||||||
|
foreach ($options as $option) {
|
||||||
|
$insertData[] = [
|
||||||
|
'userID' => (int) $option->userID,
|
||||||
|
'about' => $option->userOption1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($insertData) {
|
||||||
|
DB::table('temp_user_options_values')->insert($insertData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bring the file authors from the Hub database to the local database temporary table.
|
* Bring the file authors from the Hub database to the local database temporary table.
|
||||||
*/
|
*/
|
||||||
@ -357,6 +388,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
'name' => $hubUser->username,
|
'name' => $hubUser->username,
|
||||||
'email' => Str::lower($hubUser->email),
|
'email' => Str::lower($hubUser->email),
|
||||||
'password' => $this->cleanPasswordHash($hubUser->password),
|
'password' => $this->cleanPasswordHash($hubUser->password),
|
||||||
|
'about' => $this->fetchUserAbout($hubUser->userID) ?? '',
|
||||||
'profile_photo_path' => $this->fetchUserAvatar($curl, $hubUser),
|
'profile_photo_path' => $this->fetchUserAvatar($curl, $hubUser),
|
||||||
'cover_photo_path' => $this->fetchUserCoverPhoto($curl, $hubUser),
|
'cover_photo_path' => $this->fetchUserCoverPhoto($curl, $hubUser),
|
||||||
'created_at' => $this->cleanRegistrationDate($hubUser->registrationDate),
|
'created_at' => $this->cleanRegistrationDate($hubUser->registrationDate),
|
||||||
@ -377,6 +409,32 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
return str_starts_with($clean, '$2') ? $clean : '';
|
return str_starts_with($clean, '$2') ? $clean : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the user about text from the temporary table.
|
||||||
|
*/
|
||||||
|
private function fetchUserAbout(int $userID): string
|
||||||
|
{
|
||||||
|
$about = DB::table('temp_user_options_values')
|
||||||
|
->where('userID', $userID)
|
||||||
|
->limit(1)
|
||||||
|
->value('about');
|
||||||
|
|
||||||
|
return $this->cleanHubContent($about ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the mod description from WoltHub flavoured HTML to Markdown.
|
||||||
|
*/
|
||||||
|
protected function cleanHubContent(string $dirty): string
|
||||||
|
{
|
||||||
|
// Alright, hear me out... Shut up.
|
||||||
|
|
||||||
|
$converter = new HtmlConverter;
|
||||||
|
$clean = Purify::clean($dirty);
|
||||||
|
|
||||||
|
return $converter->convert($clean) ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the user avatar from the Hub and store it anew.
|
* Fetch the user avatar from the Hub and store it anew.
|
||||||
*/
|
*/
|
||||||
@ -914,19 +972,6 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the mod description from WoltHub flavoured HTML to Markdown.
|
|
||||||
*/
|
|
||||||
protected function cleanHubContent(string $dirty): string
|
|
||||||
{
|
|
||||||
// Alright, hear me out... Shut up.
|
|
||||||
|
|
||||||
$converter = new HtmlConverter;
|
|
||||||
$clean = Purify::clean($dirty);
|
|
||||||
|
|
||||||
return $converter->convert($clean);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the mod thumbnail from the Hub and store it anew.
|
* Fetch the mod thumbnail from the Hub and store it anew.
|
||||||
*/
|
*/
|
||||||
@ -1034,10 +1079,11 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
/**
|
/**
|
||||||
* The job failed to process.
|
* The job failed to process.
|
||||||
*/
|
*/
|
||||||
public function failed(Exception $exception): void
|
public function failed(Throwable $exception): void
|
||||||
{
|
{
|
||||||
// Explicitly drop the temporary tables.
|
// Explicitly drop the temporary tables.
|
||||||
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_user_avatar');
|
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_user_avatar');
|
||||||
|
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_user_options_values');
|
||||||
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_author');
|
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_author');
|
||||||
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_option_values');
|
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_option_values');
|
||||||
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_content');
|
DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_file_content');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user