Skip to content

Commit 2b3833f

Browse files
committed
Tabs, Indentation and brackets
1 parent e9e42c4 commit 2b3833f

File tree

1 file changed

+101
-101
lines changed

1 file changed

+101
-101
lines changed

facetwp-wp-cli.php

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,118 +18,118 @@
1818
namespace WP_Facet;
1919

2020
if ( !defined ('WP_CLI') )
21-
return;
21+
return;
2222

2323
use WP_CLI;
2424
use WP_CLI_Command;
2525
use WP_Query;
2626

2727
class CLI extends WP_CLI_Command {
2828

29-
/**
30-
* Indexes all posts
31-
*
32-
* ## OPTIONS
33-
* [--post-type=<name>]
34-
* : post type, 'any' if not defined
35-
*
36-
* [--start-at-page=<number>]
37-
* : pagenumber to start indexing, 1 if not defined
38-
*
39-
* ## EXAMPLES
40-
*
41-
* wp facet index
42-
* wp facet index --post-type=product
43-
* wp facet index --start-at-page=7
44-
*
45-
* @synopsis
46-
*/
47-
function index( $args, $assoc_args ) {
48-
if ( ! defined( 'WP_IMPORTING' ) ) {
49-
define('WP_IMPORTING', true);
50-
}
51-
52-
if( ! function_exists('FWP')){
53-
WP_CLI::error( 'FacetWP plugin is not activated.' );
54-
}
55-
56-
wp_suspend_cache_addition( true );
57-
58-
$post_type = 'any';
59-
if ( ! empty( $assoc_args['post-type'] ) ) {
60-
$post_type = $assoc_args['post-type'];
61-
}
62-
63-
$page = 1;
64-
if ( ! empty( $assoc_args['start-at-page'] ) ) {
65-
$page = $assoc_args['start-at-page'];
66-
}
67-
$posts_per_page = 100;
68-
69-
$args = array(
70-
'posts_per_page' => $posts_per_page,
71-
'paged' => $page,
72-
'post_type' => $post_type,
73-
'post_status' => 'publish',
74-
'fields' => 'ids',
75-
'orderby' => 'ID',
76-
'cache_results' => false,
77-
);
78-
79-
$total = 0;
80-
81-
$args['paged'] = $page;
82-
$my_query = new WP_Query( $args );
83-
84-
$total = $my_query->found_posts;
85-
WP_CLI::line( 'Found '.$total.' posts of type "'.$post_type.'"' );
86-
$progress_bar = WP_CLI\Utils\make_progress_bar('Indexing', $total, 1000 );
87-
do {
88-
$args['paged'] = $page;
89-
$my_query = new WP_Query( $args );
90-
WP_CLI::line( 'Starting indexing of page ' . $page . '.' );
91-
if ($my_query->have_posts())
92-
{
93-
foreach ( $my_query->posts as $post_id ) {
94-
$progress_bar->tick();
95-
FWP()->indexer->index( $post_id );
96-
}
97-
98-
$this->stop_the_insanity();
99-
WP_CLI::line( 'Finished indexing page ' . $page . '.' );
100-
$page++;
101-
}
102-
103-
104-
} while ( $my_query->have_posts() );
105-
106-
if ($total > 0)
107-
{
108-
$progress_bar->finish();
109-
WP_CLI::success( 'All posts indexed' );
110-
} else {
111-
WP_CLI::error( 'No posts of type "'.$post_type.'" found!' );
29+
/**
30+
* Indexes all posts
31+
*
32+
* ## OPTIONS
33+
* [--post-type=<name>]
34+
* : post type, 'any' if not defined
35+
*
36+
* [--start-at-page=<number>]
37+
* : pagenumber to start indexing, 1 if not defined
38+
*
39+
* ## EXAMPLES
40+
*
41+
* wp facet index
42+
* wp facet index --post-type=product
43+
* wp facet index --start-at-page=7
44+
*
45+
* @synopsis
46+
*/
47+
function index( $args, $assoc_args ) {
48+
if ( ! defined( 'WP_IMPORTING' ) ) {
49+
define('WP_IMPORTING', true);
50+
}
51+
52+
if( ! function_exists('FWP')){
53+
WP_CLI::error( 'FacetWP plugin is not activated.' );
54+
}
55+
56+
wp_suspend_cache_addition( true );
57+
58+
$post_type = 'any';
59+
if ( ! empty( $assoc_args['post-type'] ) ) {
60+
$post_type = $assoc_args['post-type'];
61+
}
62+
63+
$page = 1;
64+
if ( ! empty( $assoc_args['start-at-page'] ) ) {
65+
$page = $assoc_args['start-at-page'];
66+
}
67+
$posts_per_page = 100;
68+
69+
$args = array(
70+
'posts_per_page' => $posts_per_page,
71+
'paged' => $page,
72+
'post_type' => $post_type,
73+
'post_status' => 'publish',
74+
'fields' => 'ids',
75+
'orderby' => 'ID',
76+
'cache_results' => false,
77+
);
78+
79+
$total = 0;
80+
81+
$args['paged'] = $page;
82+
$my_query = new WP_Query( $args );
83+
84+
$total = $my_query->found_posts;
85+
WP_CLI::line( 'Found '.$total.' posts of type "'.$post_type.'"' );
86+
$progress_bar = WP_CLI\Utils\make_progress_bar('Indexing', $total, 1000 );
87+
do {
88+
$args['paged'] = $page;
89+
$my_query = new WP_Query( $args );
90+
WP_CLI::line( 'Starting indexing of page ' . $page . '.' );
91+
if ($my_query->have_posts())
92+
{
93+
foreach ( $my_query->posts as $post_id ) {
94+
$progress_bar->tick();
95+
FWP()->indexer->index( $post_id );
96+
}
97+
98+
$this->stop_the_insanity();
99+
WP_CLI::line( 'Finished indexing page ' . $page . '.' );
100+
$page++;
101+
}
102+
103+
104+
} while ( $my_query->have_posts() );
105+
106+
if ($total > 0) {
107+
$progress_bar->finish();
108+
WP_CLI::success( 'All posts indexed' );
109+
} else {
110+
WP_CLI::error( 'No posts of type "'.$post_type.'" found!' );
111+
}
112112
}
113-
}
114113

115-
/**
114+
/**
116115
* Clear all of the caches for memory management
117116
*/
118-
protected function stop_the_insanity() {
119-
global $wpdb, $wp_object_cache, $wp_actions;
120-
$wpdb->queries = array();
121-
$wp_actions = array();
122-
wp_cache_flush();
123-
if ( !is_object( $wp_object_cache ) ){
124-
return;
125-
}
126-
$wp_object_cache->group_ops = array();
127-
$wp_object_cache->stats = array();
128-
$wp_object_cache->memcache_debug = array();
129-
$wp_object_cache->cache = array();
130-
if ( is_callable( $wp_object_cache, '__remoteset' ) )
131-
$wp_object_cache->__remoteset();
132-
}
117+
protected function stop_the_insanity() {
118+
global $wpdb, $wp_object_cache, $wp_actions;
119+
$wpdb->queries = array();
120+
$wp_actions = array();
121+
wp_cache_flush();
122+
if ( !is_object( $wp_object_cache ) ){
123+
return;
124+
}
125+
$wp_object_cache->group_ops = array();
126+
$wp_object_cache->stats = array();
127+
$wp_object_cache->memcache_debug = array();
128+
$wp_object_cache->cache = array();
129+
if ( is_callable( $wp_object_cache, '__remoteset' ) ){
130+
$wp_object_cache->__remoteset();
131+
}
132+
}
133133

134134
}
135135

0 commit comments

Comments
 (0)