Making WordPress.org

Changeset 3301


Ignore:
Timestamp:
06/06/2016 12:12:09 AM (10 years ago)
Author:
pento
Message:

Plugin Directory: Tidy up the SVN access API

There were some bad variable names, __construct() needed to be public, and caching the DB results was (a) wildly unnecessary; and (b) bad practice.

Despite @rmccue's protests, the exit() is staying.

See #1722.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-svn-access.php

    r3295 r3301  
    1515class SVN_Access extends Base {
    1616
    17         protected $svn_access = array();
    18 
    1917        protected $svn_access_table;
    2018
    21         function __construct() {
     19        public function __construct() {
    2220                $this->svn_access_table = PLUGINS_TABLE_PREFIX . 'svn_access';
    2321
     
    3230         * Generates and prints the SVN access file for plugins.svn.
    3331         *
    34          * Rather than returning a value, the file is echo'd directly to STDOUT, so it can be piped 
     32         * Rather than returning a value, the file is echo'd directly to STDOUT, so it can be piped
    3533         * directly into a file. It exit()'s immediately.
    36          * 
     34         *
    3735         * @param \WP_REST_Request $request The Rest API Request.
    3836         *
     
    4038         */
    4139        public function generate_svn_access( $request ) {
    42                 $this->load_svn_access();
     40                $svn_access = $this->load_svn_access();
    4341
    44                 if ( empty( $this->svn_access ) ) {
     42                if ( empty( $svn_access ) ) {
    4543                        return false;
    4644                        }
    4745
    48                 foreach ( $this->svn_access as $slug => $users ) {
     46                foreach ( $svn_access as $slug => $users ) {
    4947                        $slug = ltrim( $slug, '/' );
    5048                        echo "\n[/$slug]\n";
     
    5452                        }
    5553                }
    56                
     54
    5755                exit();
    5856        }
    5957
     58
     59        /**
     60         * Loads the SVN access data from the svn access table.
     61         *
     62         * @access private
     63         *
     64         * @return array SVN access data, keyed by repo, then username.
     65         */
    6066        private function load_svn_access() {
    6167                global $wpdb;
    6268
    63                 $svn_access = (array) $wpdb->get_results( "SELECT * FROM {$this->svn_access_table}" );
     69                $svn_access = array();
    6470
    65                 foreach ( $svn_access as $svn_access ) {
    66                         if ( ! isset( $this->svn_access[ $svn_access->path ] ) ) {
    67                                 $this->svn_access[ $svn_access->path ] = array();
     71                $access_data = (array) $wpdb->get_results( "SELECT * FROM {$this->svn_access_table}" );
     72
     73                foreach ( $access_data as $datum ) {
     74                        if ( ! isset( $svn_access[ $datum->path ] ) ) {
     75                                $svn_access[ $datum->path ] = array();
    6876                        }
    6977
    70                         $this->svn_access[ $svn_access->path ][ $svn_access->user ] = $svn_access->access;
     78                        $svn_access[ $datum->path ][ $datum->user ] = $datum->access;
    7179                }
     80
     81                return $svn_access;
    7282        }
    73 
    74 
    7583}
Note: See TracChangeset for help on using the changeset viewer.