Changeset 1974

Show
Ignore:
Timestamp:
04/18/08 04:50:29 (22 months ago)
Author:
bchoate
Message:

Load object metadata from narrow tables. BugId:79287

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/php/lib/mtdb_base.php

    r1911 r1974  
    2525    var $id; 
    2626 
    27     function MTDatabaseBase($dbuser, $dbpassword = '', $dbname = '', $dbhost = '', $dbport = '', $dbsocket = '') { 
     27    ## temporary until we class our objects properly 
     28    var $object_meta = array( 
     29        'blog' => array( 
     30            'commenter_authenticators', 
     31            'nofollow_urls', 
     32            'follow_auth_links', 
     33            'captcha_provider', 
     34            'template_set', 
     35            'page_layout', 
     36            'include_system', 
     37            'include_cache'), 
     38        'template' => array( 
     39            'page_layout', 
     40            'include_with_ssi', 
     41            'use_cache', 
     42            'cache_expire_type', 
     43            'cache_expire_interval', 
     44            'cache_expire_event'), 
     45        'asset' => array('image_width', 
     46            'image_height') 
     47    ); 
     48    var $_meta_cache = array(); 
     49 
     50    function MTDatabaseBase($dbuser, $dbpassword = '', $dbname = '', 
     51        $dbhost = '', $dbport = '', $dbsocket = '') { 
    2852        $this->id = md5(uniqid('MTDatabaseBase',true)); 
    2953        $this->hide_errors(); 
     
    105129 
    106130    function fetch_blogs($args) { 
    107  
    108131        if ($blog_ids = $this->include_exclude_blogs($args)) { 
    109132            $where = ' where blog_id ' . $blog_ids; 
     
    28392862                    $expanded[$key] = $this->expand_meta($value); 
    28402863                } else { 
    2841                     if (preg_match('/(\w+)_meta$/', $key, $prefix)) { 
    2842                         $data = $this->unserialize($value); 
     2864                    if (preg_match('/^(\w+)_id$/', $key, $prefix)) { 
     2865                        $type = $prefix[1]; 
     2866                        unset($data); 
     2867                        if (array_key_exists($type, $this->object_meta)) { 
     2868                            $data = $this->get_meta($type, $value); 
     2869                        } 
    28432870                        if (isset($data)) { 
    2844                             foreach ($data as $k => $v) { 
    2845                                 $expanded[$prefix[1] . '_' . $k] = $v; 
     2871                            $cols = $this->object_meta[$type]; 
     2872                            foreach ($cols as $col) { 
     2873                                $expanded[$type . '_' . $col] = $data[$col]; 
    28462874                            } 
    28472875                        } 
     
    28532881        } 
    28542882        return $expanded; 
     2883    } 
     2884 
     2885    function get_meta($obj_type, $obj_id) { 
     2886        $real_type = $obj_type; 
     2887        if ('page' == strtolower($obj_type)) 
     2888            $real_type = 'entry'; 
     2889        elseif ('folder' == strtolower($obj_type)) 
     2890            $real_type = 'category'; 
     2891 
     2892        $meta = $this->_meta_cache["${obj_type}_meta_${obj_id}"]; 
     2893        if (!$meta) { 
     2894            $datasource = $real_type; 
     2895            $datasource = preg_replace("/^mt_/", "", $datasource); 
     2896            $result = $this->get_results("select * from mt_${datasource}_meta  where ${datasource}_meta_${datasource}_id = $obj_id", ARRAY_A); 
     2897            $field_prefix = "${datasource}_meta_"; 
     2898            $meta = array(); 
     2899            foreach ($result as $cfrow) { 
     2900                unset($value); 
     2901                unset($field); 
     2902                // need to test for each v* column to see which is populated 
     2903                // take that value and store for meta row 
     2904                foreach ($cfrow as $cffield => $cfvalue) { 
     2905                    if (preg_match("/^${field_prefix}v/", $cffield)) { 
     2906                        if (isset($cfvalue)) { 
     2907                            $value = $cfvalue; 
     2908                            $field = $cffield; 
     2909                            break; 
     2910                        } 
     2911                    } 
     2912                } 
     2913                if (isset($value)) { 
     2914                    if (preg_match("/_vblob$/", $field)) { 
     2915                        # unserialize blob if value is serialized 
     2916                        if (preg_match("/^BIN:SERG/", $value)) { 
     2917                            $value = $this->unserialize($value); 
     2918                        } 
     2919                        elseif (preg_match("/^ASC:/", $value)) { 
     2920                            $value = preg_replace("/^ASC:/", "", $value); 
     2921                        } 
     2922                    } 
     2923                    $meta[$cfrow["${datasource}_meta_type"]] = $value; 
     2924                } 
     2925            } 
     2926            $this->_meta_cache["${obj_type}_meta_${obj_id}"] = $meta; 
     2927        } 
     2928 
     2929        return $meta; 
    28552930    } 
    28562931 
     
    30023077    } 
    30033078} 
    3004 ?>