Skip to content

Commit

Permalink
Upgrade laravel to 11 and all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
carsso committed Jan 26, 2025
1 parent 2c92215 commit 326feb4
Show file tree
Hide file tree
Showing 67 changed files with 5,926 additions and 4,972 deletions.
19 changes: 15 additions & 4 deletions .env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ DB_DATABASE=kantine
DB_USERNAME=kantine
DB_PASSWORD=password

IP_ALLOW_LIST=127.0.0.1,10.0.0.0/8,mydomain.com
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
REVERB_HOST="localhost"
REVERB_PORT=5189
REVERB_SCHEME=https
REVERB_SERVER_PORT=5189

SENTRY_LARAVEL_DSN=https://[email protected]/xx
SENTRY_TRACES_SAMPLE_RATE=1.0
#SENTRY_CDN=https://sentry.xxx.xxxx/cdn
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

IP_ALLOW_LIST=127.0.0.1,10.0.0.0/8,mydomain.com
19 changes: 15 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ DB_DATABASE=kantine
DB_USERNAME=kantine
DB_PASSWORD=password

IP_ALLOW_LIST=127.0.0.1,10.0.0.0/8,mydomain.com
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
REVERB_HOST="mydomain.com"
REVERB_PORT=443
REVERB_SCHEME=https
REVERB_SERVER_PORT=5189

SENTRY_LARAVEL_DSN=https://[email protected]/xx
SENTRY_TRACES_SAMPLE_RATE=1.0
#SENTRY_CDN=https://sentry.xxx.xxxx/cdn
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

IP_ALLOW_LIST=127.0.0.1,10.0.0.0/8,mydomain.com
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
composer.phar
laravel-echo-server.lock
laravel-echo-server.json
/.fleet
/.idea
/.vscode
Expand Down
47 changes: 47 additions & 0 deletions app/Console/Commands/RefreshDashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Console\Commands;

use App\Events\DashboardRefreshEvent;
use App\Events\MenuUpdatedEvent;
use App\Models\Menu;
use Illuminate\Console\Command;

class RefreshDashboard extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kantine:refresh-dashboard {date?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Refresh dashboard page';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if($date = $this->argument('date')) {
$menu = Menu::where('date', $date)->first();
if(!$menu) {
$this->error('Menu not found for date: ' . $date);
return 1;
}
MenuUpdatedEvent::dispatch($menu);
$this->info('Menu updated for date: ' . $date);
} else {
DashboardRefreshEvent::dispatch();
$this->info('Dashboard refreshed');
}
return 0;
}
}
4 changes: 4 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ protected function schedule(Schedule $schedule): void
{
$schedule->command('kantine:notify-webex')
->weekdays()->at('10:30');

$schedule->command('kantine:refresh-dashboards')
->dailyAt('00:30')
->dailyAt('15:30');
}

/**
Expand Down
31 changes: 31 additions & 0 deletions app/Events/DashboardRefreshEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DashboardRefreshEvent implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct()
{
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return [ new Channel('public') ];
}
}
40 changes: 40 additions & 0 deletions app/Events/MenuUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Events;

use App\Models\Menu;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MenuUpdatedEvent implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* @var Menu
*/
public $menu;

/**
* Create a new event instance.
*
* @param Menu $menu
*/
public function __construct(Menu $menu)
{
$this->menu = $menu;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return [ new Channel('public') ];
}
}
2 changes: 0 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Sentry\Laravel\Integration;
use Throwable;

class Handler extends ExceptionHandler
Expand All @@ -26,7 +25,6 @@ public function register(): void
{
$this->reportable(
function (Throwable $e) {
Integration::captureUnhandledException($e);
}
);
}
Expand Down
13 changes: 10 additions & 3 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function menu($dateString = null)
public function updateMenu(UpdateMenuFormRequest $request)
{
$validated = $request->validated();
$isDirty = false;
if($validated['date'] && count($validated['date']) > 0) {
foreach($validated['date'] as $idx => $date)
{
foreach($validated['date'] as $idx => $date) {
$menu = Menu::where('date', $date)->first();
if(!$menu) {
$menu = new Menu;
Expand All @@ -87,7 +87,14 @@ public function updateMenu(UpdateMenuFormRequest $request)
$menu->cheeses = $validated['cheeses'][$idx] ?? [];
$menu->desserts = $validated['desserts'][$idx] ?? [];
$menu->file_id = $menu->file_id ?? null;
$menu->save();
if($menu->isDirty()) {
$menu->save();
$isDirty = true;
}
}

if(!$isDirty) {
return $this->redirectWithError('Rien à mettre à jour', redirect()->route('admin.menu', ['date' => $validated['date'][0]]), null, 'flash', true);
}
return $this->redirectWithSuccess('Menus mis à jour', redirect()->route('admin.menu', ['date' => $validated['date'][0]]));
}
Expand Down
10 changes: 7 additions & 3 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ protected function backWithSuccess(string $message, $sessionBag = 'flash', Redir
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectWithError(string $message, RedirectResponse $redirectResponse, ?Exception $e = null, $sessionBag = 'flash')
protected function redirectWithError(string $message, RedirectResponse $redirectResponse, ?Exception $e = null, $sessionBag = 'flash', $withoutInput = false)
{
$withError = 'with' . Str::studly($sessionBag) . 'Error';
$withErrorException = $withError . 'Exception';

$response = $redirectResponse->$withError($message)->withInput();
if($withoutInput) {
$response = $redirectResponse->$withError($message);
} else {
$response = $redirectResponse->$withError($message)->withInput();
}
if ($e) {
$response = $response->$withErrorException($e->getMessage());
$response = $redirectResponse->$withErrorException($e->getMessage());
}

return $response;
Expand Down
26 changes: 0 additions & 26 deletions app/Http/Controllers/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\File;
use App\Http\Requests\UploadFormRequest;
use App\Jobs\ProcessFile;
use Barryvdh\Debugbar\Facades\Debugbar;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
Expand Down Expand Up @@ -185,29 +184,4 @@ public function legal()
{
return view('legal');
}

public function sentry(Request $request)
{
Debugbar::disable();
if (!config('sentry.dsn')) {
return response('Sentry is not configured', 500);
}

$envelope = $request->getContent();
$pieces = explode("\n", $envelope, 2);
$header = json_decode($pieces[0], true);

if (empty($header['dsn']) || $header['dsn'] !== config('sentry.dsn')) {
return response('Invalid DSN', 500);
}

$dsn = parse_url(config('sentry.dsn'));
$project_id = intval(trim($dsn['path'], '/'));

return Http::withBody($envelope, 'application/x-sentry-envelope')
->withHeaders([
'X-Forwarded-For' => $request->ip(),
])
->post('https://'.$dsn['host'].'/api/'.$project_id.'/envelope/');
}
}
6 changes: 3 additions & 3 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'restrict.ip' => \App\Http\Middleware\RestrictIpAddressMiddleware::class,
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
];
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
* @var array<int, string>
*/
protected $except = [
'/sentry'
'broadcasting/auth',
];
}
1 change: 1 addition & 0 deletions app/Jobs/ProcessFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\File;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use App\Models\Menu;
Expand Down
14 changes: 14 additions & 0 deletions app/Models/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace App\Models;

use App\Events\MenuUpdatedEvent;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;

class Menu extends Model
{
Expand Down Expand Up @@ -297,4 +299,16 @@ public function getMainSpecialName($index, $short = true)
return null;
}

public function save(array $options = []): bool
{
$saved = parent::save($options);
if ($saved) {
try {
MenuUpdatedEvent::dispatch($this);
} catch (\Exception $e) {
Log::error($e);
}
}
return $saved;
}
}
37 changes: 18 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.2",
"sentry/sentry-laravel": "^3.8",
"smalot/pdfparser": "^2.5",
"spatie/laravel-permission": "^5.11",
"symfony/process": "^6.3"
"php": "*",
"guzzlehttp/guzzle": "^7.9",
"laravel/framework": "^11.40",
"laravel/reverb": "^1.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.10",
"laravel/ui": "^4.6",
"smalot/pdfparser": "^2.11",
"spatie/laravel-permission": "^6.10",
"symfony/process": "^7.2"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8",
"fakerphp/faker": "^1.9.1",
"laravel-lang/common": "^4.0",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
"fakerphp/faker": "^1.24",
"laravel-lang/common": "^6.4",
"laravel/pint": "^1.20",
"laravel/sail": "^1.40",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5",
"spatie/laravel-ignition": "^2.9"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 326feb4

Please sign in to comment.