Skip to content

Commit

Permalink
[COM-727] - added new migration to fix new message/reason entries tha…
Browse files Browse the repository at this point in the history
…t have not been correctly formatted
  • Loading branch information
ajaypayne committed May 4, 2021
1 parent db9d017 commit 62f435e
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Schema\Builder;
use Flarum\Formatter\Formatter;
use Flarum\Post\Post;

return [
'up' => function (Builder $schema) {
/** @var Formatter $formatter */
$formatter = app()->make(Formatter::class);

$schema->getConnection()
->query()
->select()
->from('users_suspension_history')
->chunk(100, function ($suspensionLogs) use ($formatter, $schema) {
foreach ($suspensionLogs as $suspensionLog) {
$update = [];
if ($suspensionLog->reason !== null && substr( $suspensionLog->reason, 0, 1 ) !== "<") {
$update['reason'] = $formatter->parse($suspensionLog->reason, new Post());
}
if ($suspensionLog->message !== null && substr( $suspensionLog->message, 0, 1 ) !== "<") {
$update['message'] = $formatter->parse($suspensionLog->message, new Post());
}

if (array_key_exists('message', $update) || array_key_exists('reason', $update)) {
$schema->getConnection()->table('users_suspension_history')
->where('id', $suspensionLog->id)
->update($update);
}
}
});
},

'down' => function (Builder $schema) {
// One way
}
];

0 comments on commit 62f435e

Please sign in to comment.