1
0
mirror of https://github.com/flarum/core.git synced 2025-08-05 16:07:34 +02:00

Store discussion slug in database table

In preparation for #646.
This commit is contained in:
Franz Liedke
2016-02-04 11:46:30 +01:00
parent efff4c1801
commit 97979b2189
5 changed files with 91 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Core\Migration;
use Flarum\Core\Discussion;
use Flarum\Database\AbstractMigration;
use Flarum\Util\Str;
use Illuminate\Database\Schema\Blueprint;
class AddSlugToDiscussions extends AbstractMigration
{
public function up()
{
$this->schema->table('discussions', function (Blueprint $table) {
$table->string('slug');
});
// Store slugs for existing discussions
Discussion::chunk(100, function ($discussions) {
foreach ($discussions as $discussion) {
$discussion->slug = Str::slug($discussion->title);
$discussion->save();
}
});
}
public function down()
{
$this->schema->table('discussions', function (Blueprint $table) {
$table->dropColumn('slug');
});
}
}