Changeset 12711
- Timestamp:
- 07/05/2023 04:06:16 AM (17 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-db.php
r10420 r12711 191 191 call_user_func( array( $this->db, $method ), '_notifications', (array) $where ); 192 192 } 193 } 194 } 195 196 /** 197 * Fetch user preferences from Trac. 198 * 199 * @param string $username The username. 200 * @return array The user preferences. [ key => value ]. 201 */ 202 function get_user_prefs( $username ) { 203 $data = $this->db->get_results( $this->db->prepare( 204 'SELECT name, value FROM session_attribute WHERE sid = %s', 205 $username 206 ), ARRAY_A ); 207 208 return array_column( $data, 'value', 'name' ); 209 } 210 211 /** 212 * Set a user preference in Trac. 213 * 214 * @param string $username The username. 215 * @param string $name The preference. 216 * @param string|null $value The value to set. If null, the preference will be deleted. 217 */ 218 function set_user_pref( $username, $name, $value = null ) { 219 // The trac column for username is `sid`. All our users are authenticated. 220 // The session_attribute table has an index: UNIQUE (sid,authenticated,name) 221 222 if ( ! is_null( $value ) ) { 223 $result = $this->db->update( 224 'session_attribute', 225 [ 'value' => $value ], 226 [ 227 'sid' => $username, 228 'authenticated' => 1, 229 'name' => $name 230 ] 231 ); 232 233 if ( ! $result ) { 234 // Insert the session if it doesn't exist. 235 $user_has_visited_trac = $this->db->get_var( $this->db->prepare( 236 'SELECT sid FROM session WHERE sid = %s', 237 $username 238 ) ); 239 if ( ! $user_has_visited_trac ) { 240 $this->db->insert( 'session', [ 241 'sid' => $username, 242 'authenticated' => 1, 243 'last_visit' => time(), 244 ] ); 245 } 246 247 // Set the pref. 248 $result = $this->db->insert( 'session_attribute', [ 249 'sid' => $username, 250 'authenticated' => 1, 251 'name' => $name, 252 'value' => $value, 253 ] ); 254 } 255 256 return $result; 257 } else { 258 return $this->db->delete( 'session_attribute', [ 259 'sid' => $username, 260 'authenticated' => 1, 261 'name' => $name 262 ] ); 193 263 } 194 264 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-sqlite-driver.php
r2027 r12711 69 69 return (bool) $this->db->query( $query ); 70 70 } 71 72 public function update( $table, $data, $wheres ) { 73 $values = []; 74 $sql_sets = []; 75 $sql_wheres = []; 76 77 foreach ( $data as $field => $value ) { 78 $sql_sets[] = "$field = %s"; 79 $values[] = $value; 80 } 81 $sql_sets = implode( ', ', $sql_sets ); 82 83 foreach ( $wheres as $field => $where ) { 84 $sql_wheres[] = "$field = %s"; 85 $values[] = $value; 86 } 87 $sql_wheres = implode( ' AND ', $sql_wheres ); 88 89 if ( ! $values ) { 90 return false; 91 } 92 93 $query = $this->prepare( 94 "UPDATE $table SET $sql_sets WHERE $sql_wheres", 95 $values 96 ); 97 98 return (bool) $this->db->query( $query ); 99 } 71 100 }
Note: See TracChangeset
for help on using the changeset viewer.