improvements on detect encode and WP-Cli #245

This commit is contained in:
vnmedeiros 2019-09-11 23:53:47 -03:00
parent 005a304edb
commit dbec21d502
2 changed files with 16 additions and 8 deletions

View File

@ -260,7 +260,11 @@ class Media {
try {
$PDF2Text->decodePDF();
$content = preg_replace('~[[:cntrl:]]~', '', $PDF2Text->output());
$content = mb_convert_encoding($content, 'UTF-8', 'ISO-8859-1');
$wp_charset = get_bloginfo('charset');
$content_charset = mb_detect_encoding($content);
$content = mb_convert_encoding($content, $wp_charset, $content_charset);
$meta_id = update_post_meta( $item_id, $content_index_meta, $content );
} catch(Exception $e) {
error_log('Caught exception: ' . $e->getMessage() . "\n");

View File

@ -22,8 +22,8 @@ class Cli_Document {
* index content of documents
*
* ## OPTIONS
* [--collection-id=<value>]
* : <value> Specific ID of the collection into which the document content of the items will be indexed, if not informed all collections will be index.
* [--collection=<value>]
* : <value> Specific ID of the collection into which the document content of the items will be indexed, or 'all' to all collections.
*
*
* [--dry-run]
@ -31,13 +31,13 @@ class Cli_Document {
*
* ## EXAMPLES
*
* wp tainacan index-content --collection-id=416
* wp tainacan index-content --collection=416
* indexing documents of items to collection 416: 100% [====================================================] 0:00 / 0:00
* Success:
* 7 items indexed
*
*
* wp tainacan index-content
* wp tainacan index-content --collection=all
* indexing documents of items to collection 416: 100% [====================================================] 0:00 / 0:00
* Success:
* 7 items indexed
@ -52,11 +52,15 @@ class Cli_Document {
$this->dry_run = true;
}
if( empty($assoc_args['collection-id']) ) {
if( empty($assoc_args['collection']) ) {
\WP_CLI::error( 'Wrong parameters', true );
}
$collection = $assoc_args['collection'];
if ($collection == 'all') {
$this->index_item_all_collections();
} else {
$collection_id = $assoc_args['collection-id'];
$this->index_item($collection_id);
$this->index_item($collection);
}
}