Changeset 12712 for sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-db.php
- Timestamp:
- 07/05/2023 05:04:40 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-db.php
r12711 r12712 214 214 * @param string $username The username. 215 215 * @param string $name The preference. 216 * @param string|null $value The value to set. If null, the preference will be deleted.216 * @param string|null $value The value to set. 217 217 */ 218 function set_user_pref( $username, $name, $value = null) {218 function set_user_pref( $username, $name, $value = '' ) { 219 219 // The trac column for username is `sid`. All our users are authenticated. 220 220 // The session_attribute table has an index: UNIQUE (sid,authenticated,name) 221 221 222 if ( ! is_null( $value ) ) { 222 $result = $this->db->insert( 'session_attribute', array( 223 'sid' => $username, 224 'authenticated' => 1, 225 'name' => $name, 226 'value' => $value 227 ) ); 228 229 if ( ! $result ) { 223 230 $result = $this->db->update( 224 231 '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', [ 232 array( 233 'value' => $value 234 ), array( 249 235 'sid' => $username, 250 236 'authenticated' => 1, 251 237 '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 ] ); 263 } 238 ) 239 ); 240 } 241 242 return $result; 243 } 244 245 /** 246 * Delete a user preference. 247 * 248 * @param string $username The username. 249 * @param string $name The preference. 250 * @return bool 251 */ 252 function delete_user_pref( $username, $name ) { 253 return $this->db->delete( 'session_attribute', array( 254 'sid' => $username, 255 'authenticated' => 1, 256 'name' => $name 257 ) ); 264 258 } 265 259 … … 303 297 'attachments', 304 298 'comments', 305 'profile_data' ,299 'profile_data' 306 300 ); 307 301 }
Note: See TracChangeset
for help on using the changeset viewer.