| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- /**
- * UpgradeCrontabController 从服务器定时查询更新代码版本
- */
- namespace console\controllers;
- use common\enums\StatusEnum;
- use common\models\backend\SystemVersionLog;
- use common\models\backend\SystemVersionSlb;
- use yii\console\Controller;
- use yii\console\ExitCode;
- use Yii;
- class UpgradeCrontabController extends Controller
- {
- /**
- * 从服务器定时查询更新代码
- * * * * * * *
- * @Author: lun
- * @DateTime: 2021/11/17 0017 20:38
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return int
- */
- public function actionExecute(){
- try {
- // 获取最新的更新信息
- $log = SystemVersionLog::find()->where(['status' => StatusEnum::ENABLED])->orderBy('id desc')->asArray()->one();
- if (empty($log)) return ExitCode::OK;
- // 获取从服务器最新的更新记录
- $ip = Yii::$app->params['network_ip'];
- $slb = SystemVersionSlb::find()->where(['version_id' => $log['id'], 'ip' => $ip, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if (empty($slb) && !empty($log['upgrade_params'])) {
- $model = SystemVersionSlb::initSetData($log['id']);
- if ($model == false) throw new \Exception('更新初始化失败:' . SystemVersionSlb::getStaticError());
- $upgrade_data = json_decode($log['upgrade_params'], true);// 解析更新参数
- Yii::$app->services->upgrade->slbUpgrade($upgrade_data, $model['id']);
- }
- return ExitCode::OK;
- } catch (\Exception $e) {
- echo $e->getMessage();
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- }
|