다운타임없이 Laravel 4.1.26으로 업그레이드 하기

Submitted by river - 등록 10 years ago - 수정 10 years ago

인증시 사용되는 remember me 쿠키에 보안 문제가 생겨서 Larvel 4.1.26이 릴리즈 됐습니다. Laravel 4.1.26을 업그레이드를 하려면 패키지는 물론 User.php와 users DB 테이블을 변경해야 한다. 다음의 방법을 통하면 최소한의 다운타임으로 업그레이드 할 수 있을 것 같다.

User.php 수정

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

use \Eloquent;

class User extends Eloquent implements UserInterface, RemindableInterface
{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

    // Added for Laravel 4.1.26 upgrade
    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    public function getRememberTokenName()
    {
        return 'remember_token';
    }

}

app\database\migrations 폴더에 2014_04_18_111111_add_nullable_remember_token_to_user.php 파일 추가

<?php

use Illuminate\Database\Migrations\Migration;

class AddNullableRememberTokenToUser extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function($table) {
            $table->text("remember_token")->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function($table) {
            $table->dropColumn("remember_token");
        });
    }

}

Laravel maintenance 모드로 변경. 이때 접속을 하면 Be right back! 이란 화면이 뜬다.

$ php artisan down

DB 마이그레이션 실행

$ php artisan migrate

패키지 갱신

$ composer update

Laravel 웹 시작

$ php artisan up

위 내용은 하나의 쉘 파일로 만들어서 실행하는 게 편하다.

$ vi patch.sh
php artisan down
php artisan migrate
composer update
php artisan up
$ chmod u+x patch.sh
$ ./patch.sh

참고

Laracast : Important Breaking Change in 4.1.26

comments powered by Disqus