<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------

namespace app\service\domain\upgrade;


use app\service\domain\admin\system\CorePlatformService;
use Core\service\BaseCoreService;
use think\facade\Log;


/**
 * 升级运行刷新服务
 * Upgrade Runtime Refresh Service

 * @package app\service\domain\upgrade

 */

class UpgradeRuntimeRefreshService extends BaseCoreService
{
    /**
     * 刷新升级运行时
     * @param string $scene 场景 upgrade 或 sync
     * @return array
     */
    public function refresh(string $scene = 'upgrade'): array
    {
        try {
            $result = $this->app->make(CorePlatformService::class)->sync();
            if (function_exists('opcache_reset')) {
                opcache_reset();
            }
            return is_array($result) ? $result : ['code' => 0, 'msg' => ''];

        } catch (\Throwable $e) {

            Log::error(sprintf('upgrade runtime refresh failed [%s]: %s', $scene, $e->getMessage()));
            return [
                'code' => 1,
                'msg' => $e->getMessage(),
            ];
        }
    }
}