Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //LOADER
- require 'aws-autoloader.php'; //Autoloader SDK
- use Aws\Common\Aws; //Utilizar SDK
- date_default_timezone_set("UTC"); //Horario UTC
- //ENTORNO
- ignore_user_abort(1); //Ejecutar aunque el usuario aborte
- set_time_limit(0); //Sin tiempo maximo de ejecucion
- ini_set('memory_limit', '1024M'); //1024MB RAM
- header("Cache-Control: no-cache, must-revalidate"); //Sin Cache
- //Declaracion datetime de hoy
- $ano = date('Y-m-d');
- $hora = date('H:i:s');
- $fecha = $ano.'T'.$hora.'Z';
- //ENDPOINTS
- $endpointsearch = 'search-domain-1-j5q2iblypdnqlllc3l3s4t6izi.eu-west-1.cloudsearch.amazonaws.com';
- $endpointupload = 'doc-domain-1-j5q2iblypdnqlllc3l3s4t6izi.eu-west-1.cloudsearch.amazonaws.com';
- // AWS Service Builder
- $aws = Aws::factory('config.php');
- //Inicializamos los clientes
- //$cloudsearch = $aws->get('CloudSearch');
- $cloudsearchdomainse = $aws->get('CloudSearchDomain', array('endpoint' => $endpointsearch));
- $cloudsearchdomainup = $aws->get('CloudSearchDomain', array('endpoint' => $endpointupload));
- echo '<h2>SEARCH</h2>';
- //Search documento a la API
- $result = $cloudsearchdomainse->search(array('query' => 'matchall', 'queryParser' => 'structured', 'size' => 10000));
- foreach ($result["hits"]["hit"] as $hit)
- {
- echo 'añadiendo ID <b>'.$hit['id'].'</b>...<br>';
- $final .= '<delete id="'.$hit['id'].'" />';
- //Generamos y enviamos batch
- if (strlen($final) >= 4800000)
- {
- $final = '<batch>'.$final.'</batch>';
- $result = $cloudsearchdomainup->uploadDocuments(array('documents' => $final, 'contentType' => 'application/xml'));
- $final = '';
- echo 'Generando BATCH...<br>';
- //Debug
- echo '<pre>';
- print_r($final);
- echo '</pre><hr>';
- echo '<pre>';
- print_r($result);
- echo '</pre><hr>';
- }
- }
- //Restos
- if ($final != '')
- {
- $final = '<batch>'.$final.'</batch>';
- $result = $cloudsearchdomainup->uploadDocuments(array('documents' => $final, 'contentType' => 'application/xml'));
- //Debug
- echo '<pre>';
- print_r($final);
- echo '</pre><hr>';
- echo '<pre>';
- print_r($result);
- echo '</pre><hr>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement