From b013b84b8b8bf5d141e84000d6028c888bbad293 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 8 May 2017 22:07:20 +0200 Subject: [PATCH] [fix] init management in deploy --- lib/api/deploy | 2 +- lib/api/source/deploy.php | 23 ++++++++++++++++------- lib/api/source/init.php | 18 +++++++++--------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/api/deploy b/lib/api/deploy index edc3aee..5342ebd 100755 --- a/lib/api/deploy +++ b/lib/api/deploy @@ -1,3 +1,3 @@ #!/bin/sh -/usr/bin/env php $(realpath $(dirname $0))/source/deploy.php; +/usr/bin/env php $(realpath $(dirname $0))/source/deploy.php $*; diff --git a/lib/api/source/deploy.php b/lib/api/source/deploy.php index c4b44a5..7ff7ddf 100755 --- a/lib/api/source/deploy.php +++ b/lib/api/source/deploy.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../../include/php/const'; - function api_deploy(){ + function api_deploy($init){ /* [1] Fetch api response =========================================================*/ @@ -20,7 +20,7 @@ if( is_null($arr_r) ) return 127; - + /* [2] Get system states (global_state) =========================================================*/ /* (1) Check data */ @@ -58,7 +58,7 @@ foreach($arr_r['chips'] as $chip) $f->fwrite( json_encode([ - + (int) $chip['position'], $chip['pins'], $chip['states'] @@ -82,7 +82,7 @@ foreach($arr_r['permissions'] as $code=>$perm) $f->fwrite( json_encode([ - + $code, (int) $perm['id_user'], $perm['actions'] @@ -107,7 +107,7 @@ foreach($arr_r['actions'] as $timeout=>$actions) foreach($actions as $action) $f->fwrite( json_encode([ - + (int) $timeout, (int) $action['id_action'], $action['previous'], @@ -121,6 +121,10 @@ /* [6] Remove history entries =========================================================*/ + /* (0) We are done if @init */ + if( $init ) + return 0; + /* (1) Check history entries count */ if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) ) return 127; @@ -146,10 +150,15 @@ } - $exec = api_deploy(); + /* Manage init vs. sync */ + $is_init = false; + if( $argc > 1 && $argv[1] == 'init' ) + $is_init = true; + + $exec = api_deploy($is_init); echo $exec; die($exec); - + ?> diff --git a/lib/api/source/init.php b/lib/api/source/init.php index 17116f6..5c26d5d 100755 --- a/lib/api/source/init.php +++ b/lib/api/source/init.php @@ -39,7 +39,7 @@ /* (4) Try new hash if available */ $new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new'); - + if( $new === false ){ slog("cyclic-hash:new returned $new EXIT_STATUS", 'api:init','update'); return 127; @@ -55,7 +55,7 @@ $unlock_code = preg_replace('/\s/', '', $unlock_code); - + /* [2] Create httpRequest base =========================================================*/ @@ -114,14 +114,14 @@ /* (2) Close request */ curl_close($curl); - + /* (3) Return response as result */ if( $response === false ){ slog("Request error", 'api:init','update'); return 127; } - + /* [6] Response management =========================================================*/ /* (1) Try to json_decode response */ @@ -160,19 +160,19 @@ /* [8] Deploy received data =========================================================*/ /* (1) Manage response deployement */ - $deploy = syscall(SOURCE_DIR.'/lib/api/deploy'); - + $deploy = syscall(SOURCE_DIR.'/lib/api/deploy init'); + /* (2) Return state */ return ($deploy === true) ? 0 : 127; - + } $exec = api_init(); echo $exec; die($exec); - - + + ?>