Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <?php
  2. //LOADER
  3. require 'aws-autoloader.php'; //Autoloader SDK
  4. use Aws\Common\Aws; //Utilizar SDK
  5. date_default_timezone_set("UTC"); //Horario UTC
  6.  
  7. //ENTORNO
  8. ignore_user_abort(1); //Ejecutar aunque el usuario aborte
  9. set_time_limit(0); //Sin tiempo maximo de ejecucion
  10. ini_set('memory_limit', '1024M'); //1024MB RAM
  11. header("Cache-Control: no-cache, must-revalidate"); //Sin Cache
  12.  
  13. //Declaracion datetime de hoy
  14. $ano = date('Y-m-d');
  15. $hora = date('H:i:s');
  16. $fecha = $ano.'T'.$hora.'Z';
  17.  
  18. //ENDPOINTS
  19. $endpointsearch = 'search-domain-1-j5q2iblypdnqlllc3l3s4t6izi.eu-west-1.cloudsearch.amazonaws.com';
  20. $endpointupload = 'doc-domain-1-j5q2iblypdnqlllc3l3s4t6izi.eu-west-1.cloudsearch.amazonaws.com';
  21.  
  22. // AWS Service Builder
  23. $aws = Aws::factory('config.php');
  24.  
  25. //Inicializamos los clientes
  26. //$cloudsearch = $aws->get('CloudSearch');
  27. $cloudsearchdomainse = $aws->get('CloudSearchDomain', array('endpoint' => $endpointsearch));
  28. $cloudsearchdomainup = $aws->get('CloudSearchDomain', array('endpoint' => $endpointupload));
  29.  
  30. echo '<h2>SEARCH</h2>';
  31.  
  32. //Search documento a la API
  33. $result = $cloudsearchdomainse->search(array('query' => 'matchall', 'queryParser' => 'structured', 'size' => 10000));
  34.  
  35. foreach ($result["hits"]["hit"] as $hit)
  36. {
  37. echo 'añadiendo ID <b>'.$hit['id'].'</b>...<br>';
  38. $final .= '<delete id="'.$hit['id'].'" />';
  39. //Generamos y enviamos batch
  40. if (strlen($final) >= 4800000)
  41. {
  42. $final = '<batch>'.$final.'</batch>';
  43. $result = $cloudsearchdomainup->uploadDocuments(array('documents' => $final, 'contentType' => 'application/xml'));
  44. $final = '';
  45. echo 'Generando BATCH...<br>';
  46.  
  47. //Debug
  48. echo '<pre>';
  49. print_r($final);
  50. echo '</pre><hr>';
  51. echo '<pre>';
  52. print_r($result);
  53. echo '</pre><hr>';
  54. }
  55. }
  56.  
  57. //Restos
  58. if ($final != '')
  59. {
  60. $final = '<batch>'.$final.'</batch>';
  61. $result = $cloudsearchdomainup->uploadDocuments(array('documents' => $final, 'contentType' => 'application/xml'));
  62. //Debug
  63. echo '<pre>';
  64. print_r($final);
  65. echo '</pre><hr>';
  66. echo '<pre>';
  67. print_r($result);
  68. echo '</pre><hr>';
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement