/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('board_adventures', function (Blueprint $table) {
         $table->increments('adventure_id');
         $table->binary('adventurer_ip');
         $table->string('board_uri', 32);
         $table->integer('post_id')->unsigned()->nullable()->default(NULL);
         $table->timestamps();
         $table->timestamp('expires_at');
         $table->timestamp('expended_at')->nullable()->default(NULL);
         $table->foreign('board_uri')->references('board_uri')->on('boards')->onDelete('cascade')->onUpdate('cascade');
     });
     Schema::table('posts', function (Blueprint $table) {
         $table->integer('adventure_id')->unsigned()->nullable()->default(NULL)->after('locked_at');
         $table->foreign('adventure_id')->references('adventure_id')->on('board_adventures')->onDelete('set null')->onUpdate('cascade');
     });
     Schema::table('boards', function (Blueprint $table) {
         $table->timestamp('last_post_at')->nullable()->default(NULL)->after('updated_at');
     });
     Board::chunk(100, function ($boards) {
         foreach ($boards as $board) {
             $lastPost = $board->posts()->orderBy('created_at', 'desc')->limit(1)->get()->last();
             if ($lastPost) {
                 $board->last_post_at = $lastPost->created_at;
                 $board->save();
             }
         }
     });
 }
示例#2
0
 public function runBoards()
 {
     $this->command->comment("\tInserting board owner roles.");
     $boardRole = $this->slugs()[Role::ID_OWNER];
     Board::chunk(50, function ($boards) {
         foreach ($boards as $board) {
             $boardRole = $board->getOwnerRole();
             if (!$boardRole) {
                 $boardRole = Role::getOwnerRoleForBoard($board);
                 $this->command->line("\t/{$board->board_uri}/ has no owner role.");
             }
             $roleModel = Role::firstOrCreate(['role' => $boardRole['role'], 'board_uri' => $board->board_uri, 'caste' => $boardRole['caste']]);
             if ($roleModel->wasRecentlyCreated) {
                 $roleModel->fill(['name' => $boardRole['name'], 'capcode' => $boardRole['capcode'], 'inherit_id' => Role::ID_OWNER, 'system' => false, 'weight' => $boardRole['weight'] + 5])->save();
             }
         }
     });
 }