Changeset 93515 in spip-zone
- Timestamp:
- Dec 10, 2015, 12:13:55 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/indexer/trunk/inc/indexer.php
r93457 r93515 336 336 return $sug; 337 337 } 338 339 /* 340 * faire un DUMP SQL de notre base sphinx 341 * dest: fichier destination (null: stdout) 342 * bloc : nombre d'enregistrements a rapatrier a chaque tour (maximum 1000) 343 * usage : 344 include_spip('inc/indexer'); 345 indexer_dumpsql(); 346 // indexer_dumpsql('tmp/indexer.sql', 1000); 347 */ 348 function indexer_dumpsql($dest = null, $bloc = 100) { 349 if (is_null($dest)) 350 $dest = 'php://stdout'; 351 352 $fp = fopen($dest,'w'); 353 if (!$fp) { 354 spip_log('Impossible d ouvrir '.$dest, 'indexer'); 355 return false; 356 } 357 358 $sphinx = new Sphinx\SphinxQL\SphinxQL(SPHINX_SERVER_HOST, SPHINX_SERVER_PORT); 359 360 361 $version = unserialize(lire_meta('plugin')); 362 $version = $version['INDEXER']['version']; 363 364 $index = SPHINX_DEFAULT_INDEX; 365 366 $comm = '# SPIP indexer / SphinxQL Dump 367 # version '. $version .' 368 # http://contrib.spip.net/Indexer 369 # 370 # Host: '.SPHINX_SERVER_HOST.':'.SPHINX_SERVER_PORT.' 371 # Generation Time: '.date(DATE_ISO8601).' 372 # Server version: (unknown) 373 # PHP Version: '. phpversion() .' 374 # 375 # Database : `'. $index .'` 376 # 377 378 '; 379 380 381 $query = "DESC ".$index; 382 $all = $sphinx->allfetsel($query); 383 384 if (isset($all['query']['docs'])) { 385 $comm .= '# -------------------------------------------------------- 386 387 # 388 # Table structure for table `' . $index . '` 389 # 390 391 CREATE TABLE `' . $index . '` ( 392 '; 393 $fields = []; 394 foreach($all['query']['docs'] as $doc) { 395 $fields[] = "\t" . '`' . $doc['Field'] .'` ' . $doc['Type']; 396 } 397 $comm .= join(",\n", $fields); 398 $comm .= " 399 ) 400 401 402 # 403 # Dumping data for table `" . $index . "` 404 # 405 406 "; 407 } 408 409 if (!fwrite($fp, $comm)) { 410 spip_log('Impossible d ecrire dans '.$dest, 'indexer'); 411 return false; 412 } 413 414 do { 415 416 $where = isset($begin) ? " WHERE id > $begin " : ''; 417 $query = "SELECT * FROM " . $index . $where . " ORDER BY id ASC LIMIT 0,$bloc"; 418 419 $all = $sphinx->allfetsel($query); 420 $cdocs = count($all['query']['docs']); 421 if ($cdocs > 0) { 422 foreach($all['query']['docs'] as $doc) { 423 $sql = 'INSERT INTO ' . $index . ' (' 424 . join(', ', array_keys($doc)) 425 . ') VALUES (' 426 . join(', ', array_map('_q', $doc)) 427 . ');' . "\n"; 428 429 if (!fwrite($fp, $sql)) { 430 spip_log('Impossible d ecrire dans '.$dest, 'indexer'); 431 return false; 432 } 433 } 434 $begin = $all['query']['docs'][$cdocs-1]['id']; 435 } 436 } while ($cdocs > 0); 437 438 if ($fp) fclose($fp); 439 return true; 440 }
Note: See TracChangeset
for help on using the changeset viewer.