fix bug auto sync feature

This commit is contained in:
dongpd 2022-07-11 13:41:25 +07:00
parent 64d9ad0b88
commit 45c9a9f4f1
2 changed files with 43 additions and 5 deletions

View File

@ -4,5 +4,6 @@ return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
"maxLogs" => 50000, "maxLogs" => 50000,
"maxPicture" => 9999, "maxPicture" => 9999,
"version" => "1.0.7" "version" => "1.0.7",
"autoSyncLog" => true
]; ];

View File

@ -516,6 +516,22 @@ class ApiController extends Controller {
public function actionCheckLogs() { public function actionCheckLogs() {
set_time_limit(5000); set_time_limit(5000);
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$logProcessStatus = \app\models\SyncUrl::findOne(['key_config' => 'log_process_status']);
if (!$logProcessStatus) {
$model = new \app\models\SyncUrl();
$model->create(['key_config' => 'log_process_status', 'data' => "true"]);
$logProcessStatus = \app\models\SyncUrl::findOne(['key_config' => 'log_process_status']);
} else {
if ($logProcessStatus->data == "true") {
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", "CHECK LOGS PROCESSING\n", FILE_APPEND);
return ["data" => "check logs processing"];
} else {
$logProcessStatus->data = "true";
$logProcessStatus->save();
}
}
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com"; $ip = "https://dev-dc.beetai.com";
if ($server_ip) if ($server_ip)
@ -535,11 +551,16 @@ class ApiController extends Controller {
]) ])
] ]
])), true); ])), true);
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", "START CHECK LOGS\n", FILE_APPEND);
if ($datas['status'] == 10000) { if ($datas['status'] == 10000) {
$logs = $datas['data']; $logs = $datas['data'];
$infomation = []; $infomation = [];
$fault_information = []; $fault_information = [];
$count = 0;
foreach ($logs as $key => $value) { foreach ($logs as $key => $value) {
$count++;
$start = $this->getCurrentTime();
$result = true; $result = true;
if ($value['action'] == "insert_image") if ($value['action'] == "insert_image")
$result = $this->insertImage($value['images'][0], $value['id'], $value['files_name'][0]); $result = $this->insertImage($value['images'][0], $value['id'], $value['files_name'][0]);
@ -558,6 +579,10 @@ class ApiController extends Controller {
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute(); \Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*")); array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));
} }
$finish = $this->getCurrentTime();
$processTime = round(($finish - $start), 4);
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", $count . "\t" . $value['action'] . "\t" . $value['files_name'][0] . "\t" . ($result ? "true" : "false") . "\t" . $processTime . "\t" . $value['name'] . "\n", FILE_APPEND);
if (in_array($value['action'], ['insert_image', 'remove_image', 'insert_info', 'remove_info', 'reset_all'])) { if (in_array($value['action'], ['insert_image', 'remove_image', 'insert_info', 'remove_info', 'reset_all'])) {
if ($result) if ($result)
@ -587,6 +612,8 @@ class ApiController extends Controller {
])); ]));
@file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count()); @file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
} }
$logProcessStatus->data = "false";
$logProcessStatus->save();
return ["data" => "check logs"]; return ["data" => "check logs"];
} }
@ -627,8 +654,11 @@ class ApiController extends Controller {
], ],
"type" => "128" "type" => "128"
]); ]);
if (!$features['status']) if (!$features['status']) {
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", "[ERROR] extract feature " . json_encode($features) . "\n", FILE_APPEND);
return false; return false;
}
$features = json_decode($features['data'], true); $features = json_decode($features['data'], true);
$ft[] = [ $ft[] = [
"serverKey" => $files_name, "serverKey" => $files_name,
@ -639,10 +669,17 @@ class ApiController extends Controller {
]; ];
$model->image = json_encode($ft); $model->image = json_encode($ft);
$model->last_modified = time(); $model->last_modified = time();
$model->save(); return $model->save();
} else {
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", "[ERROR] image error" . $image . "\n", FILE_APPEND);
return false;
} }
} else {
if (Yii::$app->params['autoSyncLog'])
file_put_contents("logs.txt", "[ERROR] file exists" . $files_name . "\n", FILE_APPEND);
return false;
} }
return true;
} }
public function removeImage($staff_id, $files_name) { public function removeImage($staff_id, $files_name) {