PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.9
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Core / Migration.php

Migration.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.5.9, at includes/Core/Migration.php

110 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Core;
4
5 use WP_Query;
6 use WPDeveloper\BetterDocs\Utils\Base;
7 use WPDeveloper\BetterDocs\Utils\Database;
8 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
9
10 class Migration extends Base {
11 /**
12 * Database
13 * @var Database
14 */
15 private $database;
16 private $settings;
17 private $container;
18
19 public function __construct( Container $container ) {
20 $this->container = $container;
21 $this->database = $container->get( Database::class );
22 $this->settings = $container->get( Settings::class );
23 }
24
25 public function init( $version ) {
26 if( $version > 250 ) {
27 for( $_version = 250; $_version <= $version; $_version++ ) {
28 if( method_exists( $this, "v$_version") ) {
29 call_user_func([$this, "v$_version"]);
30 }
31 }
32 }
33
34 $this->search_migration();
35
36 /**
37 * Settings Migration
38 */
39 $this->settings->migration( $version );
40 }
41
42 public function search_migration() {
43 global $wpdb;
44 if ( ! $this->database->get( 'betterdocs_search_data_migration', false ) ) {
45 $search_data = $this->database->get( 'betterdocs_search_data' );
46 if ( ! empty( $search_data ) ) {
47 $search_data_arr = unserialize( $search_data );
48 foreach ( $search_data_arr as $key => $value ) {
49 $args = [
50 'post_type' => 'docs',
51 'post_status' => 'publish',
52 'posts_per_page' => -1,
53 'suppress_filters' => true,
54 's' => $key
55 ];
56
57 $loop = new WP_Query( $args );
58 if ( $loop->have_posts() ) {
59 $count = $value;
60 $not_found_count = 0;
61 } else {
62 $count = 0;
63 $not_found_count = $value;
64 }
65
66 $keyword = $wpdb->get_var(
67 $wpdb->prepare( "
68 SELECT keyword
69 FROM {$wpdb->prefix}betterdocs_search_keyword
70 WHERE keyword = %s",
71 $key
72 )
73 );
74
75 if ( $keyword == NUll ) {
76 $insert = $wpdb->query(
77 $wpdb->prepare(
78 "INSERT INTO {$wpdb->prefix}betterdocs_search_keyword
79 ( keyword )
80 VALUES ( %s )",
81 [
82 $key
83 ]
84 )
85 );
86
87 if ( $insert ) {
88 $wpdb->query(
89 $wpdb->prepare(
90 "INSERT INTO {$wpdb->prefix}betterdocs_search_log
91 (keyword_id, count, not_found_count, created_at)
92 VALUES (%d, %d, %d, %s)",
93 [
94 $wpdb->insert_id,
95 $count,
96 $not_found_count,
97 date( 'Y-m-d' )
98 ]
99 )
100 );
101 }
102 }
103 }
104
105 $this->database->save( 'betterdocs_search_data_migration', '1.0' );
106 }
107 }
108 }
109 }
110