diff --git a/controllers/ApiController.php b/controllers/ApiController.php index f296f8fb..5f2dd819 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -248,6 +248,8 @@ class ApiController extends Controller { public function actionAutoGenFeature() { Yii::$app->response->format = "json"; + if (!$this->check512()) + return ["status" => false]; $updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']); if (!$updating) { $model = new \app\models\SyncUrl(); @@ -410,26 +412,46 @@ class ApiController extends Controller { } } - public function actionTest() { - $check = \app\models\SyncUrl::findOne(['key_config' => 'updating']); - $check->data = "false"; - $check->save(); - return var_dump($check); -// file_get_contents("http://localhost:2305/update-feature"); -// return; - set_time_limit(0); - $lists = ListManagement::find()->all(); - foreach ($lists as $key => $value) { - $extract = false; - $images = json_decode($value->image, true); - $newImgs = []; - foreach ($images as $k => $v) { - $v['features512'] = []; - $newImgs[] = $v; - } - $value->image = json_encode($newImgs); - $value->save(); + public function check512() { + $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST" + ] + ])), true); + if (!$tempConfig['status']) + return false; + + $engineConfig = json_decode($tempConfig['data'], true); + if (count($engineConfig['data']['engines']) == 0) + return false; + + $checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + 'path' => $engineConfig['data']['engines'][0]['path'] + ]) + ] + ])), true); + + if (!$checkConfig['status']) + return false; + + $config_json = ""; + if ($checkConfig['status']) { + $config_json = json_decode($checkConfig['data'], true); + $check512 = $config_json['feature']['type2']['enable']; + if ($check512 !== "0") + return true; } + return false; + } + + public function actionTest() { + $updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']); + var_dump($updating->data); } public function actionReGenFeature() { @@ -441,7 +463,10 @@ class ApiController extends Controller { 'data' => "false" ]); } else { - $updating->data = "false"; + if ($this->check512()) + $updating->data = "true"; + else + $updating->data = "false"; $updating->save(); } Yii::$app->response->format = "json";