Changeset 12712
- Timestamp:
- 07/05/2023 05:04:40 AM (19 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
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 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-sqlite-driver.php
r12711 r12712 51 51 } 52 52 53 /** 54 * Delete row(s) from a table. 55 * 56 * @return bool If the query ran. 57 */ 53 58 public function delete( $table, $where ) { 54 59 $fields = 'AND ' . implode( ' = %s AND ', array_keys( $where ) ) . ' = %s'; … … 57 62 array_values( $where ) 58 63 ); 59 $this->db->query( $query );64 return (bool) $this->db->query( $query ); 60 65 } 61 66 67 /** 68 * Insert a row into a table. 69 * 70 * @return bool If the query ran. 71 */ 62 72 public function insert( $table, $args ) { 63 73 $fields = "'" . implode( "', '", array_keys( $args ) ) . "'"; … … 70 80 } 71 81 82 /** 83 * Update a row in a table. 84 * 85 * @return bool If the query executed and modified rows. 86 */ 72 87 public function update( $table, $data, $wheres ) { 73 $values = [];74 $sql_sets = [];75 $sql_wheres = [];88 $values = array(); 89 $sql_sets = array(); 90 $sql_wheres = array(); 76 91 77 92 foreach ( $data as $field => $value ) { … … 81 96 $sql_sets = implode( ', ', $sql_sets ); 82 97 83 foreach ( $wheres as $field => $ where ) {98 foreach ( $wheres as $field => $value ) { 84 99 $sql_wheres[] = "$field = %s"; 85 100 $values[] = $value; … … 87 102 $sql_wheres = implode( ' AND ', $sql_wheres ); 88 103 89 if ( ! $values ) {104 if ( ! $values || ! $sql_wheres ) { 90 105 return false; 91 106 } … … 96 111 ); 97 112 98 return (bool) $this->db->query( $query ); 113 $result = $this->db->query( $query ); 114 115 return $result && $result->rowCount() > 0; 99 116 } 100 117 }
Note: See TracChangeset
for help on using the changeset viewer.