From 37b034f614568b83a154176d3eb6d109c83b1dff Mon Sep 17 00:00:00 2001 From: Banana Date: Sun, 25 Apr 2021 21:51:50 +0200 Subject: [PATCH] some updates while working with a games import --- data-crow/datacrowimport.class.php | 10 ++++ data-crow/import/game/import-mapping.json | 67 +++++++++++------------ data-crow/run-import-to-bibliotheca.php | 44 +++++++++------ 3 files changed, 69 insertions(+), 52 deletions(-) diff --git a/data-crow/datacrowimport.class.php b/data-crow/datacrowimport.class.php index dc88257..52ccbed 100644 --- a/data-crow/datacrowimport.class.php +++ b/data-crow/datacrowimport.class.php @@ -181,6 +181,13 @@ class Datacrowimport { curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + /** remove for debug + $fp = fopen(dirname(__FILE__).'/import-error.log', 'w+'); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_STDERR, $fp); + curl_setopt($ch, CURLINFO_HEADER_OUT, true); + */ + if(!empty($port)) { curl_setopt($ch, CURLOPT_PORT, $port); } @@ -189,9 +196,12 @@ class Datacrowimport { if(is_string($do) === true) { $ret = $do; + // debug line + //error_log(var_export(curl_getinfo($ch),true)); } else { error_log(var_export(curl_error($ch),true)); + error_log(var_export(curl_getinfo($ch),true)); } curl_close($ch); diff --git a/data-crow/import/game/import-mapping.json b/data-crow/import/game/import-mapping.json index 311a408..882d650 100644 --- a/data-crow/import/game/import-mapping.json +++ b/data-crow/import/game/import-mapping.json @@ -2,70 +2,67 @@ "mapping": { "element": "software-item", "fields": { + "title": { + "into": "title" + }, "categories": { "child": "category", "valuefield": "name", "into": "category" }, "description": { - "into": "description" - }, - "developers": { - "child": "developer", - "valuefield": "name", - "into": "directors" - }, - - - "countries-list": { - "into": "country" - }, - "created": { - "into": "date" - }, - "description": { - "into": "body" + "into": "content" }, "description-alternative": { "into": "description", "from": "description", "method": "firstSentence" }, - - "genres": { - "child": "genre", + "developers": { + "child": "developer", "valuefield": "name", - "into": "genres" + "into": "developer" }, - "title": { - "into": "title" - }, - "languages-list": { - "into": "languages" + "picture-front": { + "into": "coverimage", + "asset": "image" }, "picture-back": { - "into": "file_picture-back", + "into": "attachment", "asset": "image" }, "picture-cd": { - "into": "file_picture-cd", + "into": "attachment", "asset": "image" }, - "picture-front": { - "into": "file_picture-front", - "asset": "image" + "publishers": { + "child": "publisher", + "valuefield": "name", + "into": "publisher" + }, + "platform": { + "into": "platform" }, "rating": { "into": "rating", - "method": "modifyRating" + "method": "modifyRatingTrim" + }, + "screenshot-one": { + "into": "attachment", + "asset": "image" }, - "playlength": { - "into": "runtime" + "screenshot-two": { + "into": "attachment", + "asset": "image" + }, + "screenshot-three": { + "into": "attachment", + "asset": "image" }, "tags": { "child": "tag", "valuefield": "name", - "into": "storage" + "into": "tag" }, "year": { "into": "year" diff --git a/data-crow/run-import-to-bibliotheca.php b/data-crow/run-import-to-bibliotheca.php index 7c96b53..1a462b7 100644 --- a/data-crow/run-import-to-bibliotheca.php +++ b/data-crow/run-import-to-bibliotheca.php @@ -20,22 +20,22 @@ */ # where the data crow export data is located. -define('IMPORT_FOLDER','import/movie'); +define('IMPORT_FOLDER','import/game'); # the data crow xml filename within the IMPORT_FOLDER -define('DATACROW_XML_FILENAME','movies-export.xml'); +define('DATACROW_XML_FILENAME','games-export.xml'); # the data crow images folder within the IMPORT_FOLDER (optional) -define('DATACROW_IMAGES_FOLDERNAME','movies-export_images'); -# the output folder where the generead MD content will be saved +define('DATACROW_IMAGES_FOLDERNAME','games-export_images'); +# the output folder where the generated MD content will be saved define('OUTPUT_FOLDER','output'); # the bibliotheca api endpoint define('API_ENDPOINT','http://localhost/bibliotheca/webclient/api.php?p=add'); # the tolen to connect to the api. # created in bibliotheca use management -define('API_TOKEN','c435168733c58b82d455d776990ff425'); +define('API_TOKEN','1e637832829255b453ce589b066b3c69'); # the bibliotheca collection to store into -define('BIB_COLLECTION_ID','1'); +define('BIB_COLLECTION_ID','2'); define('DEBUG',true); @@ -97,12 +97,12 @@ if(!empty($entries)) { // the resulting POST data array is key=>value (string) only // only the upload can be an array - $_data['actors'] = implode(',',$entry['actors']); - $_data['tag'] = implode(',',$entry['tag']); - $_data['genres'] = implode(',',$entry['genres']); - $_data['directors'] = implode(',',$entry['directors']); - $_data['countries'] = implode(',',$entry['countries']); - $_data['languages'] = implode(',',$entry['languages']); + // lookupmultiple fields + // change to match your import settings + if(isset($_data['category'])) $_data['category'] = implode(',',$entry['category']); + if(isset($_data['developer'])) $_data['developer'] = implode(',',$entry['developer']); + if(isset($_data['tag'])) $_data['tag'] = implode(',',$entry['tag']); + if(isset($_data['publisher'])) $_data['publisher'] = implode(',',$entry['publisher']); if(!empty($_data['coverimage'])) { $_data['coverimage'] = curl_file_create($_data['coverimage']); @@ -123,16 +123,26 @@ if(!empty($entries)) { unset($_data['attachment']); } - var_dump($_data); - exit(); $do = $ImportObj->curlPostCall($url,$_data); if(!empty($do)) { - echo "Created: ".$entry['title']."\n"; - echo var_export($do, true)."\n"; + $retJson = json_decode($do,true); + if(!empty($retJson) && isset($retJson['status']) && $retJson['status'] === 200) { + echo "Created: ".$entry['title']."\n"; + echo "With data: ".var_export($entry,true)."\n"; + echo "Returndata: ".var_export($do, true)."\n"; + } + else { + echo "can not create: ".$entry['title']."\n"; + echo "With data: ".var_export($entry,true)."\n"; + echo "Returndata: ".var_export($do, true)."\n"; + exit(1); + } } else { echo "can not create: ".$entry['title']."\n"; - echo var_export($do, true)."\n"; + echo "invalid call return data\n"; + echo "With data: ".var_export($entry,true)."\n"; + echo "Returndata: ".var_export($do, true)."\n"; exit(1); } } -- 2.39.5