diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 5add7c19..418a2dfe 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -481,12 +481,6 @@ class ApiController extends Controller { } public function actionTest() { - $logs = CaptureLogs::find()->andWhere(["<=", "time", 1646092799])->count(); - foreach ($logs as $key => $value) { - @unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image); - $value->delete(); - } - exit(); // $updating = \app\models\SyncUrl::findOne(['key_config' => 'token']); $updating = \app\models\SyncUrl::find()->all(); foreach ($updating as $key => $value) { @@ -543,18 +537,20 @@ class ApiController extends Controller { if ($datas['status'] == 10000) { $logs = $datas['data']; $infomation = []; + file_put_contents("test.txt", json_encode($logs)); foreach ($logs as $key => $value) { + $result = true; if ($value['action'] == "insert_image") - $this->insertImage($value['images'][0], $value['id'], $value['files_name'][0]); + $result = $this->insertImage($value['images'][0], $value['id'], $value['files_name'][0]); if ($value['action'] == "remove_image") - $this->removeImage($value['id'], $value['files_name'][0]); + $result = $this->removeImage($value['id'], $value['files_name'][0]); if ($value['action'] == "insert_info") - $this->insertInfo($value); + $result = $this->insertInfo($value); if ($value['action'] == "remove_info") - $this->removeInfo($value); + $result = $this->removeInfo($value); if ($value['action'] == "reset_all") { \Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute(); @@ -562,7 +558,7 @@ class ApiController extends Controller { array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*")); } - if (in_array($value['action'], ['insert_image', 'remove_image', 'insert_info', 'remove_info', 'reset_all'])) { + if ($result && in_array($value['action'], ['insert_image', 'remove_image', 'insert_info', 'remove_info', 'reset_all'])) { $infomation[] = [ "obj_Log" => $value['obj_Log'], "action" => $value['action'], @@ -587,6 +583,8 @@ class ApiController extends Controller { public function insertImage($image, $staff_id, $files_name) { $model = ListManagement::findOne(['staff_id' => $staff_id]); + if (!$model) + return false; $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; $targetPath = $RootFolder . "/face"; @@ -635,10 +633,15 @@ class ApiController extends Controller { $model->save(); } } + return true; } public function removeImage($staff_id, $files_name) { $model = ListManagement::findOne(['staff_id' => $staff_id]); + if (!$model) + return false; + if (!$model) + file_put_contents("error.txt", $staff_id . "\n", FILE_APPEND); $images = json_decode($model->image, true); $ft = []; foreach ($images as $key => $value) { @@ -649,7 +652,7 @@ class ApiController extends Controller { } $model->image = json_encode($ft); $model->last_modified = time(); - $model->save(); + return $model->save(); } public function insertInfo($data) { @@ -676,6 +679,7 @@ class ApiController extends Controller { 'abbreviated_name' => $data['abbreviated_name'], ]); } + return true; } public function removeInfo($data) { @@ -687,7 +691,7 @@ class ApiController extends Controller { } $model->delete(); } - return; + return true; } public function resizeImg($img, $fileTarget) {