diff --git a/commands/HelloController.php b/commands/HelloController.php deleted file mode 100644 index 20066c40..00000000 --- a/commands/HelloController.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @since 2.0 - */ -class HelloController extends Controller -{ - /** - * This command echoes what you have entered as the message. - * @param string $message the message to be echoed. - * @return int Exit code - */ - public function actionIndex($message = 'hello world') - { - echo $message . "\n"; - - return ExitCode::OK; - } -} diff --git a/commands/SyncController.php b/commands/SyncController.php new file mode 100644 index 00000000..0df6a920 --- /dev/null +++ b/commands/SyncController.php @@ -0,0 +1,75 @@ + + * @since 2.0 + */ +class SyncController extends Controller { + + /** + * This command echoes what you have entered as the message. + * @param string $message the message to be echoed. + * @return int Exit code + */ + public function actionIndex() { + if ($this->is_connected()) { + $sync = \app\models\SyncUrl::find()->one(); + if ($sync) { + $logs = \app\models\FaceLogs::find()->all(); + foreach ($logs as $key => $value) { + $options = [ + 'http' => [ + 'header' => "Content-Type: application/json", + 'method' => "POST", + 'content' => json_encode([ + "camera_id" => $value->camera_id, + "confidence" => $value->confidence, + "enable_door" => $value->enable_door, + "encoded_person_image" => $value->encoded_person_image, + "frametime" => $value->frametime, + "id" => $value->face_id, + "image" => $value->image, + "name" => $value->name, + "person_id" => $value->person_id, + "status" => $value->status, + "stt" => $value->stt, + "timezone" => $value->timezone + ]), + ] + ]; + file_get_contents($sync->data, false, stream_context_create($options)); + $value->delete(); + } + } + } + return ExitCode::OK; + } + + function is_connected() { + $connected = @fsockopen("google.com", 80); + //website, port (try 80 or 443) + if ($connected) { + $is_conn = true; //action when connected + fclose($connected); + } else { + $is_conn = false; //action in connection failure + } + return $is_conn; + } + +} diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 2092c47f..99b0f9ca 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -38,8 +38,14 @@ class ApiController extends Controller { public function actionSyncUrl() { if (Yii::$app->request->post()) { $post = Yii::$app->request->bodyParams; - $model = new \app\models\FaceLogs(); - $model->create($post); + $sync = \app\models\SyncUrl::find()->one(); + if ($sync) { + $sync->data = $post['url']; + $sync->save(); + } else { + $model = new \app\models\SyncUrl(); + $model->create($post); + } Yii::$app->response->format = "json"; return ["stt" => true]; } diff --git a/controllers/DashboardController.php b/controllers/DashboardController.php index 8fe20fba..929eb248 100644 --- a/controllers/DashboardController.php +++ b/controllers/DashboardController.php @@ -43,7 +43,7 @@ class DashboardController extends Controller { $this->view->title = "Bảng tổng hợp"; $searchModel = new FaceLogsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - + return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, diff --git a/db/app.db b/db/app.db index a68c1520..40061df8 100644 Binary files a/db/app.db and b/db/app.db differ