Changeset 3668 in subversion


Ignore:
Timestamp:
May 26, 2010 5:25:24 AM (3 years ago)
Author:
thomasb
Message:

Allow derived classes of rcube_contacts to override table and sequence names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_contacts.php

    r3615 r3668  
    2929{ 
    3030    // protected for backward compat. with some plugins 
    31     // maybe changed in the future 
     31    // deprecated: re-implement $this->get_table_name() instead 
    3232    protected $db_name = ''; 
     33    protected $db_groups = ''; 
     34    protected $db_groupmembers = ''; 
     35     
    3336    private $db = null; 
    3437    private $user_id = 0; 
     
    5962    { 
    6063        $this->db = $dbconn; 
    61         $this->db_name = get_table_name('contacts'); 
     64        $this->db_name = $this->get_table_name('contacts'); 
     65        $this->db_groups = $this->get_table_name('contactgroups'); 
     66        $this->db_groupmembers = $this->get_table_name('contactgroupmembers'); 
     67         
    6268        $this->user_id = $user; 
    6369        $this->ready = $this->db && !$this->db->is_error(); 
     
    128134 
    129135        $sql_result = $this->db->query( 
    130             "SELECT * FROM ".get_table_name('contactgroups'). 
     136            "SELECT * FROM ".$this->db_groups. 
    131137            " WHERE del<>1". 
    132138            " AND user_id=?". 
     
    166172 
    167173        if ($this->group_id) 
    168             $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 
     174            $join = " LEFT JOIN ".$this->db_groupmembers." AS m". 
    169175                " ON (m.contact_id = c.".$this->primary_key.")"; 
    170176 
     
    283289    { 
    284290        if ($this->group_id) 
    285             $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 
     291            $join = " LEFT JOIN ".$this->db_groupmembers." AS m". 
    286292                " ON (m.contact_id=c.".$this->primary_key.")"; 
    287293 
     
    380386            ); 
    381387 
    382             $insert_id = $this->db->insert_id('contacts'); 
     388            $insert_id = $this->db->insert_id($this->get_sequence_name('contacts')); 
    383389        } 
    384390 
     
    494500 
    495501        $this->db->query( 
    496             "INSERT INTO ".get_table_name('contactgroups'). 
     502            "INSERT INTO ".$this->db_groups. 
    497503            " (user_id, changed, name)". 
    498504            " VALUES (".intval($this->user_id).", ".$this->db->now().", ".$this->db->quote($name).")" 
    499505        ); 
    500506 
    501         if ($insert_id = $this->db->insert_id('contactgroups')) 
     507        if ($insert_id = $this->db->insert_id($this->get_sequence_name('contactgroups'))) 
    502508            $result = array('id' => $insert_id, 'name' => $name); 
    503509 
     
    516522        // flag group record as deleted 
    517523        $sql_result = $this->db->query( 
    518             "UPDATE ".get_table_name('contactgroups'). 
     524            "UPDATE ".$this->db_groups. 
    519525            " SET del=1, changed=".$this->db->now(). 
    520526            " WHERE contactgroup_id=?", 
     
    541547 
    542548        $sql_result = $this->db->query( 
    543             "UPDATE ".get_table_name('contactgroups'). 
     549            "UPDATE ".$this->db_groups. 
    544550            " SET name=?, changed=".$this->db->now(). 
    545551            " WHERE contactgroup_id=?", 
     
    567573        foreach ($ids as $contact_id) { 
    568574            $sql_result = $this->db->query( 
    569                 "SELECT 1 FROM ".get_table_name('contactgroupmembers'). 
     575                "SELECT 1 FROM ".$this->db_groupmembers. 
    570576                " WHERE contactgroup_id=?". 
    571577                    " AND contact_id=?", 
     
    576582            if (!$this->db->num_rows($sql_result)) { 
    577583                $this->db->query( 
    578                     "INSERT INTO ".get_table_name('contactgroupmembers'). 
     584                    "INSERT INTO ".$this->db_groupmembers. 
    579585                    " (contactgroup_id, contact_id, created)". 
    580586                    " VALUES (?, ?, ".$this->db->now().")", 
     
    607613 
    608614        $sql_result = $this->db->query( 
    609             "DELETE FROM ".get_table_name('contactgroupmembers'). 
     615            "DELETE FROM ".$this->db_groupmembers. 
    610616            " WHERE contactgroup_id=?". 
    611617                " AND contact_id IN ($ids)", 
     
    630636        do { 
    631637            $sql_result = $this->db->query( 
    632                 "SELECT 1 FROM ".get_table_name('contactgroups'). 
     638                "SELECT 1 FROM ".$this->db_groups. 
    633639                " WHERE del<>1". 
    634640                    " AND user_id=?". 
     
    645651    } 
    646652 
     653 
     654    /** 
     655     * Wrapper for global get_table_name() which can be re-implemented 
     656     * by a derived class 
     657     */ 
     658    protected function get_table_name($table) 
     659    { 
     660        return get_table_name($table); 
     661    } 
     662 
     663    /** 
     664     * Wrapper for global get_sequence_name() which can be re-implemented 
     665     * by a derived class 
     666     */ 
     667    protected function get_sequence_name($table) 
     668    { 
     669        return get_sequence_name($table); 
     670    } 
     671 
    647672} 
Note: See TracChangeset for help on using the changeset viewer.