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

config 初始化缺少判断 #4

Closed
springjk opened this issue Oct 12, 2017 · 3 comments
Closed

config 初始化缺少判断 #4

springjk opened this issue Oct 12, 2017 · 3 comments

Comments

@springjk
Copy link

springjk commented Oct 12, 2017

触发:
当在 AppServiceProvider 的 boot 中添加 Config::load();时如果数据库中无 admin_config 表就会触发,此处对表进行了全读取。

[Illuminate\Database\QueryException]                                                                                                          
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.admin_config' doesn't exist (SQL: select `name`, `value` from `admin_config`)  

场景:
服务器上部署代码是先拉取代码再执行 php artisan migrate 等命令来安装初始化的,但是这个时候 load 因为在 boot 中,任何地方都会触发,所以连 php artisan 都无法执行,形成了死循环。

解决方案:

  1. 先临时注释掉此行代码,在 php artisan admin:import config 命令执行完成后再打开
  2. 手工在数据库中创建 admin_config
  3. 代码进行判断,如:
    public function boot()
    {
        if (Schema::hasTable('admin_config')) {
            Config::load();
        }
    }

但以上三种方法均非良策,看代码是因为要压入系统配置函数所以直接初始化,有无更好的方法直接在包里改进?

@z-song
Copy link
Member

z-song commented Oct 12, 2017

先migrate, 再在AppServiceProvider添加load

@springjk
Copy link
Author

@z-song 我上面有说场景,比如是部署代码,如果是本地开发可以改改代码或者先注释,服务器上大多需要一些自动化脚本,此时数据库是空的,如果要做的你说说的,就需要在脚本中按照方案1先临时注释,再进行开启,要写一个定位到某某行的脚本较为麻烦并且存在时效性,所以大多只能采用方案3,但我认为这样在任何时候都要多一次数据库查询,似乎不是好办法。

@z-song
Copy link
Member

z-song commented Oct 12, 2017

确实没有一个很好的办法,参考的另一个包https://github.com/laravel-backpack/settings就是用的方案三

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants