@@ -6,136 +6,136 @@ |
||
| 6 | 6 | class Analysis_Background_Service { |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache'; |
|
| 10 | - const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count'; |
|
| 11 | - const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache'; |
|
| 9 | + const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache'; |
|
| 10 | + const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count'; |
|
| 11 | + const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache'; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var Analysis_Service |
|
| 15 | - */ |
|
| 16 | - private $analysis_service; |
|
| 17 | - /** |
|
| 18 | - * @var Analysis_Background_Process |
|
| 19 | - */ |
|
| 20 | - private $analysis_background_process; |
|
| 13 | + /** |
|
| 14 | + * @var Analysis_Service |
|
| 15 | + */ |
|
| 16 | + private $analysis_service; |
|
| 17 | + /** |
|
| 18 | + * @var Analysis_Background_Process |
|
| 19 | + */ |
|
| 20 | + private $analysis_background_process; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var \Wordlift_Log_Service |
|
| 24 | - */ |
|
| 25 | - private $log; |
|
| 22 | + /** |
|
| 23 | + * @var \Wordlift_Log_Service |
|
| 24 | + */ |
|
| 25 | + private $log; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function __construct( $analysis_service ) { |
|
| 28 | + public function __construct( $analysis_service ) { |
|
| 29 | 29 | |
| 30 | - $this->analysis_service = $analysis_service; |
|
| 30 | + $this->analysis_service = $analysis_service; |
|
| 31 | 31 | |
| 32 | - $this->analysis_background_process = new Analysis_Background_Process( $this ); |
|
| 32 | + $this->analysis_background_process = new Analysis_Background_Process( $this ); |
|
| 33 | 33 | |
| 34 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 35 | - } |
|
| 34 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function start() { |
|
| 38 | - $this->analysis_background_process->start(); |
|
| 39 | - } |
|
| 37 | + public function start() { |
|
| 38 | + $this->analysis_background_process->start(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function cancel() { |
|
| 42 | - $this->analysis_background_process->cancel(); |
|
| 43 | - } |
|
| 41 | + public function cancel() { |
|
| 42 | + $this->analysis_background_process->cancel(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function stop() { |
|
| 46 | - $this->analysis_background_process->cancel(); |
|
| 47 | - $this->analysis_background_process->request_cancel(); |
|
| 48 | - } |
|
| 45 | + public function stop() { |
|
| 46 | + $this->analysis_background_process->cancel(); |
|
| 47 | + $this->analysis_background_process->request_cancel(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * A list of term ids. |
|
| 52 | - * @return int|\WP_Error|\WP_Term[] |
|
| 53 | - */ |
|
| 54 | - public function next() { |
|
| 50 | + /** |
|
| 51 | + * A list of term ids. |
|
| 52 | + * @return int|\WP_Error|\WP_Term[] |
|
| 53 | + */ |
|
| 54 | + public function next() { |
|
| 55 | 55 | |
| 56 | - $state = $this->info(); |
|
| 56 | + $state = $this->info(); |
|
| 57 | 57 | |
| 58 | - return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array( |
|
| 59 | - 'fields' => 'ids', |
|
| 60 | - 'hide_empty' => false, |
|
| 61 | - 'number' => $this->get_batch_size(), |
|
| 58 | + return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array( |
|
| 59 | + 'fields' => 'ids', |
|
| 60 | + 'hide_empty' => false, |
|
| 61 | + 'number' => $this->get_batch_size(), |
|
| 62 | 62 | // 'offset' => $state->index, |
| 63 | - 'meta_query' => array( |
|
| 64 | - array( |
|
| 65 | - 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 66 | - 'compare' => 'NOT EXISTS' |
|
| 67 | - ) |
|
| 68 | - ), |
|
| 69 | - ) ); |
|
| 70 | - } |
|
| 63 | + 'meta_query' => array( |
|
| 64 | + array( |
|
| 65 | + 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 66 | + 'compare' => 'NOT EXISTS' |
|
| 67 | + ) |
|
| 68 | + ), |
|
| 69 | + ) ); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function count() { |
|
| 72 | + public function count() { |
|
| 73 | 73 | |
| 74 | - $count = count( Terms_Compat::get_terms( |
|
| 75 | - Terms_Compat::get_public_taxonomies(), |
|
| 76 | - array( |
|
| 77 | - 'fields' => 'ids', |
|
| 78 | - 'hide_empty' => false, |
|
| 79 | - // return all terms, we cant pass -1 here. |
|
| 80 | - 'number' => 0, |
|
| 81 | - 'meta_query' => array( |
|
| 82 | - array( |
|
| 83 | - 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 84 | - 'compare' => 'NOT EXISTS' |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - ) ) ); |
|
| 74 | + $count = count( Terms_Compat::get_terms( |
|
| 75 | + Terms_Compat::get_public_taxonomies(), |
|
| 76 | + array( |
|
| 77 | + 'fields' => 'ids', |
|
| 78 | + 'hide_empty' => false, |
|
| 79 | + // return all terms, we cant pass -1 here. |
|
| 80 | + 'number' => 0, |
|
| 81 | + 'meta_query' => array( |
|
| 82 | + array( |
|
| 83 | + 'key' => self::ANALYSIS_DONE_FLAG, |
|
| 84 | + 'compare' => 'NOT EXISTS' |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + ) ) ); |
|
| 88 | 88 | |
| 89 | - $this->log->debug( "Count returned as $count" ); |
|
| 89 | + $this->log->debug( "Count returned as $count" ); |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | - return $count; |
|
| 93 | - } |
|
| 92 | + return $count; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function get_batch_size() { |
|
| 96 | - return 10; |
|
| 97 | - } |
|
| 95 | + public function get_batch_size() { |
|
| 96 | + return 10; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function info() { |
|
| 100 | - return Analysis_Background_Process::get_state(); |
|
| 101 | - } |
|
| 99 | + public function info() { |
|
| 100 | + return Analysis_Background_Process::get_state(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @param $term_ids |
|
| 105 | - * |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public function perform_analysis_for_terms( $term_ids ) { |
|
| 103 | + /** |
|
| 104 | + * @param $term_ids |
|
| 105 | + * |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public function perform_analysis_for_terms( $term_ids ) { |
|
| 109 | 109 | |
| 110 | - foreach ( $term_ids as $term_id ) { |
|
| 110 | + foreach ( $term_ids as $term_id ) { |
|
| 111 | 111 | |
| 112 | - $tag = get_term( $term_id ); |
|
| 112 | + $tag = get_term( $term_id ); |
|
| 113 | 113 | |
| 114 | - // This adds the entities to ttl cache |
|
| 115 | - $result = $this->analysis_service->get_entities( $tag ); |
|
| 114 | + // This adds the entities to ttl cache |
|
| 115 | + $result = $this->analysis_service->get_entities( $tag ); |
|
| 116 | 116 | |
| 117 | - $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" ); |
|
| 117 | + $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" ); |
|
| 118 | 118 | |
| 119 | - // then set the analysis complete flag. |
|
| 120 | - update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 ); |
|
| 119 | + // then set the analysis complete flag. |
|
| 120 | + update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 ); |
|
| 121 | 121 | |
| 122 | - if ( $result !== false ) { |
|
| 123 | - if ( count( $result ) > 0 ) { |
|
| 124 | - update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 ); |
|
| 125 | - } |
|
| 126 | - } |
|
| 122 | + if ( $result !== false ) { |
|
| 123 | + if ( count( $result ) > 0 ) { |
|
| 124 | + update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 ); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * This action fires when the analysis is complete for the current batch |
|
| 132 | - * @since 3.30.0 |
|
| 133 | - */ |
|
| 134 | - do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' ); |
|
| 130 | + /** |
|
| 131 | + * This action fires when the analysis is complete for the current batch |
|
| 132 | + * @since 3.30.0 |
|
| 133 | + */ |
|
| 134 | + do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' ); |
|
| 135 | 135 | |
| 136 | - return true; |
|
| 136 | + return true; |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | \ No newline at end of file |