Completed
Pull Request — develop (#1707)
by
unknown
01:18
created
src/classes/content/wordpress/class-abstract-wordpress-content-service.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -11,143 +11,143 @@
 block discarded – undo
11 11
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
12 12
 abstract class Abstract_Wordpress_Content_Service implements Content_Service {
13 13
 
14
-	protected function __construct() {
14
+    protected function __construct() {
15 15
 
16
-	}
16
+    }
17 17
 
18
-	protected function get_dataset_uri() {
19
-		return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() );
20
-	}
18
+    protected function get_dataset_uri() {
19
+        return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() );
20
+    }
21 21
 
22
-	protected function is_absolute( $uri ) {
23
-		return 1 === preg_match( '@^https?://@', $uri );
24
-	}
22
+    protected function is_absolute( $uri ) {
23
+        return 1 === preg_match( '@^https?://@', $uri );
24
+    }
25 25
 
26
-	protected function is_internal( $uri ) {
27
-		$dataset_uri = $this->get_dataset_uri();
26
+    protected function is_internal( $uri ) {
27
+        $dataset_uri = $this->get_dataset_uri();
28 28
 
29
-		return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri );
30
-	}
29
+        return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri );
30
+    }
31 31
 
32
-	protected function make_absolute( $uri ) {
33
-		Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
32
+    protected function make_absolute( $uri ) {
33
+        Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
34 34
 
35
-		if ( 1 !== preg_match( '@^https?://@', $uri ) ) {
36
-			return $this->get_dataset_uri() . $uri;
37
-		}
35
+        if ( 1 !== preg_match( '@^https?://@', $uri ) ) {
36
+            return $this->get_dataset_uri() . $uri;
37
+        }
38 38
 
39
-		return $uri;
40
-	}
39
+        return $uri;
40
+    }
41 41
 
42
-	protected function make_relative( $uri ) {
43
-		$dataset_uri = $this->get_dataset_uri();
44
-		if ( 0 === strpos( $uri, $dataset_uri ) ) {
45
-			return substr( $uri, strlen( $dataset_uri ) );
46
-		}
42
+    protected function make_relative( $uri ) {
43
+        $dataset_uri = $this->get_dataset_uri();
44
+        if ( 0 === strpos( $uri, $dataset_uri ) ) {
45
+            return substr( $uri, strlen( $dataset_uri ) );
46
+        }
47 47
 
48
-		return $uri;
49
-	}
48
+        return $uri;
49
+    }
50 50
 
51
-	/**
52
-	 * @param Wordpress_Content_Id $content_id
53
-	 *
54
-	 * @return string|null
55
-	 */
56
-	public function get_about_jsonld( $content_id ) {
57
-		global $wpdb;
51
+    /**
52
+     * @param Wordpress_Content_Id $content_id
53
+     *
54
+     * @return string|null
55
+     */
56
+    public function get_about_jsonld( $content_id ) {
57
+        global $wpdb;
58 58
 
59
-		return $wpdb->get_var(
60
-			$wpdb->prepare(
61
-				"
59
+        return $wpdb->get_var(
60
+            $wpdb->prepare(
61
+                "
62 62
 			SELECT about_jsonld FROM {$wpdb->prefix}wl_entities
63 63
 			WHERE content_id = %d AND content_type = %d
64 64
 			",
65
-				$content_id->get_id(),
66
-				$content_id->get_type()
67
-			)
68
-		);
69
-	}
70
-
71
-	/**
72
-	 * @param Wordpress_Content_Id $content_id
73
-	 * @param string $value
74
-	 *
75
-	 * @throws Exception If the 'match_name' column does not exist in the database table.
76
-	 */
77
-	public function set_about_jsonld( $content_id, $value ) {
78
-		global $wpdb;
79
-
80
-		// Cleanup value.
81
-		$value      = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null;
82
-		$match_name = "NULL";
83
-
84
-		if ( $value ) {
85
-			// Check if the 'match_name' column exists in the database table
86
-			$columns = $wpdb->get_col_info( 'name', 0 );
87
-			if ( in_array( 'match_name', $columns ) ) {
88
-				$match_name = $this->get_match_name( $value );
89
-			}
90
-		}
91
-
92
-		// This `hack` is necessary to ensure the entity exists in the entities table, but we
93
-		// should revise how this works really.
94
-		//
95
-		// This is currently needed because rel_uri is required in the table.
96
-		switch ( $content_id->get_type() ) {
97
-			case Object_Type_Enum::POST:
98
-				Wordpress_Dataset_Content_Service_Hooks::insert_post( $content_id->get_id() );
99
-				break;
100
-			case Object_Type_Enum::TERM:
101
-				Wordpress_Dataset_Content_Service_Hooks::created_term( $content_id->get_id() );
102
-				break;
103
-			case Object_Type_Enum::USER:
104
-				Wordpress_Dataset_Content_Service_Hooks::user_register( $content_id->get_id() );
105
-				break;
106
-		}
107
-
108
-		/**
109
-		 * As of May 16 2023, $wpdb:prepare doesnt support null
110
-		 * values in about_jsonld, this results in NULL values being populated
111
-		 * as `null` if we directly pass it to the prepare function(). So its necessary
112
-		 * to make the query conditional based on the $value
113
-		 */
114
-		if ( null === $value ) {
115
-			return $wpdb->query(
116
-				$wpdb->prepare(
117
-					"UPDATE {$wpdb->prefix}wl_entities
65
+                $content_id->get_id(),
66
+                $content_id->get_type()
67
+            )
68
+        );
69
+    }
70
+
71
+    /**
72
+     * @param Wordpress_Content_Id $content_id
73
+     * @param string $value
74
+     *
75
+     * @throws Exception If the 'match_name' column does not exist in the database table.
76
+     */
77
+    public function set_about_jsonld( $content_id, $value ) {
78
+        global $wpdb;
79
+
80
+        // Cleanup value.
81
+        $value      = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null;
82
+        $match_name = "NULL";
83
+
84
+        if ( $value ) {
85
+            // Check if the 'match_name' column exists in the database table
86
+            $columns = $wpdb->get_col_info( 'name', 0 );
87
+            if ( in_array( 'match_name', $columns ) ) {
88
+                $match_name = $this->get_match_name( $value );
89
+            }
90
+        }
91
+
92
+        // This `hack` is necessary to ensure the entity exists in the entities table, but we
93
+        // should revise how this works really.
94
+        //
95
+        // This is currently needed because rel_uri is required in the table.
96
+        switch ( $content_id->get_type() ) {
97
+            case Object_Type_Enum::POST:
98
+                Wordpress_Dataset_Content_Service_Hooks::insert_post( $content_id->get_id() );
99
+                break;
100
+            case Object_Type_Enum::TERM:
101
+                Wordpress_Dataset_Content_Service_Hooks::created_term( $content_id->get_id() );
102
+                break;
103
+            case Object_Type_Enum::USER:
104
+                Wordpress_Dataset_Content_Service_Hooks::user_register( $content_id->get_id() );
105
+                break;
106
+        }
107
+
108
+        /**
109
+         * As of May 16 2023, $wpdb:prepare doesnt support null
110
+         * values in about_jsonld, this results in NULL values being populated
111
+         * as `null` if we directly pass it to the prepare function(). So its necessary
112
+         * to make the query conditional based on the $value
113
+         */
114
+        if ( null === $value ) {
115
+            return $wpdb->query(
116
+                $wpdb->prepare(
117
+                    "UPDATE {$wpdb->prefix}wl_entities
118 118
 					SET about_jsonld = NULL, match_name = %s
119 119
 					WHERE content_id = %d AND content_type = %d",
120
-					$match_name,
121
-					$content_id->get_id(),
122
-					$content_id->get_type()
123
-				)
124
-			);
125
-		}
126
-
127
-		return $wpdb->query(
128
-			$wpdb->prepare(
129
-				"UPDATE {$wpdb->prefix}wl_entities
120
+                    $match_name,
121
+                    $content_id->get_id(),
122
+                    $content_id->get_type()
123
+                )
124
+            );
125
+        }
126
+
127
+        return $wpdb->query(
128
+            $wpdb->prepare(
129
+                "UPDATE {$wpdb->prefix}wl_entities
130 130
 				SET about_jsonld = %s, match_name = %s
131 131
 				WHERE content_id = %d AND content_type = %d",
132
-				$value,
133
-				$match_name,
134
-				$content_id->get_id(),
135
-				$content_id->get_type()
136
-			)
137
-		);
138
-	}
139
-
140
-	/**
141
-	 * @param $jsonld
142
-	 *
143
-	 * @return mixed|null
144
-	 */
145
-	public function get_match_name( $jsonld ) {
146
-		$data = json_decode( $jsonld, true );
147
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
148
-			return "NULL";
149
-		}
150
-
151
-		return $data['name'];
152
-	}
132
+                $value,
133
+                $match_name,
134
+                $content_id->get_id(),
135
+                $content_id->get_type()
136
+            )
137
+        );
138
+    }
139
+
140
+    /**
141
+     * @param $jsonld
142
+     *
143
+     * @return mixed|null
144
+     */
145
+    public function get_match_name( $jsonld ) {
146
+        $data = json_decode( $jsonld, true );
147
+        if ( ! $data || ! array_key_exists( 'name', $data ) ) {
148
+            return "NULL";
149
+        }
150
+
151
+        return $data['name'];
152
+    }
153 153
 }
Please login to merge, or discard this patch.
src/install/class-wordlift-install-3-49-1.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -7,85 +7,85 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Install_3_49_1 extends Wordlift_Install {
9 9
 
10
-	/**
11
-	 * {@inheritdoc}
12
-	 */
13
-	protected static $version = '3.49.1';
10
+    /**
11
+     * {@inheritdoc}
12
+     */
13
+    protected static $version = '3.49.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_relation_instances' 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_relation_instances' 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
-		$wpdb->query(
48
-			"ALTER TABLE {$wpdb->prefix}wl_relation_instances
46
+        // Add new 'match_name' column
47
+        $wpdb->query(
48
+            "ALTER TABLE {$wpdb->prefix}wl_relation_instances
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_relation_instances 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_relation_instances 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 = $this->get_match_name( $row['about_jsonld'] );
58
+        // Update 'match_name' for each row
59
+        foreach ( $results as $row ) {
60
+            $match_name = $this->get_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_relation_instances",
68
-				array( 'match_name' => $match_name ),
69
-				array( 'id' => $row['id'] )
70
-			);
71
-		}
66
+            $wpdb->update(
67
+                "{$wpdb->prefix}wl_relation_instances",
68
+                array( 'match_name' => $match_name ),
69
+                array( 'id' => $row['id'] )
70
+            );
71
+        }
72 72
 
73
-		Ttl_Cache::flush_all();
74
-	}
73
+        Ttl_Cache::flush_all();
74
+    }
75 75
 
76
-	/**
77
-	 * Get match name
78
-	 *
79
-	 * @param $jsonld
80
-	 *
81
-	 * @return mixed|null
82
-	 */
83
-	public function get_match_name( $jsonld ) {
84
-		$data = json_decode( $jsonld, true );
85
-		if ( ! $data || ! array_key_exists( 'name', $data ) ) {
86
-			return null;
87
-		}
76
+    /**
77
+     * Get match name
78
+     *
79
+     * @param $jsonld
80
+     *
81
+     * @return mixed|null
82
+     */
83
+    public function get_match_name( $jsonld ) {
84
+        $data = json_decode( $jsonld, true );
85
+        if ( ! $data || ! array_key_exists( 'name', $data ) ) {
86
+            return null;
87
+        }
88 88
 
89
-		return $data['name'];
90
-	}
89
+        return $data['name'];
90
+    }
91 91
 }
Please login to merge, or discard this patch.