Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/composer.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
run: docker compose exec -e APP_ENV=testing -T api vendor/bin/phpunit
- name: Psalm
run: docker compose exec -T api vendor/bin/psalm
- name: Linting
run: docker compose exec api vendor/bin/pint --test -v

- name: Run elasticsearch index deletion integration test
run: docker compose exec -e RUN_PHPUNIT_INTEGRATION_TEST=1 -e ELASTICSEARCH_HOST=elasticsearch.svc:9200 -T api vendor/bin/phpunit tests/Jobs/Integration/ElasticSearchIndexDeleteTest.php
Expand Down
19 changes: 0 additions & 19 deletions .php_cs

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ Currently most of the tests require the DB connection to exist.
docker compose exec api vendor/bin/phpunit
```

### Linting

```sh
docker compose exec api vendor/bin/pint --test -v
```

#### Debugging

If you get a CORS error from an API when testing, it might be due to an exception internally, resulting in a 500 response with no CORS.
Expand Down
7 changes: 3 additions & 4 deletions app/ComplaintRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* @property \Illuminate\Support\Carbon|null $dispatched_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*
* @mixin \Eloquent
*/
class ComplaintRecord extends Model
{
class ComplaintRecord extends Model {
use HasFactory;

protected $fillable = [
Expand All @@ -30,8 +30,7 @@ class ComplaintRecord extends Model
'offending_urls',
];

public function markAsDispatched()
{
public function markAsDispatched() {
$this->dispatched_at = Carbon::now();
}
}
6 changes: 2 additions & 4 deletions app/Console/Commands/Invitation/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use App\Invitation;
use Illuminate\Console\Command;

class All extends Command
{
class All extends Command {
protected $signature = 'wbs-invitation:all';

protected $description = 'List all current invitations';
Expand All @@ -16,8 +15,7 @@ class All extends Command
*
* @return mixed
*/
public function handle()
{
public function handle() {
foreach (Invitation::all() as $invitation) {
$this->line($invitation->code);
}
Expand Down
10 changes: 4 additions & 6 deletions app/Console/Commands/Invitation/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use App\Jobs\InvitationCreateJob;
use Illuminate\Console\Command;

class Create extends Command
{
class Create extends Command {
protected $signature = 'wbs-invitation:create {code}';

protected $description = 'Create an invitation';
Expand All @@ -16,15 +15,14 @@ class Create extends Command
*
* @return mixed
*/
public function handle()
{
public function handle() {
$code = trim($this->argument('code'));
$jobResult = (new InvitationCreateJob($code))->handle();

if ($jobResult) {
$this->line('Successfully created invitation: '.$code);
$this->line('Successfully created invitation: ' . $code);
} else {
$this->line('Failed to create invitation: '.$code);
$this->line('Failed to create invitation: ' . $code);
}

return 0;
Expand Down
20 changes: 9 additions & 11 deletions app/Console/Commands/Invitation/CreateBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace App\Console\Commands\Invitation;

use App\Helper\InviteHelper;
use App\Jobs\InvitationCreateJob;
use Illuminate\Console\Command;
use App\Helper\InviteHelper;

class CreateBulk extends Command
{
class CreateBulk extends Command {
protected $signature = 'wbs-invitation:create-bulk {numCodes}';

protected $description = 'Create an bulk invitations';
Expand All @@ -17,20 +16,19 @@ class CreateBulk extends Command
*
* @return mixed
*/
public function handle()
{
public function handle() {
$numCodes = trim($this->argument('numCodes'));
$helper = new InviteHelper();
$helper = new InviteHelper;

for($i = 0; $i < $numCodes; $i++) {
for ($i = 0; $i < $numCodes; $i++) {
$code = $helper->generate();
$jobResult = (new InvitationCreateJob($code))->handle();

if ($jobResult) {
$this->line('Successfully created invitation: '.$code);
} else {
$this->line('Failed to create invitation: '.$code);
}
$this->line('Successfully created invitation: ' . $code);
} else {
$this->line('Failed to create invitation: ' . $code);
}
}

return 0;
Expand Down
6 changes: 2 additions & 4 deletions app/Console/Commands/Invitation/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use App\Jobs\InvitationDeleteJob;
use Illuminate\Console\Command;

class Delete extends Command
{
class Delete extends Command {
protected $signature = 'wbs-invitation:delete {code}';

protected $description = 'Delete an invitation';
Expand All @@ -16,8 +15,7 @@ class Delete extends Command
*
* @return mixed
*/
public function handle()
{
public function handle() {
$code = trim($this->argument('code'));
(new InvitationDeleteJob($code))->handle();

Expand Down
41 changes: 20 additions & 21 deletions app/Console/Commands/RebuildQueryserviceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
namespace App\Console\Commands;

use App\Constants\MediawikiNamespace;
use App\Jobs\SpawnQueryserviceUpdaterJob;
use App\QueryserviceNamespace;
use App\Traits;
use App\Wiki;
use App\WikiSetting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Queue;
use App\Wiki;
use App\WikiSetting;
use App\QueryserviceNamespace;
use App\Jobs\SpawnQueryserviceUpdaterJob;

class RebuildQueryserviceData extends Command
{
class RebuildQueryserviceData extends Command {
use Traits\PageFetcher;

protected $signature = 'wbs-qs:rebuild {--domain=*} {--chunkSize=50} {--queueName=manual-intervention} {--sparqlUrlFormat=http://queryservice.default.svc.cluster.local:9999/bigdata/namespace/%s/sparql}';

protected $description = 'Rebuild the queryservice data for a certain wiki or all wikis';

protected int $chunkSize;

protected string $sparqlUrlFormat;

protected string $queueName;

public function handle()
{
public function handle() {
$this->chunkSize = intval($this->option('chunkSize'));
$this->sparqlUrlFormat = $this->option('sparqlUrlFormat');
$this->queueName = $this->option('queueName');
$this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST').'/w/api.php';
$this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php';

$wikiDomains = $this->option('domain');
$exitCode = 0;
Expand All @@ -48,7 +47,7 @@ public function handle()
$sparqlUrl = $this->getSparqlUrl($wiki);
} catch (\Exception $ex) {
Log::error(
'Failed to get prerequisites for enqueuing wiki '.$wiki->domain.', will not dispatch jobs.',
'Failed to get prerequisites for enqueuing wiki ' . $wiki->domain . ', will not dispatch jobs.',
[$ex],
);
$exitCode = 1;
Expand All @@ -66,24 +65,24 @@ public function handle()
}
$jobTotal += count($entityChunks);
$processedWikis += 1;
Log::info('Dispatched '.count($entityChunks).' job(s) for wiki '.$wiki->domain.'.');
Log::info('Dispatched ' . count($entityChunks) . ' job(s) for wiki ' . $wiki->domain . '.');
}

Log::info(
'Done. Jobs dispatched: '.$jobTotal.' Wikis processed: '.$processedWikis.' Wikis skipped: '.$skippedWikis
'Done. Jobs dispatched: ' . $jobTotal . ' Wikis processed: ' . $processedWikis . ' Wikis skipped: ' . $skippedWikis
);

return $exitCode;
}

private function getEntitiesForWiki (Wiki $wiki): array
{
private function getEntitiesForWiki(Wiki $wiki): array {
$items = $this->fetchPagesInNamespace($wiki->domain, MediawikiNamespace::item);
$properties = $this->fetchPagesInNamespace($wiki->domain, MediawikiNamespace::property);

$lexemesSetting = WikiSetting::where(
[
'wiki_id' => $wiki->id,
'name' => WikiSetting::wwExtEnableWikibaseLexeme
'name' => WikiSetting::wwExtEnableWikibaseLexeme,
],
)->first();
$hasLexemesEnabled = $lexemesSetting !== null && $lexemesSetting->value === '1';
Expand All @@ -93,22 +92,22 @@ private function getEntitiesForWiki (Wiki $wiki): array

$merged = array_merge($items, $properties, $lexemes);
$this->stripPrefixes($merged);

return $merged;
}

private function getSparqlUrl (Wiki $wiki): string
{
private function getSparqlUrl(Wiki $wiki): string {
$match = QueryserviceNamespace::where(['wiki_id' => $wiki->id])->first();
if (!$match) {
throw new \Exception(
'Unable to find queryservice namespace record for wiki '.$wiki->domain
'Unable to find queryservice namespace record for wiki ' . $wiki->domain
);
}

return sprintf($this->sparqlUrlFormat, $match->namespace);
}

private static function stripPrefixes (array &$items): void
{
private static function stripPrefixes(array &$items): void {
foreach ($items as &$item) {
$e = explode(':', $item);
$item = end($e);
Expand Down
19 changes: 9 additions & 10 deletions app/Console/Commands/ScheduleStatsUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Jobs\PlatformStatsSummaryJob;
use App\Jobs\SiteStatsUpdateJob;
use App\Wiki;
use App\Jobs\PlatformStatsSummaryJob;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;

/**
* Schedules jobs for updating site_stats per wiki then platformsummaryjob
*/
class ScheduleStatsUpdates extends Command
{
class ScheduleStatsUpdates extends Command {
/**
* The name and signature of the console command.
*
Expand All @@ -32,8 +32,7 @@ class ScheduleStatsUpdates extends Command
*
* @return void
*/
public function __construct()
{
public function __construct() {
parent::__construct();
}

Expand All @@ -42,20 +41,20 @@ public function __construct()
*
* @return int
*/
public function handle()
{
public function handle() {
$siteStatsUpdateJobs = [];
foreach (Wiki::all() as $wiki) {
$siteStatsUpdateJobs[] = new SiteStatsUpdateJob($wiki->id);
}

Log::info(__METHOD__ . ": Scheduling updates for " . count($siteStatsUpdateJobs) . " wikis.");
Log::info(__METHOD__ . ': Scheduling updates for ' . count($siteStatsUpdateJobs) . ' wikis.');

Bus::batch($siteStatsUpdateJobs)
->allowFailures()
->finally(function () {
dispatch(new PlatformStatsSummaryJob());
dispatch(new PlatformStatsSummaryJob);
})->dispatch();

return 0;
}
}
15 changes: 8 additions & 7 deletions app/Console/Commands/User/ChangeEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

namespace App\Console\Commands\User;

use App\Jobs\UserVerificationCreateTokenAndSendJob;
use App\User;
use Illuminate\Console\Command;
use App\Jobs\UserVerificationCreateTokenAndSendJob;

class ChangeEmail extends Command
{
class ChangeEmail extends Command {
protected $signature = 'wbs-user:change-email {--from=} {--to=}';

protected $description = 'Change e-mail address for user';

public function handle(): int
{
public function handle(): int {
$emailOld = $this->option('from');
$emailNew = $this->option('to');

$user = User::whereEmail($emailOld)->first();

if (!$user) {
$this->error("Error: Could not find a user for '$emailOld'.");

return 1;
}

if ($emailNew == $emailOld) {
$this->error("Error: New email matches current email.");
$this->error('Error: New email matches current email.');

return 2;
}

Expand All @@ -40,7 +40,8 @@ public function handle(): int

return 0;
} else {
$this->error("Error: Failed to save changes to the database.");
$this->error('Error: Failed to save changes to the database.');

return 3;
}
}
Expand Down
Loading
Loading