Skip to:
Content

BuddyPress.org

Changeset 15


Ignore:
Timestamp:
04/07/2008 09:35:36 PM (19 years ago)
Author:
apeatling
Message:

Fixed DB errors on field adding, saving and deleting (all caused by fields with no children). Made sure that field children are deleted in the DB when their parent is deleted.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp_friends.php

    r14 r15  
    6363
    6464        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    65         if($wpdb->get_var("show tables like '$table_name'") != $table_name) friends_install();
     65        if($wpdb->get_var("show tables like '%" . $table_name . "%'") == false) friends_install();
    6666}
    6767add_action('admin_menu','friends_add_menu');
  • trunk/bp_messages.php

    r14 r15  
    2626
    2727        $sql = "CREATE TABLE ". $table_name ." (
    28                   id mediumint(9) NOT NULL AUTO_INCREMENT,
    29                   sender_id mediumint(9) NOT NULL,
    30                   recipient_id mediumint(9) NOT NULL,
     28                  id int(11) NOT NULL AUTO_INCREMENT,
     29                  sender_id int(11) NOT NULL,
     30                  recipient_id int(11) NOT NULL,
     31                  folder_id tinyint(1) NOT NULL DEFAULT 1,
    3132                  subject varchar(200) NOT NULL,
    3233                  message longtext NOT NULL,
    … …  
    7071
    7172        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    72         if($wpdb->get_var("show tables like '$table_name'") != $table_name) messages_install();
     73        if($wpdb->get_var("show tables like '%" . $table_name . "%'") == false) messages_install();
    7374}
    7475add_action('admin_menu','messages_add_menu');
  • trunk/bp_xprofile.php

    r14 r15  
    102102
    103103        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    104         if($wpdb->get_var("show tables like '$bp_xprofile_table_name'") != $bp_xprofile_table_name) xprofile_install();
     104        if($wpdb->get_var("show tables like '%" . $bp_xprofile_table_name . "%'") == false) xprofile_install();
    105105}
    106106add_action('admin_menu','xprofile_add_menu');
  • trunk/bp_xprofile/bp_xprofile.classes.php

    r14 r15  
    5757
    5858        }
    59        
    60         function exists()
     59
     60        function save()
    6161        {
    6262                global $wpdb;
    6363               
    64                 // check to see if the current object exists in the DB
    65                
    66                 $sql = "SELECT id FROM " . $this->table_name . "_groups
    67                                 WHERE group_id = " . $this->id;
    68                
    69                 if(!$wpdb->get_row($sql))
    70                 {
    71                         return false;
    72                 }
    73                
    74                 return true;                           
    75         }
    76        
    77         function save()
    78         {
    79                 global $wpdb;
    80                
    81                 if($this->exists())
     64                if($this->id != null)
    8265                {
    8366                        // Update a group.
    … …  
    306289        }
    307290
    308         function exists()
     291        function delete()
    309292        {
    310293                global $wpdb;
    311294               
    312                 // check to see if the current object exists in the DB
    313                
    314                 $sql = "SELECT id FROM " . $this->table_name . "_fields
    315                                 WHERE id = " . $this->id;
    316                
    317                 if(!$wpdb->get_row($sql))
    318                 {
    319                         return false;
    320                 }
    321                
    322                 return true;           
    323         }
    324 
    325         function delete()
     295                $sql = "DELETE FROM " . $this->table_name . "_fields
     296                                WHERE id = " . $this->id . "
     297                                OR parent_id = " . $this->id;
     298
     299                if($wpdb->query($sql) === false) {
     300                        return false;
     301                }
     302               
     303                // delete the data in the DB for this field
     304                BP_XProfile_ProfileData::delete_all($this->id);
     305               
     306                return true;
     307               
     308        }
     309       
     310        function save()
    326311        {
    327312                global $wpdb;
    328                
    329                 $sql = "DELETE FROM " . $this->table_name . "_fields
    330                                 WHERE id = " . $this->id;
    331 
    332                 if($wpdb->query($sql) === false) {
    333                         return false;
    334                 }
    335                
    336                 return true;
    337                
    338         }
    339        
    340         function save()
    341         {
    342                 global $wpdb;
    343 
    344                 if($this->exists())
     313
     314                if($this->id != null)
    345315                {
    346316                        $sql = "UPDATE " . $this->table_name . "_fields
    … …  
    364334                if($wpdb->query($sql) !== false)
    365335                {
    366                         // Remove any radio or dropdown options for this
    367                         // field. They will be re-added if needed.
    368                         // This stops orphan options if the user changes a
    369                         // field from a radio button field to a text box.
    370                        
    371                         $this->delete_children();
     336                        // Only do this if we are editing an existing field
     337                        if($this->id != null) {
     338                               
     339                                // Remove any radio or dropdown options for this
     340                                // field. They will be re-added if needed.
     341                                // This stops orphan options if the user changes a
     342                                // field from a radio button field to a text box.
     343                                $this->delete_children();
     344                        }
    372345                       
    373346                        // Check to see if this is a selectbox or radio button field.
    374347                        // We need to add the options to the db, if it is.
    375 
    376348                        if($this->type == "radio" || $this->type == "selectbox")
    377349                        {
    … …  
    404376                                                {
    405377                                                        return false;
    406                                                        
     378                                               
    407379                                                        // Need to go back and reverse what has been entered here.
    408380                                                }
    … …  
    626598        function render_admin_form($message = '')
    627599        {
    628                 $options = $this->get_children();
    629 
     600                if($this->id != null) {
     601                        $options = $this->get_children();
     602                }
    630603        ?>
    631604       
    … …  
    642615                <form action="<?php echo $action ?>" method="post">
    643616
    644                         <fieldset id="titlediv">
    645                                 <legend><?php _e("Field Title") ?></legend>
     617                                <label for="title">* <?php _e("Field Title") ?></label>
    646618                                <div>
    647619                                        <input type="text" name="title" id="title" value="<?php echo $this->name ?>" style="width:50%" />
    648620                                </div>
    649                         </fieldset>
    650 
    651                         <fieldset id="descriptiondiv">
    652                                 <legend><?php _e("Field Description") ?></legend>
     621                                <p></p>
     622                                <label for="description"><?php _e("Field Description") ?></label>
    653623                                <div>
    654624                                        <textarea name="description" id="description" rows="5" cols="60"><?php echo $this->desc ?></textarea>
    655625                                </div>
    656                         </fieldset>
    657                        
    658                         <fieldset id="requireddiv">
    659                                 <legend><?php _e("Is This Field Required?") ?></legend>
     626                                <p></p>
     627                                <label for="required">* <?php _e("Is This Field Required?") ?></label>
    660628                                <div>
    661629                                        <select name="required" id="required">
    … …  
    664632                                        </select>
    665633                                </div>
    666                         </fieldset>
    667 
    668                         <fieldset id="typediv">
    669                                 <legend><?php _e("Field Type") ?></legend>
     634                                <p></p>
     635                                <label for="fieldtype">* <?php _e("Field Type") ?></label>
    670636                                <div>
    671637                                        <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)">
    … …  
    677643                                        </select>
    678644                                </div>
    679                         </fieldset>
    680645                       
    681646                        <div id="radio" style="<?php if($this->type != 'radio') {?>display: none;<?php } ?> margin-left: 15px;">
    … …  
    762727                if($_POST['title'] == '' || $_POST['required'] == '' || $_POST['fieldtype'] == '')
    763728                {
    764                         $message = __('Please make sure you fill out the form completely, every field is required.');
     729                        $message = __('Please make sure you fill out all required fields.');
    765730                        return false;
    766731                }
    … …  
    952917        }
    953918       
    954        
    955 
    956919        /** Static Functions **/
    957920       
    … …  
    974937                                return false;
    975938                        }
     939                }
     940        }
     941       
     942        function delete_all($field_id)
     943        {
     944                global $wpdb, $userdata;
     945               
     946                if(bp_core_validate($field_id))
     947                {
     948                        $sql = "DELETE FROM " . $this->table_name . "_data
     949                                        WHERE field_id = " . $field_id;
     950
     951                        if($wpdb->query($sql) === false) {
     952                                return false;
     953                        }
     954                       
     955                        return true;
    976956                }
    977957        }
  • trunk/bp_xprofile/bp_xprofile.cssjs.php

    r14 r15  
    157157                        color: #555;
    158158                }
    159                
     159
    160160               
    161161        </style>
Note: See TracChangeset for help on using the changeset viewer.