Making WordPress.org


Ignore:
Timestamp:
07/05/2023 05:04:40 AM (17 months ago)
Author:
dd32
Message:

Trac: Add a custom API to fetch/set user preferences. Take Two.

See [12711].
See #5055.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications-sqlite-driver.php

    r12711 r12712  
    5151    }
    5252
     53    /**
     54     * Delete row(s) from a table.
     55     *
     56     * @return bool If the query ran.
     57     */
    5358    public function delete( $table, $where ) {
    5459        $fields = 'AND ' . implode( ' = %s AND ', array_keys( $where ) ) . ' = %s';
     
    5762            array_values( $where )
    5863        );
    59         $this->db->query( $query );
     64        return (bool) $this->db->query( $query );
    6065    }
    6166
     67    /**
     68     * Insert a row into a table.
     69     *
     70     * @return bool If the query ran.
     71     */
    6272    public function insert( $table, $args ) {
    6373        $fields = "'" . implode( "', '", array_keys( $args ) ) . "'";
     
    7080    }
    7181
     82    /**
     83     * Update a row in a table.
     84     *
     85     * @return bool If the query executed and modified rows.
     86     */
    7287    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();
    7691
    7792        foreach ( $data as $field => $value ) {
     
    8196        $sql_sets = implode( ', ', $sql_sets );
    8297
    83         foreach ( $wheres as $field => $where ) {
     98        foreach ( $wheres as $field => $value ) {
    8499            $sql_wheres[] = "$field = %s";
    85100            $values[]     = $value;
     
    87102        $sql_wheres = implode( ' AND ', $sql_wheres );
    88103
    89         if ( ! $values ) {
     104        if ( ! $values || ! $sql_wheres ) {
    90105            return false;
    91106        }
     
    96111        );
    97112
    98         return (bool) $this->db->query( $query );
     113        $result = $this->db->query( $query );
     114
     115        return $result && $result->rowCount() > 0;
    99116    }
    100117}
Note: See TracChangeset for help on using the changeset viewer.