comparison php/read/getBookDetails.php @ 9:232deb0b066a

tidy up debugging, only show parms on non-throttled error
author Henry S. Thompson <ht@markup.co.uk>
date Sat, 18 Feb 2017 11:38:36 +0000
parents 077b0a0a3e6d
children 5aa24c984a3b
comparison
equal deleted inserted replaced
8:226f00d9f6f5 9:232deb0b066a
187 //'SearchIndex' =>$searchindex , //Books for example. 187 //'SearchIndex' =>$searchindex , //Books for example.
188 $parameters['SearchIndex']=$searchindex; 188 $parameters['SearchIndex']=$searchindex;
189 } 189 }
190 190
191 191
192 file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ".
193 print_r($parameters,TRUE)."\n",FILE_APPEND);
194
195 $ext=$Aserver[$locale]['ext']; 192 $ext=$Aserver[$locale]['ext'];
196 $file_data=$ext; 193 $file_data=$ext;
197 ksort($parameters); 194 ksort($parameters);
198 foreach ($parameters as $i=>$d) { 195 foreach ($parameters as $i=>$d) {
199 $file_data.='&'.$i.'='.$d; 196 $file_data.='&'.$i.'='.$d;
211 $out = curl_exec($crl); 208 $out = curl_exec($crl);
212 curl_close($crl); 209 curl_close($crl);
213 210
214 //echo $out; 211 //echo $out;
215 212
216 if (preg_match("<Error>",$out)) { 213 if (preg_match("<Error>",$out)) {
217 $xml = new SimpleXMLElement($out); 214 $xml = new SimpleXMLElement($out);
218 $resName=$xml->getName(); 215 $resName=$xml->getName();
219 $code=$xml->Error->Code; 216 $code=$xml->Error->Code;
220 file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, ". 217 file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND);
221 $xml->Error->Code."\n",FILE_APPEND); 218 if ($code=='RequestThrottled') {
222 } 219 usleep(200000); // Try to reduce throttling until we get a
223 else { 220 // principled solution in place
224 $xml = new SimpleXMLElement($out); 221 }
225 //use this xml to pull out the necessary information and save it 222 else {
226 set_error_handler(function () { 223 file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ".
227 global $out,$isbn; 224 print_r($parameters,TRUE)."\n",FILE_APPEND);
228 file_put_contents('/var/ywww/debug/phpDebug', 225 }
229 "Caught one bd: ".$isbn, 226 }
230 FILE_APPEND); 227 else {
231 file_put_contents('/var/ywww/debug/phpDebug', 228 $xml = new SimpleXMLElement($out);
232 print_r($out, TRUE)."\n", 229 //use this xml to pull out the necessary information and save it
233 FILE_APPEND); 230 set_error_handler(function () {
234 } ); 231 global $out,$isbn;
235 232 file_put_contents('/var/ywww/debug/phpDebug',
236 $title=""; 233 "Caught one bd: ".$isbn,
237 $author=""; 234 FILE_APPEND);
238 $binding=""; 235 file_put_contents('/var/ywww/debug/phpDebug',
239 $dewey=""; 236 print_r($out, TRUE)."\n",
240 $imageURL=""; 237 FILE_APPEND);
241 $salesRank=""; 238 } );
242 $pubDate=""; 239
243 $publisher=""; 240 $title="";
244 241 $author="";
245 $title = $xml->Items->Item->ItemAttributes->Title; 242 $binding="";
246 $author = $xml->Items->Item->ItemAttributes->Author; 243 $dewey="";
247 $binding = $xml->Items->Item->ItemAttributes->Binding; 244 $imageURL="";
248 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; 245 $salesRank="";
249 if($dewey == "") 246 $pubDate="";
250 $dewey = "null"; 247 $publisher="";
251 $imageURL = $xml->Items->Item->MediumImage->URL; 248
252 $salesRank = $xml->Items->Item->SalesRank; 249 $title = $xml->Items->Item->ItemAttributes->Title;
253 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; 250 $author = $xml->Items->Item->ItemAttributes->Author;
254 $publisher = $xml->Items->Item->ItemAttributes->Publisher; 251 $binding = $xml->Items->Item->ItemAttributes->Binding;
255 restore_error_handler(); 252 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
256 /*echo $title; 253 if($dewey == "")
257 echo $author; 254 $dewey = "null";
258 echo $binding; 255 $imageURL = $xml->Items->Item->MediumImage->URL;
259 echo $dewey; 256 $salesRank = $xml->Items->Item->SalesRank;
260 echo $imageURL; 257 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
261 echo $salesRank; 258 $publisher = $xml->Items->Item->ItemAttributes->Publisher;
262 echo $pubDate; 259 restore_error_handler();
263 echo $publisher;*/ 260 /*echo $title;
264 261 echo $author;
265 $genreID = ""; 262 echo $binding;
266 $genre = ""; 263 echo $dewey;
267 $genArr = array(); 264 echo $imageURL;
268 $g1 = "null"; 265 echo $salesRank;
269 $g2 = "null"; 266 echo $pubDate;
270 $g3 = "null"; 267 echo $publisher;*/
271 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ 268
272 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ 269 $genreID = "";
273 //sexy recursive function 270 $genre = "";
274 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); 271 $genArr = array();
275 272 $g1 = "null";
276 if($genre != "") 273 $g2 = "null";
277 $genArr[strval($genreID)] = strval($genre); 274 $g3 = "null";
278 //$genArr[$i] = array(strval($genreID) => strval($genre)); 275 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){
279 276 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){
280 //echo $genre; 277 //sexy recursive function
281 //echo $genreID; 278 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
282 279
283 $genre = ""; 280 if($genre != "")
284 $genreID = ""; 281 $genArr[strval($genreID)] = strval($genre);
285 } 282 //$genArr[$i] = array(strval($genreID) => strval($genre));
286 283
287 $g1 = "null"; 284 //echo $genre;
288 $g2 = "null"; 285 //echo $genreID;
289 $g3 = "null"; 286
290 $loop = 1; 287 $genre = "";
291 288 $genreID = "";
292 foreach ($genArr as $key => $value) { 289 }
293 //echo "$key => $value"; 290
294 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table 291 $g1 = "null";
295 //echo $queryG; 292 $g2 = "null";
296 $resG = mysqli_query($link, $queryG); 293 $g3 = "null";
297 294 $loop = 1;
298 switch ($loop) { 295
299 case 1: 296 foreach ($genArr as $key => $value) {
300 $g1 = $key; 297 //echo "$key => $value";
301 break; 298 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table
302 case 2: 299 //echo $queryG;
303 $g2 = $key; 300 $resG = mysqli_query($link, $queryG);
304 break; 301
305 case 3: 302 switch ($loop) {
306 $g3 = $key; 303 case 1:
307 break; 304 $g1 = $key;
308 } 305 break;
309 306 case 2:
310 $loop++; 307 $g2 = $key;
311 } 308 break;
312 } 309 case 3:
313 310 $g3 = $key;
314 if($salesRank == "") 311 break;
315 $salesRank = "null"; 312 }
316 313
317 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop 314 $loop++;
318 include "../../../private/db.php"; 315 }
319 316 }
320 $title = strtr($title, '"', "'"); 317
321 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; 318 if($salesRank == "")
322 //echo $queryInsert; 319 $salesRank = "null";
323 320
324 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); 321 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
325 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop 322 include "../../../private/db.php";
326 323
327 324 $title = strtr($title, '"', "'");
328 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; 325 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";
329 $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; 326 //echo $queryInsert;
330 $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; 327
331 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; 328 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
332 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; 329 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
333 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; 330
334 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; 331
335 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; 332 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
336 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; 333 $output .= "<Title>" . htmlspecialchars($title) . "</Title>";
337 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; 334 $output .= "<Author>" . htmlspecialchars($author) . "</Author>";
338 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; 335 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>";
339 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; 336 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
340 $output .= "<ProductGroup>Book</ProductGroup>"; 337 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
338 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
339 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
340 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
341 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
342 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
343 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";
344 $output .= "<ProductGroup>Book</ProductGroup>";
341 } 345 }
342 } 346 }
343 347
344 $output .= "</BookDetails>"; 348 $output .= "</BookDetails>";
345 349