Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e6d980d
wip composer.json
deer-wmde Feb 16, 2024
4c12e0b
WIP - departure to integrate
deer-wmde Feb 16, 2024
8bec342
replace `gluedev/laravel-stackdriver`
deer-wmde Feb 16, 2024
d9c231d
configure `absszero/laravel-stackdriver-error-reporting`
deer-wmde Feb 7, 2024
a4b1a4e
remove call to `registerPolicies`
deer-wmde Feb 7, 2024
d5e3e62
schedule redis stale tag pruning
deer-wmde Feb 7, 2024
5c9f61c
use `$casts` property
deer-wmde Feb 7, 2024
7b9b7f2
run `composer update --ignore-platform-reqs`
deer-wmde Feb 16, 2024
2e5381a
rename `$routeMiddleware`
deer-wmde Feb 7, 2024
d1cc531
Apply curated changes from
deer-wmde Feb 7, 2024
a7af73b
test: php 8.2
deer-wmde Feb 7, 2024
057906a
update php version in composer
deer-wmde Feb 16, 2024
af1f342
remove custom stackdriver repo
deer-wmde Feb 16, 2024
6320805
upgrade to phpunit 10
deer-wmde Feb 16, 2024
9790236
migrate phpunit configuration
deer-wmde Feb 16, 2024
6aa3dd5
re-add "absszero/laravel-stackdriver-error-reporting"
deer-wmde Feb 16, 2024
220b8b1
replace CORS Handler
deer-wmde Feb 16, 2024
6dbb7f9
refactor data providers
deer-wmde Feb 16, 2024
f6b19cc
refactor `$this->dispatch` & `dispatchNow`
deer-wmde Feb 16, 2024
82e9c29
fix test class name
deer-wmde Feb 16, 2024
084ef40
refactor some tests
deer-wmde Feb 16, 2024
69e426e
update phpunit to 10.5, run composer update
deer-wmde Feb 19, 2024
8753b46
migrate ElasticSearchIndexDeleteTest.php
deer-wmde Feb 19, 2024
a0a8c04
fix deprecated string interpolation
deer-wmde Feb 21, 2024
985ead4
tests: replace job to queue dispatching with calling handle()
deer-wmde Feb 21, 2024
af5121d
implement ForceSearchIndex::uniqueId
deer-wmde Feb 21, 2024
78423e5
move to `dispatch` as mostly recommended example
deer-wmde Feb 22, 2024
863f660
remove leftover phpunit conf cbackup
deer-wmde Feb 22, 2024
e7a98ca
remove unused `MAIL_URL` conf
deer-wmde Feb 22, 2024
35ef59b
CHANGELOG
deer-wmde Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/composer.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 8.1
php_version: 8.2
command: install

- name: Copy example .env file
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Homestead.yaml
.env
.php_cs.cache
.phpunit.result.cache
.phpunit.cache
/storage/*.key
/public/storage
_ide_helper.php
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# api

## 10x.0.0 - 26 February 2024
- Update Laravel to v10.10 - T341797
- schedule redis stale tag pruning
- refactor: `dispatchNow` was removed
- Update to PHPUnit v10.5
- fix: Implemented ForceSearchIndex::uniqueId T358106

## 9x.1.0 - 16 Februrary 2024
- Switching to PHP 8.2

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/Wiki/SetSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle()
'wiki_id' => $wiki->id,
'name' => $settingKey,
])->delete();
$this->line("Deleted setting ${settingKey} for wiki id ${wikiId}");
$this->line("Deleted setting {$settingKey} for wiki id {$wikiId}");
return;
}

Expand All @@ -54,7 +54,7 @@ public function handle()
'value' => $settingValue,
]
);
$this->line("Set setting ${settingKey} to ${settingValue} for wiki id ${wikiId}");
$this->line("Set setting {$settingKey} to {$settingValue} for wiki id {$wikiId}");

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class Kernel extends ConsoleKernel
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
protected function schedule(Schedule $schedule): void
{
// Make sure that the DB and QS pools are always populated somewhat.
// This will create at most 1 new entry for each per minute...
Expand All @@ -48,6 +47,9 @@ protected function schedule(Schedule $schedule)
// Schedule site stat updates for each wiki and platform-summary
$schedule->command('schedule:stats')->dailyAt('7:00');

// https://laravel.com/docs/10.x/upgrade#redis-cache-tags
$schedule->command('cache:prune-stale-tags')->hourly();

$schedule->job(new PollForMediaWikiJobsJob)->everyFifteenMinutes();

$schedule->job(new UpdateWikiSiteStatsJob)->dailyAt('19:00');
Expand All @@ -57,10 +59,8 @@ protected function schedule(Schedule $schedule)

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__.'/Commands/User');
Expand Down
22 changes: 3 additions & 19 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,8 @@

class Handler extends ExceptionHandler
{

/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];

/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [];

/**
* A list of the inputs that are never flashed for validation exceptions.
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array
*/
Expand All @@ -37,10 +20,11 @@ class Handler extends ExceptionHandler
/**
* Register the exception handling callbacks for the application.
*/
public function register()
public function register(): void
{
$this->reportable(function (Throwable $e) {
(new \Absszero\ErrorReporting)->report($e);
});
}
}

3 changes: 1 addition & 2 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, ValidatesRequests;
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Sandbox/SandboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public function create(Request $request): \Illuminate\Http\Response
// For now only schedule this job for 1 dataSet type
// As the extension API is dumb currently
if ($dataSet === 'library') {
$this->dispatch(new MediawikiSandboxLoadData($domain, $dataSet));
dispatch(new MediawikiSandboxLoadData($domain, $dataSet));
}

// opportunistic dispatching of jobs to make sure storage pools are topped up
$this->dispatch(new ProvisionWikiDbJob(null, null, 10));
$this->dispatch(new ProvisionQueryserviceNamespaceJob(null, 10));
dispatch(new ProvisionWikiDbJob(null, null, 10));
dispatch(new ProvisionQueryserviceNamespaceJob(null, 10));

$res['success'] = true;
$res['message'] = 'Success!';
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function create(Request $request): \Illuminate\Http\Response
$maxWikis = config('wbstack.wiki_max_per_user');

if ( config('wbstack.wiki_max_per_user') !== false && $numWikis > config('wbstack.wiki_max_per_user')) {
abort(403, "Too many wikis. Your new total of {$numWikis} would exceed the limit of ${maxWikis} per user.");
abort(403, "Too many wikis. Your new total of {$numWikis} would exceed the limit of {$maxWikis} per user.");
}

$wiki = Wiki::create([
Expand Down Expand Up @@ -114,22 +114,22 @@ public function create(Request $request): \Illuminate\Http\Response
]);

// TODO maybe always make these run in a certain order..?
$this->dispatch(new MediawikiInit($wiki->domain, $request->input('username'), $user->email));
dispatch(new MediawikiInit($wiki->domain, $request->input('username'), $user->email));
// Only dispatch a job to add a k8s ingress IF we are using a custom domain...
if (! $isSubdomain) {
$this->dispatch(new KubernetesIngressCreate($wiki->id, $wiki->domain));
dispatch(new KubernetesIngressCreate($wiki->id, $wiki->domain));
}
});


// dispatch elasticsearch init job to enable the feature
if ( Config::get('wbstack.elasticsearch_enabled_by_default') ) {
$this->dispatch(new ElasticSearchIndexInit($wiki->id));
dispatch(new ElasticSearchIndexInit($wiki->id));
}

// opportunistic dispatching of jobs to make sure storage pools are topped up
$this->dispatch(new ProvisionWikiDbJob(null, null, 10));
$this->dispatch(new ProvisionQueryserviceNamespaceJob(null, 10));
dispatch(new ProvisionWikiDbJob(null, null, 10));
dispatch(new ProvisionQueryserviceNamespaceJob(null, 10));

$res['success'] = true;
$res['message'] = 'Success!';
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Http\Middleware\HandleCors::class,
\Illuminate\Http\Middleware\TrustProxies::class,
];

Expand All @@ -32,7 +32,7 @@ class Kernel extends HttpKernel
*
* @var array
*/
protected $routeMiddleware = [
protected $middlewareAliases = [
// Came with Laravel
'auth' => \App\Http\Middleware\Authenticate::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
Expand Down
15 changes: 9 additions & 6 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

/**
* The purpose of RedirectIfAuthenticated is to keep an already authenticated user
Expand All @@ -17,15 +19,16 @@ class RedirectIfAuthenticated
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle(Request $request, Closure $next, string ...$guards): Response
{
if (Auth::guard($guard)->check()) {
return response()->json('Endpoint not needed', 400);
//return redirect('/home');
}
$guards = empty($guards) ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return response()->json('Endpoint not needed', 400);
}
}
return $next($request);
}
}
11 changes: 9 additions & 2 deletions app/Jobs/CirrusSearch/ForceSearchIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* Example:
*
* php artisan job:dispatchNow CirrusSearch\\ForceSearchIndex id 1 0 1000
* php artisan job:dispatch CirrusSearch\\ForceSearchIndex id 1 0 1000
*/
class ForceSearchIndex extends CirrusSearchJob
{
Expand All @@ -25,6 +25,13 @@ public function __construct( string $selectCol, $selectValue, int $fromId, int $
$this->toId = $toId;
parent::__construct($wiki->id);
}

public function uniqueId() {
return parent::uniqueId() . '_'
. $this->fromId . '_'
. $this->toId;
}

public function fromId(): int {
return $this->fromId;
}
Expand Down Expand Up @@ -59,7 +66,7 @@ public function handleResponse( string $rawResponse, $error ) : void {

if ( count($successMatches) === 2 && is_numeric($successMatches[1][0]) ) {
$numIndexedPages = intVal($successMatches[1][0]);
Log::info(__METHOD__ . ": Finished batch! Indexed ${numIndexedPages} pages. From id {$this->fromId} to {$this->toId}");
Log::info(__METHOD__ . ": Finished batch! Indexed {$numIndexedPages} pages. From id {$this->fromId} to {$this->toId}");
} else {
dd($successMatches);
Log::error(__METHOD__ . ": Job finished but did not contain the expected output.");
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/CirrusSearch/QueueSearchIndexBatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* Example:
*
* php artisan job:dispatchNow CirrusSearch\\QueueSearchIndexBatches 1
* php artisan job:dispatch CirrusSearch\\QueueSearchIndexBatches 1
*/
class QueueSearchIndexBatches extends CirrusSearchJob
{
Expand Down Expand Up @@ -84,7 +84,7 @@ public function handleResponse( string $rawResponse, $error ) : void {
if ( !empty($batches) ) {
// todo rewrite as batch
foreach ($batches as $job) {
$this->dispatch($job);
dispatch($job);
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/CreateEmptyWikiDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* To be deleted after migration
*
* Example usage that will always provision a new DB:
* php artisan job:dispatchNow CreateEmptyWikiDb
* php artisan job:dispatch CreateEmptyWikiDb
*/
class CreateEmptyWikiDb extends Job
{
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/DeleteWikiFinalizeJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function handle( HttpRequest $request )
continue;
}

$this->fail(new \RuntimeException("WikiDb for ${$wiki->id} still exists"));
$this->fail(new \RuntimeException("WikiDb for {$wiki->id} still exists"));
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/KubernetesIngressCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* This can be run with for example:
* php artisan job:dispatchNow KubernetesIngressCreate 999999999 wiki.addshore.com
* php artisan job:dispatch KubernetesIngressCreate 999999999 wiki.addshore.com
*
* If you need to cleanup a test run of this you need to remove the ingress and the related secret
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PlatformStatsSummaryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* TODO The stats from wiki statistics doesn't add up https://github.com/wbstack/mediawiki/issues/59
* We need to fix that before we can get total pages/edits/users
*
* Example: php artisan job:dispatchNow PlatformStatsSummaryJob
* Example: php artisan job:dispatch PlatformStatsSummaryJob
*/
class PlatformStatsSummaryJob extends Job
{
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProvisionQueryserviceNamespaceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Example usage
* php artisan job:dispatchNow ProvisionQueryserviceNamespaceJob
* php artisan job:dispatch ProvisionQueryserviceNamespaceJob
*/
class ProvisionQueryserviceNamespaceJob extends Job
{
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProvisionWikiDbJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Example usage that will always provision a new DB:
* php artisan job:dispatchNow ProvisionWikiDbJob
* php artisan job:dispatch ProvisionWikiDbJob
*/
class ProvisionWikiDbJob extends Job
{
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/SetWikiLogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

/**
* This can be run with the artisan job command, for example:
* php artisan job:dispatchNow SetWikiLogo domain wiki.addshore.com /path/to/logo.png
* php artisan job:dispatchNow SetWikiLogo id 1234 /path/to/logo.png
* php artisan job:dispatch SetWikiLogo domain wiki.addshore.com /path/to/logo.png
* php artisan job:dispatch SetWikiLogo id 1234 /path/to/logo.png
*
* NOTE: This job needs to be run as the correct user if run via artisan (instead of via the UI)
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/SiteStatsUpdateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* Job that updates site_stats table in mediawiki by calling initSiteStats.php
*
* Example: php artisan job:dispatchNow SiteStatsUpdateJob
* Example: php artisan job:dispatch SiteStatsUpdateJob
*/
class SiteStatsUpdateJob extends Job
{
Expand Down
8 changes: 2 additions & 6 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->bind(HttpRequest::class, CurlRequest::class);
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
public function boot(): void
{
Queue::failing(function (JobFailed $event) {
$name = data_get($event->job->payload(), 'data.commandName');
Expand Down
Loading