Completed
Pull Request — develop (#1707)
by
unknown
01:24
created
src/install/class-wordlift-install-service.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -18,201 +18,201 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Install_Service {
20 20
 
21
-	/**
22
-	 * A {@link Wordlift_Log_Service} instance.
23
-	 *
24
-	 * @since  3.18.0
25
-	 * @access private
26
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
-	 */
28
-	private $log;
29
-
30
-	/**
31
-	 * The singleton instance.
32
-	 *
33
-	 * @since  3.18.0
34
-	 * @access private
35
-	 * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
-	 */
37
-	private static $instance;
38
-
39
-	/**
40
-	 * @var array
41
-	 */
42
-	private $installs;
43
-
44
-	/**
45
-	 * Wordlift_Install_Service constructor.
46
-	 *
47
-	 * @since 3.18.0
48
-	 */
49
-	public function __construct() {
50
-
51
-		/** Installs. */
52
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
76
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-2.php';
77
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-41-0.php';
78
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-42-0.php';
79
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-1.php';
80
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-4.php';
81
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-0.php';
82
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-1.php';
83
-		require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-50-1.php';
84
-
85
-		// Get the install services.
86
-		$this->installs = array(
87
-			new Wordlift_Install_1_0_0(),
88
-			new Wordlift_Install_3_10_0(),
89
-			new Wordlift_Install_3_12_0(),
90
-			new Wordlift_Install_3_14_0(),
91
-			new Wordlift_Install_3_15_0(),
92
-			new Wordlift_Install_3_18_0(),
93
-			new Wordlift_Install_3_18_3(),
94
-			new Wordlift_Install_3_19_5(),
95
-			new Wordlift_Install_3_20_0(),
96
-
97
-			/*
21
+    /**
22
+     * A {@link Wordlift_Log_Service} instance.
23
+     *
24
+     * @since  3.18.0
25
+     * @access private
26
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
+     */
28
+    private $log;
29
+
30
+    /**
31
+     * The singleton instance.
32
+     *
33
+     * @since  3.18.0
34
+     * @access private
35
+     * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
+     */
37
+    private static $instance;
38
+
39
+    /**
40
+     * @var array
41
+     */
42
+    private $installs;
43
+
44
+    /**
45
+     * Wordlift_Install_Service constructor.
46
+     *
47
+     * @since 3.18.0
48
+     */
49
+    public function __construct() {
50
+
51
+        /** Installs. */
52
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install.php';
53
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-1-0-0.php';
54
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-10-0.php';
55
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-12-0.php';
56
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-14-0.php';
57
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-15-0.php';
58
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-0.php';
59
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-18-3.php';
60
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-19-5.php';
61
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-20-0.php';
62
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-23-4.php';
63
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-24-2.php';
64
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-all-entity-types.php';
65
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-package-type.php';
66
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-25-0.php';
67
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-0.php';
68
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-27-1.php';
69
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-28-0.php';
70
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-32-0.php';
71
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-33-9.php';
72
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-36-0.php';
73
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-38-5.php';
74
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-39-1.php';
75
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-1.php';
76
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-40-2.php';
77
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-41-0.php';
78
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-42-0.php';
79
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-1.php';
80
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-44-4.php';
81
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-0.php';
82
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-45-1.php';
83
+        require_once plugin_dir_path( __DIR__ ) . 'install/class-wordlift-install-3-50-1.php';
84
+
85
+        // Get the install services.
86
+        $this->installs = array(
87
+            new Wordlift_Install_1_0_0(),
88
+            new Wordlift_Install_3_10_0(),
89
+            new Wordlift_Install_3_12_0(),
90
+            new Wordlift_Install_3_14_0(),
91
+            new Wordlift_Install_3_15_0(),
92
+            new Wordlift_Install_3_18_0(),
93
+            new Wordlift_Install_3_18_3(),
94
+            new Wordlift_Install_3_19_5(),
95
+            new Wordlift_Install_3_20_0(),
96
+
97
+            /*
98 98
 			 * This should be enabled with #852.
99 99
 			 */
100
-			new Wordlift_Install_Package_Type(),
101
-			new Wordlift_Install_3_23_4(),
102
-			new Wordlift_Install_3_24_2(),
103
-			new Wordlift_Install_3_25_0(),
104
-			new Wordlift_Install_3_27_0(),
105
-			new Wordlift_Install_3_27_1(),
106
-			new Wordlift_Install_3_28_0(),
107
-			// Add column to represent term
108
-			new Wordlift_Install_3_32_0(),
109
-			// Add the entities table.
110
-			new Wordlift_Install_3_33_9(),
111
-			// When woocommerce extension installed, acf4so should be installed automatically.
112
-			new Wordlift_Install_3_36_0(),
113
-
114
-			new Wordlift_Install_3_38_5(),
115
-			new Wordlift_Install_3_39_1(),
116
-
117
-			// See #1621.
118
-			new Wordlift_Install_3_40_1(),
119
-
120
-			// @link https://github.com/insideout10/wordlift-plugin/issues/1627
121
-			new Wordlift_Install_3_40_2(),
122
-
123
-			new Wordlift_Install_3_41_0(),
124
-			new Wordlift_Install_3_42_0(),
125
-
126
-			new Wordlift_Install_3_44_1(),
127
-			new Wordlift_Install_3_44_4(),
128
-
129
-			new Wordlift_Install_3_45_0(),
130
-			new Wordlift_Install_3_45_1(),
131
-
132
-			new Wordlift_Install_3_50_1(),
133
-		);
134
-		self::$instance = $this;
135
-
136
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
137
-
138
-		add_action( 'init', array( $this, 'install' ) );
139
-
140
-	}
141
-
142
-	/**
143
-	 * Get the singleton instance.
144
-	 *
145
-	 * @since 3.18.0
146
-	 */
147
-	public static function get_instance() {
148
-
149
-		return self::$instance;
150
-	}
151
-
152
-	/**
153
-	 * Loop thought all versions and install the updates.
154
-	 *
155
-	 * @return void
156
-	 * @since 3.18.0
157
-	 *
158
-	 * @since 3.20.0 use a transient to avoid concurrent installation calls.
159
-	 */
160
-	public function install() {
161
-
162
-		$version = null;
163
-
164
-		if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
165
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
166
-			/** @var Wordlift_Install $install */
167
-			foreach ( $this->installs as $install ) {
168
-				// Get the install version.
169
-				$version = $install->get_version();
170
-
171
-				if ( version_compare( $version, $this->get_current_version(), '>' )
172
-				     || $install->must_install() ) {
173
-					$class_name = get_class( $install );
174
-
175
-					$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
176
-					// Install version.
177
-					$install->install();
178
-
179
-					$this->log->info( "$class_name installed." );
180
-
181
-					// Bump the version.
182
-					update_option( 'wl_db_version', $version );
183
-				}
184
-			}
185
-
186
-			// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
187
-			@delete_transient( '_wl_installing' );
188
-
189
-		}
190
-
191
-	}
192
-
193
-	private function install_required() {
194
-
195
-		/** @var Wordlift_Install $install */
196
-		foreach ( $this->installs as $install ) {
197
-			// Get the install version.
198
-			$version = $install->get_version();
199
-
200
-			if ( version_compare( $version, $this->get_current_version(), '>' )
201
-			     || $install->must_install() ) {
202
-				return true;
203
-			}
204
-		}
205
-
206
-		return false;
207
-	}
100
+            new Wordlift_Install_Package_Type(),
101
+            new Wordlift_Install_3_23_4(),
102
+            new Wordlift_Install_3_24_2(),
103
+            new Wordlift_Install_3_25_0(),
104
+            new Wordlift_Install_3_27_0(),
105
+            new Wordlift_Install_3_27_1(),
106
+            new Wordlift_Install_3_28_0(),
107
+            // Add column to represent term
108
+            new Wordlift_Install_3_32_0(),
109
+            // Add the entities table.
110
+            new Wordlift_Install_3_33_9(),
111
+            // When woocommerce extension installed, acf4so should be installed automatically.
112
+            new Wordlift_Install_3_36_0(),
113
+
114
+            new Wordlift_Install_3_38_5(),
115
+            new Wordlift_Install_3_39_1(),
116
+
117
+            // See #1621.
118
+            new Wordlift_Install_3_40_1(),
119
+
120
+            // @link https://github.com/insideout10/wordlift-plugin/issues/1627
121
+            new Wordlift_Install_3_40_2(),
122
+
123
+            new Wordlift_Install_3_41_0(),
124
+            new Wordlift_Install_3_42_0(),
125
+
126
+            new Wordlift_Install_3_44_1(),
127
+            new Wordlift_Install_3_44_4(),
128
+
129
+            new Wordlift_Install_3_45_0(),
130
+            new Wordlift_Install_3_45_1(),
131
+
132
+            new Wordlift_Install_3_50_1(),
133
+        );
134
+        self::$instance = $this;
135
+
136
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
137
+
138
+        add_action( 'init', array( $this, 'install' ) );
139
+
140
+    }
141
+
142
+    /**
143
+     * Get the singleton instance.
144
+     *
145
+     * @since 3.18.0
146
+     */
147
+    public static function get_instance() {
148
+
149
+        return self::$instance;
150
+    }
151
+
152
+    /**
153
+     * Loop thought all versions and install the updates.
154
+     *
155
+     * @return void
156
+     * @since 3.18.0
157
+     *
158
+     * @since 3.20.0 use a transient to avoid concurrent installation calls.
159
+     */
160
+    public function install() {
161
+
162
+        $version = null;
163
+
164
+        if ( $this->install_required() && false === get_transient( '_wl_installing' ) ) {
165
+            set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
166
+            /** @var Wordlift_Install $install */
167
+            foreach ( $this->installs as $install ) {
168
+                // Get the install version.
169
+                $version = $install->get_version();
170
+
171
+                if ( version_compare( $version, $this->get_current_version(), '>' )
172
+                     || $install->must_install() ) {
173
+                    $class_name = get_class( $install );
174
+
175
+                    $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
176
+                    // Install version.
177
+                    $install->install();
178
+
179
+                    $this->log->info( "$class_name installed." );
180
+
181
+                    // Bump the version.
182
+                    update_option( 'wl_db_version', $version );
183
+                }
184
+            }
185
+
186
+            // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
187
+            @delete_transient( '_wl_installing' );
188
+
189
+        }
190
+
191
+    }
192
+
193
+    private function install_required() {
194
+
195
+        /** @var Wordlift_Install $install */
196
+        foreach ( $this->installs as $install ) {
197
+            // Get the install version.
198
+            $version = $install->get_version();
199
+
200
+            if ( version_compare( $version, $this->get_current_version(), '>' )
201
+                 || $install->must_install() ) {
202
+                return true;
203
+            }
204
+        }
205
+
206
+        return false;
207
+    }
208 208
 
209
-	/**
210
-	 * Retrieve the current db version.
211
-	 *
212
-	 * @return type
213
-	 */
214
-	private function get_current_version() {
215
-		return get_option( 'wl_db_version', '0.0.0' );
216
-	}
209
+    /**
210
+     * Retrieve the current db version.
211
+     *
212
+     * @return type
213
+     */
214
+    private function get_current_version() {
215
+        return get_option( 'wl_db_version', '0.0.0' );
216
+    }
217 217
 
218 218
 }
Please login to merge, or discard this patch.
src/install/class-wordlift-install-3-50-1.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Install_3_50_1 extends Wordlift_Install {
9 9
 
10
-	/**
11
-	 * {@inheritdoc}
12
-	 */
13
-	protected static $version = '3.50.1';
10
+    /**
11
+     * {@inheritdoc}
12
+     */
13
+    protected static $version = '3.50.1';
14 14
 
15
-	/**
16
-	 * Is column exists
17
-	 *
18
-	 * @param $column_name
19
-	 *
20
-	 * @return mixed
21
-	 */
22
-	public static function is_column_exists( $column_name ) {
23
-		global $wpdb;
15
+    /**
16
+     * Is column exists
17
+     *
18
+     * @param $column_name
19
+     *
20
+     * @return mixed
21
+     */
22
+    public static function is_column_exists( $column_name ) {
23
+        global $wpdb;
24 24
 
25
-		return $wpdb->get_results(
26
-			$wpdb->prepare(
27
-				"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name ='{$wpdb->prefix}wl_entities' AND column_name = %s",
28
-				$column_name
29
-			)
30
-		);
31
-	}
25
+        return $wpdb->get_results(
26
+            $wpdb->prepare(
27
+                "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name ='{$wpdb->prefix}wl_entities' AND column_name = %s",
28
+                $column_name
29
+            )
30
+        );
31
+    }
32 32
 
33
-	/**
34
-	 * Install
35
-	 *
36
-	 * @return void
37
-	 */
38
-	public function install() {
39
-		global $wpdb;
33
+    /**
34
+     * Install
35
+     *
36
+     * @return void
37
+     */
38
+    public function install() {
39
+        global $wpdb;
40 40
 
41
-		// Check if 'match_name' column exists
42
-		if ( self::is_column_exists( 'match_name' ) ) {
43
-			return;
44
-		}
41
+        // Check if 'match_name' column exists
42
+        if ( self::is_column_exists( 'match_name' ) ) {
43
+            return;
44
+        }
45 45
 
46
-		// Add new 'match_name' column
47
-		dbDelta(
48
-			"ALTER TABLE {$wpdb->prefix}wl_entities
46
+        // Add new 'match_name' column
47
+        dbDelta(
48
+            "ALTER TABLE {$wpdb->prefix}wl_entities
49 49
 					ADD match_name VARCHAR(255) AFTER about_jsonld;"
50
-		);
50
+        );
51 51
 
52
-		// Get all rows with 'about_jsonld'
53
-		$results = $wpdb->get_results(
54
-			"SELECT id, about_jsonld FROM {$wpdb->prefix}wl_entities WHERE about_jsonld IS NOT NULL",
55
-			ARRAY_A
56
-		);
52
+        // Get all rows with 'about_jsonld'
53
+        $results = $wpdb->get_results(
54
+            "SELECT id, about_jsonld FROM {$wpdb->prefix}wl_entities WHERE about_jsonld IS NOT NULL",
55
+            ARRAY_A
56
+        );
57 57
 
58
-		// Update 'match_name' for each row
59
-		foreach ( $results as $row ) {
60
-			$match_name = Jsonld_Utils::get_about_match_name( $row['about_jsonld'] );
58
+        // Update 'match_name' for each row
59
+        foreach ( $results as $row ) {
60
+            $match_name = Jsonld_Utils::get_about_match_name( $row['about_jsonld'] );
61 61
 
62
-			if ( is_null( $match_name ) ) {
63
-				continue;
64
-			}
62
+            if ( is_null( $match_name ) ) {
63
+                continue;
64
+            }
65 65
 
66
-			$wpdb->update(
67
-				"{$wpdb->prefix}wl_entities",
68
-				array( 'match_name' => $match_name ),
69
-				array( 'id' => $row['id'] )
70
-			);
71
-		}
72
-	}
66
+            $wpdb->update(
67
+                "{$wpdb->prefix}wl_entities",
68
+                array( 'match_name' => $match_name ),
69
+                array( 'id' => $row['id'] )
70
+            );
71
+        }
72
+    }
73 73
 }
Please login to merge, or discard this patch.
src/classes/jsonld/class-jsonld-utils.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,19 +4,19 @@
 block discarded – undo
4 4
 
5 5
 class Jsonld_Utils {
6 6
 
7
-	/**
8
-	 * Get about match name value
9
-	 *
10
-	 * @param $jsonld
11
-	 *
12
-	 * @return mixed|null
13
-	 */
14
-	public static function get_about_match_name( $jsonld ) {
15
-		$data = json_decode( $jsonld, true );
16
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
17
-			return null;
18
-		}
7
+    /**
8
+     * Get about match name value
9
+     *
10
+     * @param $jsonld
11
+     *
12
+     * @return mixed|null
13
+     */
14
+    public static function get_about_match_name( $jsonld ) {
15
+        $data = json_decode( $jsonld, true );
16
+        if ( ! $data || ! array_key_exists( 'name', $data ) ) {
17
+            return null;
18
+        }
19 19
 
20
-		return $data['name'];
21
-	}
20
+        return $data['name'];
21
+    }
22 22
 }
Please login to merge, or discard this patch.
src/modules/dashboard/includes/Term_Entity_Match/Term_Query.php 1 patch
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -7,52 +7,52 @@  discard block
 block discarded – undo
7 7
 use WP_REST_Request;
8 8
 
9 9
 class Term_Query {
10
-	/**
11
-	 * @var WP_REST_Request
12
-	 */
13
-	private $request;
14
-	/**
15
-	 * @var mixed
16
-	 */
17
-	private $position;
18
-	/**
19
-	 * @var mixed
20
-	 */
21
-	private $element;
22
-	/**
23
-	 * @var mixed
24
-	 */
25
-	private $direction;
26
-
27
-	private $sort;
28
-
29
-	private $sortby;
30
-	/**
31
-	 * @var mixed
32
-	 */
33
-	private $limit;
34
-
35
-	/** @var Cursor_Sort $cursor_sort */
36
-	private $cursor_sort;
37
-
38
-	/**
39
-	 * @param WP_REST_Request $request
40
-	 * @param Cursor $cursor
41
-	 */
42
-	public function __construct( $request, $cursor, $cursor_sort, $limit ) {
43
-		global $wpdb;
44
-
45
-		$this->request     = $request;
46
-		$this->position    = $cursor->get_position();
47
-		$this->element     = $cursor->get_element();
48
-		$this->direction   = $cursor->get_direction();
49
-		$this->limit       = $limit;
50
-		$this->cursor_sort = $cursor_sort;
51
-
52
-		$this->set_sort();
53
-
54
-		// the `term_name` is required for sort.
55
-		$this->sql = "
10
+    /**
11
+     * @var WP_REST_Request
12
+     */
13
+    private $request;
14
+    /**
15
+     * @var mixed
16
+     */
17
+    private $position;
18
+    /**
19
+     * @var mixed
20
+     */
21
+    private $element;
22
+    /**
23
+     * @var mixed
24
+     */
25
+    private $direction;
26
+
27
+    private $sort;
28
+
29
+    private $sortby;
30
+    /**
31
+     * @var mixed
32
+     */
33
+    private $limit;
34
+
35
+    /** @var Cursor_Sort $cursor_sort */
36
+    private $cursor_sort;
37
+
38
+    /**
39
+     * @param WP_REST_Request $request
40
+     * @param Cursor $cursor
41
+     */
42
+    public function __construct( $request, $cursor, $cursor_sort, $limit ) {
43
+        global $wpdb;
44
+
45
+        $this->request     = $request;
46
+        $this->position    = $cursor->get_position();
47
+        $this->element     = $cursor->get_element();
48
+        $this->direction   = $cursor->get_direction();
49
+        $this->limit       = $limit;
50
+        $this->cursor_sort = $cursor_sort;
51
+
52
+        $this->set_sort();
53
+
54
+        // the `term_name` is required for sort.
55
+        $this->sql = "
56 56
 			SELECT t.term_id as id,
57 57
 				e.about_jsonld as match_jsonld,
58 58
 				t.name,
@@ -72,129 +72,129 @@  discard block
 block discarded – undo
72 72
 			WHERE 1=1
73 73
 		";
74 74
 
75
-		$this->cursor();
76
-		$this->has_match();
77
-		$this->term_contains();
78
-		$this->taxonomies();
79
-		$this->group_by();
80
-		$this->sort();
81
-		$this->limit();
82
-	}
83
-
84
-	public function get_results() {
85
-		global $wpdb;
86
-
87
-		// The `sql` is prepared in each delegated function in this class.
88
-		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
89
-		$items = $wpdb->get_results( $this->sql );
90
-
91
-		$sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC );
92
-		array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items );
93
-
94
-		return $items;
95
-	}
96
-
97
-	private function post_types() {
98
-		$post_types = $this->request->has_param( 'post_types' )
99
-			? (array) $this->request->get_param( 'post_types' )
100
-			: array( 'post', 'page' );
101
-		$value      = array_map( 'esc_sql', $post_types );
102
-		$this->sql  .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )";
103
-	}
104
-
105
-	private function limit() {
106
-		$value     = is_numeric( $this->limit ) ? $this->limit : 10;
107
-		$this->sql .= ' LIMIT ' . esc_sql( $value );
108
-	}
109
-
110
-	private function has_match() {
111
-		if ( ! $this->request->has_param( 'has_match' ) ) {
112
-			return;
113
-		}
114
-
115
-		$value = (bool) $this->request->get_param( 'has_match' );
116
-
117
-		if ( $value ) {
118
-			$this->sql .= ' AND e.about_jsonld IS NOT NULL';
119
-		} else {
120
-			$this->sql .= ' AND e.about_jsonld IS NULL';
121
-		}
122
-	}
123
-
124
-	private function group_by() {
125
-		$this->sql .= ' GROUP BY t.term_id';
126
-	}
127
-
128
-	private function sort() {
129
-		switch ( $this->direction . '$' . $this->sort ) {
130
-			case 'ASCENDING$ASC':
131
-			case 'DESCENDING$DESC':
132
-				$sort = 'ASC';
133
-				break;
134
-			case 'ASCENDING$DESC':
135
-			case 'DESCENDING$ASC':
136
-				$sort = 'DESC';
137
-				break;
138
-		}
139
-
140
-		$this->sql .= ' ORDER BY t.' . $this->sortby . ' ' . $sort;
141
-	}
142
-
143
-	private function cursor() {
144
-		if ( ! isset( $this->position ) ) {
145
-			return;
146
-		}
147
-
148
-		switch ( $this->direction . '$' . $this->sort ) {
149
-			case 'ASCENDING$ASC':
150
-			case 'DESCENDING$DESC':
151
-				$condition = '>';
152
-				break;
153
-			case 'ASCENDING$DESC':
154
-			case 'DESCENDING$ASC':
155
-				$condition = '<';
156
-				break;
157
-		}
158
-
159
-		$condition .= ( $this->element === 'INCLUDED' ? '=' : '' );
160
-		global $wpdb;
161
-		// We control the vars in this method.
162
-		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
163
-		$this->sql .= $wpdb->prepare( ' AND t.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position );
164
-	}
165
-
166
-	private function set_sort() {
167
-		$sortby_to_col = array(
168
-			// sort param  col
169
-			'term_name'   => 'name',
170
-			'entity_name' => 'match_name',
171
-			'occurrences' => 'occurrences',
172
-		);
173
-
174
-		$value = $this->request->has_param( 'sort' )
175
-			? $this->request->get_param( 'sort' )
176
-			: '+term_name';
177
-
178
-		$sortby       = substr( $value, 1 );
179
-		$this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby;
180
-		$this->sort   = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC';
181
-	}
182
-
183
-	private function term_contains() {
184
-		if ( ! $this->request->has_param( 'term_contains' ) ) {
185
-			return;
186
-		}
187
-
188
-		global $wpdb;
189
-		$value     = $this->request->get_param( 'term_contains' );
190
-		$this->sql .= $wpdb->prepare( ' and t.name LIKE %s', '%' . esc_sql( $value ) . '%' );
191
-	}
192
-
193
-	private function taxonomies() {
194
-		$taxonomies = $this->request->has_param( 'taxonomies' )
195
-			? (array) $this->request->get_param( 'taxonomies' )
196
-			: array( 'post_tag', 'category' );
197
-		$value      = array_map( 'esc_sql', $taxonomies );
198
-		$this->sql  .= " AND tt.taxonomy IN ( '" . implode( "', '", $value ) . "' )";
199
-	}
75
+        $this->cursor();
76
+        $this->has_match();
77
+        $this->term_contains();
78
+        $this->taxonomies();
79
+        $this->group_by();
80
+        $this->sort();
81
+        $this->limit();
82
+    }
83
+
84
+    public function get_results() {
85
+        global $wpdb;
86
+
87
+        // The `sql` is prepared in each delegated function in this class.
88
+        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
89
+        $items = $wpdb->get_results( $this->sql );
90
+
91
+        $sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC );
92
+        array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items );
93
+
94
+        return $items;
95
+    }
96
+
97
+    private function post_types() {
98
+        $post_types = $this->request->has_param( 'post_types' )
99
+            ? (array) $this->request->get_param( 'post_types' )
100
+            : array( 'post', 'page' );
101
+        $value      = array_map( 'esc_sql', $post_types );
102
+        $this->sql  .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )";
103
+    }
104
+
105
+    private function limit() {
106
+        $value     = is_numeric( $this->limit ) ? $this->limit : 10;
107
+        $this->sql .= ' LIMIT ' . esc_sql( $value );
108
+    }
109
+
110
+    private function has_match() {
111
+        if ( ! $this->request->has_param( 'has_match' ) ) {
112
+            return;
113
+        }
114
+
115
+        $value = (bool) $this->request->get_param( 'has_match' );
116
+
117
+        if ( $value ) {
118
+            $this->sql .= ' AND e.about_jsonld IS NOT NULL';
119
+        } else {
120
+            $this->sql .= ' AND e.about_jsonld IS NULL';
121
+        }
122
+    }
123
+
124
+    private function group_by() {
125
+        $this->sql .= ' GROUP BY t.term_id';
126
+    }
127
+
128
+    private function sort() {
129
+        switch ( $this->direction . '$' . $this->sort ) {
130
+            case 'ASCENDING$ASC':
131
+            case 'DESCENDING$DESC':
132
+                $sort = 'ASC';
133
+                break;
134
+            case 'ASCENDING$DESC':
135
+            case 'DESCENDING$ASC':
136
+                $sort = 'DESC';
137
+                break;
138
+        }
139
+
140
+        $this->sql .= ' ORDER BY t.' . $this->sortby . ' ' . $sort;
141
+    }
142
+
143
+    private function cursor() {
144
+        if ( ! isset( $this->position ) ) {
145
+            return;
146
+        }
147
+
148
+        switch ( $this->direction . '$' . $this->sort ) {
149
+            case 'ASCENDING$ASC':
150
+            case 'DESCENDING$DESC':
151
+                $condition = '>';
152
+                break;
153
+            case 'ASCENDING$DESC':
154
+            case 'DESCENDING$ASC':
155
+                $condition = '<';
156
+                break;
157
+        }
158
+
159
+        $condition .= ( $this->element === 'INCLUDED' ? '=' : '' );
160
+        global $wpdb;
161
+        // We control the vars in this method.
162
+        // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
163
+        $this->sql .= $wpdb->prepare( ' AND t.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position );
164
+    }
165
+
166
+    private function set_sort() {
167
+        $sortby_to_col = array(
168
+            // sort param  col
169
+            'term_name'   => 'name',
170
+            'entity_name' => 'match_name',
171
+            'occurrences' => 'occurrences',
172
+        );
173
+
174
+        $value = $this->request->has_param( 'sort' )
175
+            ? $this->request->get_param( 'sort' )
176
+            : '+term_name';
177
+
178
+        $sortby       = substr( $value, 1 );
179
+        $this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby;
180
+        $this->sort   = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC';
181
+    }
182
+
183
+    private function term_contains() {
184
+        if ( ! $this->request->has_param( 'term_contains' ) ) {
185
+            return;
186
+        }
187
+
188
+        global $wpdb;
189
+        $value     = $this->request->get_param( 'term_contains' );
190
+        $this->sql .= $wpdb->prepare( ' and t.name LIKE %s', '%' . esc_sql( $value ) . '%' );
191
+    }
192
+
193
+    private function taxonomies() {
194
+        $taxonomies = $this->request->has_param( 'taxonomies' )
195
+            ? (array) $this->request->get_param( 'taxonomies' )
196
+            : array( 'post_tag', 'category' );
197
+        $value      = array_map( 'esc_sql', $taxonomies );
198
+        $this->sql  .= " AND tt.taxonomy IN ( '" . implode( "', '", $value ) . "' )";
199
+    }
200 200
 }
Please login to merge, or discard this patch.
src/classes/content/wordpress/class-abstract-wordpress-content-service.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -12,119 +12,119 @@
 block discarded – undo
12 12
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
13 13
 abstract class Abstract_Wordpress_Content_Service implements Content_Service {
14 14
 
15
-	protected function __construct() {
15
+    protected function __construct() {
16 16
 
17
-	}
17
+    }
18 18
 
19
-	protected function get_dataset_uri() {
20
-		return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() );
21
-	}
19
+    protected function get_dataset_uri() {
20
+        return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() );
21
+    }
22 22
 
23
-	protected function is_absolute( $uri ) {
24
-		return 1 === preg_match( '@^https?://@', $uri );
25
-	}
23
+    protected function is_absolute( $uri ) {
24
+        return 1 === preg_match( '@^https?://@', $uri );
25
+    }
26 26
 
27
-	protected function is_internal( $uri ) {
28
-		$dataset_uri = $this->get_dataset_uri();
27
+    protected function is_internal( $uri ) {
28
+        $dataset_uri = $this->get_dataset_uri();
29 29
 
30
-		return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri );
31
-	}
30
+        return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri );
31
+    }
32 32
 
33
-	protected function make_absolute( $uri ) {
34
-		Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
33
+    protected function make_absolute( $uri ) {
34
+        Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
35 35
 
36
-		if ( 1 !== preg_match( '@^https?://@', $uri ) ) {
37
-			return $this->get_dataset_uri() . $uri;
38
-		}
36
+        if ( 1 !== preg_match( '@^https?://@', $uri ) ) {
37
+            return $this->get_dataset_uri() . $uri;
38
+        }
39 39
 
40
-		return $uri;
41
-	}
40
+        return $uri;
41
+    }
42 42
 
43
-	protected function make_relative( $uri ) {
44
-		$dataset_uri = $this->get_dataset_uri();
45
-		if ( 0 === strpos( $uri, $dataset_uri ) ) {
46
-			return substr( $uri, strlen( $dataset_uri ) );
47
-		}
43
+    protected function make_relative( $uri ) {
44
+        $dataset_uri = $this->get_dataset_uri();
45
+        if ( 0 === strpos( $uri, $dataset_uri ) ) {
46
+            return substr( $uri, strlen( $dataset_uri ) );
47
+        }
48 48
 
49
-		return $uri;
50
-	}
49
+        return $uri;
50
+    }
51 51
 
52
-	/**
53
-	 * @param Wordpress_Content_Id $content_id
54
-	 *
55
-	 * @return string|null
56
-	 */
57
-	public function get_about_jsonld( $content_id ) {
58
-		global $wpdb;
52
+    /**
53
+     * @param Wordpress_Content_Id $content_id
54
+     *
55
+     * @return string|null
56
+     */
57
+    public function get_about_jsonld( $content_id ) {
58
+        global $wpdb;
59 59
 
60
-		return $wpdb->get_var(
61
-			$wpdb->prepare(
62
-				"
60
+        return $wpdb->get_var(
61
+            $wpdb->prepare(
62
+                "
63 63
 			SELECT about_jsonld FROM {$wpdb->prefix}wl_entities
64 64
 			WHERE content_id = %d AND content_type = %d
65 65
 			",
66
-				$content_id->get_id(),
67
-				$content_id->get_type()
68
-			)
69
-		);
70
-	}
71
-
72
-	/**
73
-	 * @param Wordpress_Content_Id $content_id
74
-	 * @param string $value
75
-	 *
76
-	 * @throws Exception If the 'match_name' column does not exist in the database table.
77
-	 */
78
-	public function set_about_jsonld( $content_id, $value ) {
79
-		global $wpdb;
80
-
81
-		// Cleanup value.
82
-		$value      = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null;
83
-		$match_name = Jsonld_Utils::get_about_match_name( $value );
84
-
85
-		// This `hack` is necessary to ensure the entity exists in the entities table, but we
86
-		// should revise how this works really.
87
-		//
88
-		// This is currently needed because rel_uri is required in the table.
89
-		switch ( $content_id->get_type() ) {
90
-			case Object_Type_Enum::POST:
91
-				Wordpress_Dataset_Content_Service_Hooks::insert_post( $content_id->get_id() );
92
-				break;
93
-			case Object_Type_Enum::TERM:
94
-				Wordpress_Dataset_Content_Service_Hooks::created_term( $content_id->get_id() );
95
-				break;
96
-			case Object_Type_Enum::USER:
97
-				Wordpress_Dataset_Content_Service_Hooks::user_register( $content_id->get_id() );
98
-				break;
99
-		}
100
-
101
-		/**
102
-		 * As of May 16 2023, $wpdb:prepare doesnt support null
103
-		 * values in about_jsonld, this results in NULL values being populated
104
-		 * as `null` if we directly pass it to the prepare function(). So its necessary
105
-		 * to make the query conditional based on the $value
106
-		 */
107
-		$query  = "UPDATE {$wpdb->prefix}wl_entities SET ";
108
-		$params = array();
109
-
110
-		if ( is_null( $value ) ) {
111
-			$query .= "about_jsonld = NULL, ";
112
-		} else {
113
-			$query    .= "about_jsonld = %s, ";
114
-			$params[] = $value;
115
-		}
116
-
117
-		if ( is_null( $match_name ) ) {
118
-			$query .= "match_name = NULL ";
119
-		} else {
120
-			$query    .= "match_name = %s ";
121
-			$params[] = $match_name;
122
-		}
123
-
124
-		$query    .= "WHERE content_id = %d AND content_type = %d";
125
-		$params[] = $content_id->get_id();
126
-		$params[] = $content_id->get_type();
127
-
128
-		return $wpdb->query( $wpdb->prepare( $query, $params ) );
129
-	}
66
+                $content_id->get_id(),
67
+                $content_id->get_type()
68
+            )
69
+        );
70
+    }
71
+
72
+    /**
73
+     * @param Wordpress_Content_Id $content_id
74
+     * @param string $value
75
+     *
76
+     * @throws Exception If the 'match_name' column does not exist in the database table.
77
+     */
78
+    public function set_about_jsonld( $content_id, $value ) {
79
+        global $wpdb;
80
+
81
+        // Cleanup value.
82
+        $value      = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null;
83
+        $match_name = Jsonld_Utils::get_about_match_name( $value );
84
+
85
+        // This `hack` is necessary to ensure the entity exists in the entities table, but we
86
+        // should revise how this works really.
87
+        //
88
+        // This is currently needed because rel_uri is required in the table.
89
+        switch ( $content_id->get_type() ) {
90
+            case Object_Type_Enum::POST:
91
+                Wordpress_Dataset_Content_Service_Hooks::insert_post( $content_id->get_id() );
92
+                break;
93
+            case Object_Type_Enum::TERM:
94
+                Wordpress_Dataset_Content_Service_Hooks::created_term( $content_id->get_id() );
95
+                break;
96
+            case Object_Type_Enum::USER:
97
+                Wordpress_Dataset_Content_Service_Hooks::user_register( $content_id->get_id() );
98
+                break;
99
+        }
100
+
101
+        /**
102
+         * As of May 16 2023, $wpdb:prepare doesnt support null
103
+         * values in about_jsonld, this results in NULL values being populated
104
+         * as `null` if we directly pass it to the prepare function(). So its necessary
105
+         * to make the query conditional based on the $value
106
+         */
107
+        $query  = "UPDATE {$wpdb->prefix}wl_entities SET ";
108
+        $params = array();
109
+
110
+        if ( is_null( $value ) ) {
111
+            $query .= "about_jsonld = NULL, ";
112
+        } else {
113
+            $query    .= "about_jsonld = %s, ";
114
+            $params[] = $value;
115
+        }
116
+
117
+        if ( is_null( $match_name ) ) {
118
+            $query .= "match_name = NULL ";
119
+        } else {
120
+            $query    .= "match_name = %s ";
121
+            $params[] = $match_name;
122
+        }
123
+
124
+        $query    .= "WHERE content_id = %d AND content_type = %d";
125
+        $params[] = $content_id->get_id();
126
+        $params[] = $content_id->get_type();
127
+
128
+        return $wpdb->query( $wpdb->prepare( $query, $params ) );
129
+    }
130 130
 }
Please login to merge, or discard this patch.