<?php
namespace App\Controllers\Admin;

use Core\Installer;

/** 后台：数据升级（免 SSH，等价于 bash deploy.sh 的数据初始化部分） */
class SystemController extends AdminController
{
    public function index()
    {
        return $this->view('admin/system', ['seg' => 'system']);
    }

    public function upgrade()
    {
        if ($_SERVER['REQUEST_METHOD'] === 'POST' && csrf_check()) {
            $msgs = Installer::upgrade();
            $_SESSION['flash'] = ['type' => 'ok', 'msg' => '数据升级完成 ✓ ' . implode('；', $msgs)];
        } else {
            $_SESSION['flash'] = ['type' => 'err', 'msg' => '安全校验失败，请重试'];
        }
        $this->redirect('admin/system');
    }
}
