-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/future_event
- Loading branch information
Showing
14 changed files
with
320 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,75 @@ | ||
#!/bin/sh | ||
# exit on error | ||
# Exit on error. | ||
set -e | ||
|
||
printf "\n⏳ composer lint\n" | ||
vendor/bin/pint --test | ||
# Checks if files matching a pattern have changed. | ||
check_changed_files() { | ||
# Get the list of changed files between current branch and master. | ||
changed_files=$(git diff --name-only master...HEAD) | ||
|
||
# Check each pattern against the changed files. | ||
for pattern in "$@"; do | ||
if echo "$changed_files" | grep -q "$pattern"; then | ||
return 0 # Found a match. | ||
fi | ||
done | ||
|
||
return 1 # No matches found. | ||
} | ||
|
||
printf "\n⏳ composer analyse\n" | ||
vendor/bin/phpstan analyse --memory-limit 768M | ||
is_php_changed=false | ||
is_node_changed=false | ||
|
||
printf "\n⏳ pnpm lint:eslint\n" | ||
pnpm lint:eslint | ||
# Check for PHP changes. | ||
if check_changed_files "\.php$" "composer\.json$" "composer\.lock$" "phpstan\.neon$" "pint\.json$"; then | ||
is_php_changed=true | ||
fi | ||
|
||
printf "\n⏳ pnpm tsc\n" | ||
pnpm tsc | ||
# Check for Node.js changes. | ||
if check_changed_files "\.js$" "\.ts$" "\.tsx$" "package\.json$" "pnpm-lock\.yaml$" "eslint" "tailwind\.config\.json$" "lang/.*\.json$"; then | ||
is_node_changed=true | ||
fi | ||
|
||
printf "\n⏳ pnpm test\n" | ||
pnpm test | ||
# If no relevant changes detected, exit early. | ||
if [ "$is_php_changed" = false ] && [ "$is_node_changed" = false ]; then | ||
printf "\n✅ No PHP or Node.js changes detected. Skipping checks.\n\n" | ||
exit 0 | ||
fi | ||
|
||
# Run PHP checks if needed. | ||
if [ "$is_php_changed" = true ]; then | ||
printf "\n🔍 PHP changes detected. Running PHP checks...\n" | ||
|
||
printf "\n⏳ composer lint\n" | ||
vendor/bin/pint --test | ||
|
||
printf "\n⏳ composer analyse\n" | ||
vendor/bin/phpstan analyse --memory-limit 768M | ||
|
||
# Check the OS. Windows does not support the --parallel flag. | ||
if [ "$(uname)" = "Linux" ] || [ "$(uname)" = "Darwin" ]; then | ||
# Use --parallel if macOS or Linux are detected. | ||
printf "\n⏳ composer test -- --parallel\n" | ||
vendor/bin/paratest | ||
else | ||
# If neither of those are detected, don't use --parallel. | ||
printf "\n⏳ composer test\n" | ||
vendor/bin/phpunit | ||
fi | ||
fi | ||
|
||
# Check the OS. Windows does not support the --parallel flag. | ||
if [ "$(uname)" = "Linux" ] || [ "$(uname)" = "Darwin" ]; then | ||
# Use --parallel if macOS or Linux are detected. | ||
printf "\n⏳ composer test -- --parallel\n" | ||
vendor/bin/paratest | ||
else | ||
# If neither of those are detected, don't use --parallel. | ||
printf "\n⏳ composer test\n" | ||
vendor/bin/phpunit | ||
# Run Node.js checks if needed. | ||
if [ "$is_node_changed" = true ]; then | ||
printf "\n🔍 Node.js changes detected. Running Node.js checks...\n" | ||
|
||
printf "\n⏳ pnpm lint:eslint\n" | ||
pnpm lint:eslint | ||
|
||
printf "\n⏳ pnpm tsc\n" | ||
pnpm tsc | ||
|
||
printf "\n⏳ pnpm test\n" | ||
pnpm test | ||
fi | ||
|
||
printf "\n✅ pre-push OK\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Community\Actions; | ||
|
||
use App\Models\User; | ||
use Carbon\Carbon; | ||
|
||
class BuildDisplayNameHistoryAction | ||
{ | ||
public function execute(User $user): string | ||
{ | ||
// Get all approved display_name changes in reverse chronological order. | ||
$allChanges = $user->usernameRequests() | ||
->approved() | ||
->orderBy('approved_at', 'desc') | ||
->get(); | ||
|
||
// If there are no changes and display_name matches the username, return an empty string. | ||
if ($allChanges->isEmpty() && $user->display_name === $user->username) { | ||
return ''; | ||
} | ||
|
||
$entries = collect(); | ||
|
||
// Add current display_name if it came from a change request. | ||
if ($user->display_name === $user->username) { | ||
$entries->push($this->formatEntry($user->display_name, $user->created_at)); | ||
} elseif ($currentChange = $allChanges->firstWhere('username', $user->display_name)) { | ||
$entries->push($this->formatEntry($user->display_name, $currentChange->approved_at)); | ||
} | ||
|
||
// Add all previous display_name changes. | ||
$allChanges->reject(fn ($change) => $change->username === $user->display_name) | ||
->each(fn ($change) => $entries->push($this->formatEntry($change->username, $change->approved_at))); | ||
|
||
// Add their original username if it's different from their current display_name and not already included. | ||
if ($user->username !== $user->display_name && !$allChanges->contains('username', $user->username)) { | ||
$entries->push($this->formatEntry($user->username, $user->created_at)); | ||
} | ||
|
||
return $entries->join("\n"); | ||
} | ||
|
||
private function formatEntry(string $username, Carbon $date): string | ||
{ | ||
return $username . ' (' . $date->format('F j, Y') . ')'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Community\Commands; | ||
|
||
use App\Models\User; | ||
use DB; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Str; | ||
|
||
class SyncUserUlids extends Command | ||
{ | ||
protected $signature = 'ra:sync:user-ulids'; | ||
|
||
protected $description = 'Sync user ulid field values'; | ||
|
||
public function handle(): void | ||
{ | ||
$total = User::whereNull('ulid')->count(); | ||
|
||
if ($total === 0) { | ||
$this->info('No records need ULIDs.'); | ||
|
||
return; | ||
} | ||
|
||
$progressBar = $this->output->createProgressBar($total); | ||
$progressBar->start(); | ||
|
||
User::withTrashed() | ||
->whereNull('ulid') | ||
->chunkById(4000, function ($users) use ($progressBar) { | ||
$updates = []; | ||
$milliseconds = 0; | ||
|
||
/** @var User $user */ | ||
foreach ($users as $user) { | ||
$milliseconds += rand(1, 20); | ||
$milliseconds %= 1000; | ||
|
||
$timestamp = $user->Created->clone()->addMilliseconds($milliseconds); | ||
$ulid = (string) Str::ulid($timestamp); | ||
|
||
$updates[] = [ | ||
'ID' => $user->id, | ||
'ulid' => $ulid, | ||
]; | ||
} | ||
|
||
// Perform a batch update for speed. | ||
DB::table('UserAccounts') | ||
->upsert( | ||
$updates, | ||
['ID'], | ||
['ulid'] | ||
); | ||
|
||
$progressBar->advance(count($updates)); | ||
}); | ||
|
||
$progressBar->finish(); | ||
|
||
$this->newLine(); | ||
$this->info('Done.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
database/migrations/2025_01_26_000000_update_useraccounts_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::table('UserAccounts', function (Blueprint $table) { | ||
$table->ulid('ulid')->after('ID')->unique()->nullable(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::table('UserAccounts', function (Blueprint $table) { | ||
$table->dropColumn('ulid'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.