Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Laravel to version 9 #718

Merged
merged 11 commits into from
Jan 23, 2024
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# api

## 9x.0.0 - 23 January 2024
- Update Laravel to version 9

## 8x.35.1 - 22 January 2024
- Use S3 driver for accessing static files in GCP buckets, using proper ACLs

Expand Down
12 changes: 11 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@

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
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [];

Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function register(Request $request)

event(new Registered($user));

/**
* @psalm-suppress UndefinedInterfaceMethod
*/
Auth::guard()->login($user);

// HTTP Response
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Backend/QsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public function getBatches(Request $request): \Illuminate\Http\Response

public function markBatchesDone(Request $request): \Illuminate\Http\Response
{
$batches = (array) $request->json()->get('batches');
$batches = (array) $request->json()->all('batches');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong usage before and worked mostly by accident. Now, Symfony will throw an error on the wrong usage, so I was able to fix it.

QsBatch::whereIn('id', $batches)->increment(
'processing_attempts', 1,
['done' => 1, 'pending_since' => null]
);
return response(1);
return response('1');
}

public function markBatchesNotDone(Request $request): \Illuminate\Http\Response
{
$batches = (array) $request->json()->get('batches');
$batches = (array) $request->json()->all('batches');
QsBatch::whereIn('id', $batches)->increment(
'processing_attempts', 1,
['done' => 0, 'pending_since' => null]
);
return response(1);
return response('1');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/WikiSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WikiSettingController extends Controller
/**
* @return (SettingWikibaseManifestEquivEntities|string)[][]
*
* @psalm-return array{wgDefaultSkin: array{0: 'required', 1: 'string', 2: 'in:vector,modern,timeless'}, wwExtEnableConfirmAccount: array{0: 'required', 1: 'boolean'}, wwExtEnableWikibaseLexeme: array{0: 'required', 1: 'boolean'}, wwWikibaseStringLengthString: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMonolingualText: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMultilang: array{0: 'required', 1: 'integer', 2: 'between:250,2500'}, wikibaseFedPropsEnable: array{0: 'required', 1: 'boolean'}, wikibaseManifestEquivEntities: array{0: 'required', 1: 'json', 2: SettingWikibaseManifestEquivEntities}}
* @psalm-return array{wgDefaultSkin: array{0: 'required', 1: 'string', 2: 'in:vector,modern,timeless'}, wwExtEnableConfirmAccount: array{0: 'required', 1: 'boolean'}, wwExtEnableWikibaseLexeme: array{0: 'required', 1: 'boolean'}, wwWikibaseStringLengthString: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMonolingualText: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMultilang: array{0: 'required', 1: 'integer', 2: 'between:250,2500'}, wikibaseFedPropsEnable: array{0: 'required', 1: 'boolean'}, wikibaseManifestEquivEntities: array{0: 'required', 1: 'json', 2: SettingWikibaseManifestEquivEntities}, wwUseQuestyCaptcha: array{0: 'required, 1: 'boolean}, wwCaptchaQuestions: array:{0: 'required', 1: 'json', 2: SettingCaptchaQuestions}}
*/
private function getSettingValidations(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Kernel extends HttpKernel
'throttle.signup' => \App\Http\Middleware\ThrottleSignup::class,
//'throttle' => App\Http\Middleware\ThrottleRequests::class,
//'auth' => App\Http\Middleware\Authenticate::class,
'cors' => \Fruitcake\Cors\HandleCors::class,
'cors' => \Illuminate\Http\Middleware\HandleCors::class,
];

/**
Expand Down
13 changes: 8 additions & 5 deletions app/Jobs/DeleteWikiDbJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Database\DatabaseManager;

/**
* Prepends the MW Database, User with `deleted_` prefix and deletes WikiDB relation for a wiki
* Prepends the MW Database, User with `deleted_` prefix and deletes WikiDB relation for a wiki
*/
class DeleteWikiDbJob extends Job implements ShouldBeUnique
{
Expand Down Expand Up @@ -65,15 +65,15 @@ public function handle( DatabaseManager $manager )
if (! $conn instanceof \Illuminate\Database\Connection) {
throw new \RuntimeException('Must be run on a PDO based DB connection');
}

$pdo = $conn->getPdo();
$timestamp = Carbon::now()->timestamp;
$deletedDatabaseName = "mwdb_deleted_{$timestamp}_{$this->wikiId}";

if ($pdo->exec('USE '.$wikiDB->name) === false) {
throw new \RuntimeException('Failed to use database with dbname: '.$wikiDB->name);
}


$tables = [];
$result = $pdo->query('SHOW TABLES')->fetchAll();
Expand All @@ -88,7 +88,7 @@ public function handle( DatabaseManager $manager )
if(count($values) !== 1) {
throw new \RuntimeException("Tried getting table names for wikiDB {$wikiDB->name} but failed");
}

$tables[] = $values[0];
}

Expand All @@ -107,6 +107,9 @@ public function handle( DatabaseManager $manager )
$replacedCount = 0;
$tableWithoutPrefix = str_replace($wikiDB->prefix . '_', '', $table, $replacedCount );
if ($replacedCount !== 1) {
/**
* @psalm-suppress InvalidCast
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really tried hard to understand these warnings but I could not make any sense of them so I suppressed them for now. If anyone has a hunch why they might show up, please lmk.

*/
throw new \RuntimeException("Did not find prefix '{$wikiDB->prefix}' in tablename '{$table}' ");
}
$pdo->exec(sprintf('RENAME TABLE %s.%s TO %s.%s', $wikiDB->name, $table, $deletedDatabaseName, $tableWithoutPrefix));
Expand Down
10 changes: 10 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ public function boot()

//
}

/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}
4 changes: 2 additions & 2 deletions app/Providers/KubernetesClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\ServiceProvider;
use Maclof\Kubernetes\Client;
use Http\Adapter\Guzzle6\Client as Guzzle6Client;
use Http\Adapter\Guzzle7\Client as GuzzleClient;

class KubernetesClientServiceProvider extends ServiceProvider
{
Expand All @@ -16,7 +16,7 @@ class KubernetesClientServiceProvider extends ServiceProvider
public function register()
{
$this->app->bind(Client::class , function ($app) {
$httpClient = Guzzle6Client::createWithConfig([
$httpClient = GuzzleClient::createWithConfig([
'verify' => '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
]);

Expand Down
5 changes: 4 additions & 1 deletion app/Rules/SettingCaptchaQuestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function passes($attribute, $value)
if (!is_string($question)) {
return false;
}
/**
* @psalm-suppress NoValue
*/
if (strlen($question) > 200) {
return false;
}
Expand All @@ -34,7 +37,7 @@ public function passes($attribute, $value)
if (!is_array($answers)) {
return false;
}
if (count($answers) === 0) {
if (count((array) $answers) === 0) {
return false;
}
foreach ($answers as $answer) {
Expand Down
161 changes: 0 additions & 161 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,165 +117,4 @@ public function getEmailForVerification()
{
return $this->email;
}
/**
* Convert the model instance to an array.
*
* @return array
*/
function toArray() {
return parent::toArray();
}

/**
* Determine if the given attribute exists.
*
* @param mixed $offset
*
* @return bool
*/
function offsetExists($offset) {
return parent::offsetExists($offset);
}

/**
* Get the value for a given offset.
*
* @param mixed $offset
*
* @return mixed
*/
function offsetGet($offset) {
return parent::offsetGet($offset);
}

/**
* Set the value for a given offset.
*
* @param mixed $offset
* @param mixed $value
*
* @return void
*/
function offsetSet($offset, $value) {
parent::offsetSet($offset, $value);
}

/**
* Unset the value for a given offset.
*
* @param mixed $offset
*
* @return void
*/
function offsetUnset($offset) {
parent::offsetUnset($offset);
}

/**
* Get the broadcast channel route definition that is associated with the given entity.
*
* @return string
*/
function broadcastChannelRoute() {
return parent::broadcastChannelRoute();
}

/**
* Get the broadcast channel name that is associated with the given entity.
*
* @return string
*/
function broadcastChannel() {
return parent::broadcastChannel();
}

/**
* Convert the model instance to JSON.
*
* @param int $options
*
* @return string
*/
function toJson($options = 0) {
return parent::toJson($options);
}

/**
* Convert the object into something JSON serializable.
*
* @return array
*/
function jsonSerialize() {
return parent::jsonSerialize();
}

/**
* Get the queueable identity for the entity.
*
* @return mixed
*/
function getQueueableId() {
return parent::getQueueableId();
}

/**
* Get the queueable relationships for the entity.
*
* @return array
*/
function getQueueableRelations() {
return parent::getQueueableRelations();
}

/**
* Get the queueable connection for the entity.
*
* @return null|string
*/
function getQueueableConnection() {
return parent::getQueueableConnection();
}

/**
* Get the value of the model's route key.
*
* @return mixed
*/
function getRouteKey() {
return parent::getRouteKey();
}

/**
* Get the route key for the model.
*
* @return string
*/
function getRouteKeyName() {
return parent::getRouteKeyName();
}

/**
* Retrieve the model for a bound value.
*
* @param mixed $value
* @param null|string $field
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
function resolveRouteBinding($value, $field = null) {
return parent::resolveRouteBinding($value, $field);
}

/**
* Retrieve the child model for a bound value.
*
* @param string $childType
* @param mixed $value
* @param null|string $field
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
function resolveChildRouteBinding($childType, $value, $field) {
return parent::resolveChildRouteBinding($childType, $value, $field);
}
}