15 @ini_set(
'max_execution_time', 120);
16 @ini_set(
'memory_limit',
'1024M');
18 @error_reporting(E_ALL);
19 @ini_set(
'display_errors', 1);
21 require_once
'acn_cli_api.inc.php';
22 require_once
'acn_kvdb_api.inc.php';
25 if(php_sapi_name()!==
'cli' || !
defined(
'STDIN')){
26 echo
'Only cli execution mode supported'.PHP_EOL;
34 if(isset(
$args[
'h']) || isset(
$args[
'help']) || !isset(
$args[ACN_KVDB_CA_URL],
$args[
'document'])){
35 echo
'Usage: '.$argv[0].
' --url=kvdb_manager_url> --document=<document_file> --format=<document_format{0-xml,1-json}> '.
36 '[--t=<http_requet_timeout_sec>] [--l=<log_mode{0-Off,1-On}>]'.PHP_EOL;
42 if(!isset(
$args[ACN_KVDB_CA_TIMEOUT]) || empty(
$args[ACN_KVDB_CA_TIMEOUT])){
43 $args[ACN_KVDB_CA_TIMEOUT]=ACN_KVDB_TIMEOUT;
48 if(!isset(
$args[
'format']) ||
$args[
'format']===
''){
54 if(!isset(
$args[
'document'])){
55 $aborted=
'--document=<document_file> ';
57 if(!file_exists(
$args[
'document'])){
58 $aborted.=
'file '.$args[
'document'].
' ';
61 if(
$args[
'format']==ACN_KVDB_IMPORT_TYPE_XML){
62 $documents=ACN_KVDB_import_from_xml_file(
$args[
'document']);
64 $documents=ACN_KVDB_import_from_json_file(
$args[
'document']);
67 foreach($documents as $id=>$document){
69 $documents[$id]=base64_encode(json_encode($document));
71 $documents[$id]=json_encode($document);
75 $request_array=ACN_KVDB_prepare_request_array(ACN_KVDB_CMD_PUT, $documents);
81 $r=ACN_KVDB_request($request_array, array(ACN_KVDB_CA_URL=>
$args[ACN_KVDB_CA_URL], ACN_KVDB_CA_TIMEOUT=>
$args[ACN_KVDB_CA_TIMEOUT]));
82 if($r[
'error']==ACN_KVDB_ERROR_OK){
83 $r=ACN_KVDB_parse_response($r[
'response']);
85 var_dump($r); echo PHP_EOL;
87 if($r[ACN_KVDB_FIELD_ERROR_CODE]==ACN_KVDB_ERROR_OK){
91 echo
'Response error '.$r[ACN_KVDB_FIELD_ERROR_CODE].
' : '.$r[ACN_KVDB_FIELD_ERROR_MSG];
95 $r[ACN_KVDB_FIELD_TIME]=0;
97 echo
'Request error '.$r[
'error'].
' : '.$r[
'error_msg'].PHP_EOL;
101 $r[ACN_KVDB_FIELD_TIME]=0;
109 echo PHP_EOL.
'Finished, time '.$r[ACN_KVDB_FIELD_TIME].PHP_EOL;