Skip to:
Content

bbPress.org

Ticket #2134: 2134.1.diff

File 2134.1.diff, 18.5 KB (added by netweb, 12 years ago)

First pass, no core code changes, updated formatting, cleaned whitespace and updated inline docs and phpdoc for consistency across all import tools.

  • includes/admin/converters/Example.php

    diff --git a/includes/admin/converters/Example.php b/includes/admin/converters/Example.php
    index 4aa6dcf..f8a6a9a 100644
    a b  
    11<?php
    22
    33/**
    4  * Implementation of Example converter.
     4 * Example converter see http://codex.bbpress.org/import-forums/custom-import/
     5 *
     6 * @since bbPress (r4689)
    57 */
    6 class Example_Converter extends BBP_Converter_Base
    7 {
    8         function __construct()
    9         {
     8class Example_Converter extends BBP_Converter_Base {
     9
     10        /**
     11         * Main Constructor
     12         *
     13         * @uses Example_Converter::setup_globals()
     14         */
     15        function __construct() {
    1016                parent::__construct();
    1117                $this->setup_globals();
    1218        }
    1319
     20        /**
     21         * Sets up the field mappings
     22         */
     23
    1424        public function setup_globals()
    1525        {
    1626                /** Forum Section ******************************************************/
    1727
    18                 // Forum id. Stored in postmeta.
     28                // Forum id (Stored in postmeta)
    1929                $this->field_map[] = array(
    20                         'from_tablename' => 'forum', 'from_fieldname' => 'forumid',
    21                         'to_type' => 'forum', 'to_fieldname' => '_bbp_forum_id'
     30                        'from_tablename'  => 'forum',
     31                        'from_fieldname'  => 'forumid',
     32                        'to_type'         => 'forum',
     33                        'to_fieldname'    => '_bbp_forum_id'
    2234                );
    23                
    24                 // Forum parent id.  If no parent, than 0. Stored in postmeta.
     35
     36                // Forum parent id (If no parent, 0. Stored in postmeta)
    2537                $this->field_map[] = array(
    26                         'from_tablename' => 'forum', 'from_fieldname' => 'parentid',
    27                         'to_type' => 'forum', 'to_fieldname' => '_bbp_parent_id'
     38                        'from_tablename'  => 'forum',
     39                        'from_fieldname'  => 'parentid',
     40                        'to_type'         => 'forum',
     41                        'to_fieldname'    => '_bbp_parent_id'
    2842                );
    29                
     43
    3044                // Forum title.
    3145                $this->field_map[] = array(
    32                         'from_tablename' => 'forum', 'from_fieldname' => 'title',
    33                         'to_type' => 'forum', 'to_fieldname' => 'post_title'
     46                        'from_tablename'  => 'forum',
     47                        'from_fieldname'  => 'title',
     48                        'to_type'         => 'forum',
     49                        'to_fieldname'    => 'post_title'
    3450                );
    35                
    36                 // Forum slug. Clean name.
     51
     52                // Forum slug (Clean name to avoid confilcts)
    3753                $this->field_map[] = array(
    38                         'from_tablename' => 'forum', 'from_fieldname' => 'title_clean',
    39                         'to_type' => 'forum', 'to_fieldname' => 'post_name',
     54                        'from_tablename'  => 'forum',
     55                        'from_fieldname'  => 'title_clean',
     56                        'to_type'         => 'forum',
     57                        'to_fieldname'    => 'post_name',
    4058                        'callback_method' => 'callback_slug'
    4159                );
    42                
     60
    4361                // Forum description.
    4462                $this->field_map[] = array(
    45                         'from_tablename' => 'forum', 'from_fieldname' => 'description',
    46                         'to_type' => 'forum', 'to_fieldname' => 'post_content',
     63                        'from_tablename'  => 'forum',
     64                        'from_fieldname'  => 'description',
     65                        'to_type'         => 'forum',
     66                        'to_fieldname'    => 'post_content',
    4767                        'callback_method' => 'callback_null'
    4868                );
    49                
    50                 // Forum display order.  Starts from 1.
     69
     70                // Forum display order (Starts from 1)
    5171                $this->field_map[] = array(
    52                         'from_tablename' => 'forum', 'from_fieldname' => 'displayorder',
    53                         'to_type' => 'forum', 'to_fieldname' => 'menu_order'
     72                        'from_tablename'  => 'forum',
     73                        'from_fieldname'  => 'displayorder',
     74                        'to_type'         => 'forum',
     75                        'to_fieldname'    => 'menu_order'
    5476                );
    55                
    56                 // Forum date update.
     77
     78                // Forum dates.
    5779                $this->field_map[] = array(
    58                         'to_type' => 'forum', 'to_fieldname' => 'post_date',
     80                        'to_type'         => 'forum',
     81                        'to_fieldname'    => 'post_date',
    5982                        'default' => date('Y-m-d H:i:s')
    6083                );
    6184                $this->field_map[] = array(
    62                         'to_type' => 'forum', 'to_fieldname' => 'post_date_gmt',
     85                        'to_type'         => 'forum',
     86                        'to_fieldname'    => 'post_date_gmt',
    6387                        'default' => date('Y-m-d H:i:s')
    6488                );
    6589                $this->field_map[] = array(
    66                         'to_type' => 'forum', 'to_fieldname' => 'post_modified',
     90                        'to_type'         => 'forum',
     91                        'to_fieldname'    => 'post_modified',
    6792                        'default' => date('Y-m-d H:i:s')
    6893                );
    6994                $this->field_map[] = array(
    70                         'to_type' => 'forum', 'to_fieldname' => 'post_modified_gmt',
     95                        'to_type'         => 'forum',
     96                        'to_fieldname'    => 'post_modified_gmt',
    7197                        'default' => date('Y-m-d H:i:s')
    7298                );
    7399
    74100                /** Topic Section ******************************************************/
    75101
    76                 // Topic id. Stored in postmeta.
     102                // Topic id (Stored in postmeta)
    77103                $this->field_map[] = array(
    78                         'from_tablename' => 'thread', 'from_fieldname' => 'threadid',
    79                         'to_type' => 'topic', 'to_fieldname' => '_bbp_topic_id'
     104                        'from_tablename'  => 'thread',
     105                        'from_fieldname'  => 'threadid',
     106                        'to_type'         => 'topic',
     107                        'to_fieldname'    => '_bbp_topic_id'
    80108                );
    81                
    82                 // Forum id. Stored in postmeta.
     109
     110                // Forum id (Stored in postmeta)
    83111                $this->field_map[] = array(
    84                         'from_tablename' => 'thread', 'from_fieldname' => 'forumid',
    85                         'to_type' => 'topic', 'to_fieldname' => '_bbp_forum_id',
     112                        'from_tablename'  => 'thread',
     113                        'from_fieldname'  => 'forumid',
     114                        'to_type'         => 'topic',
     115                        'to_fieldname'    => '_bbp_forum_id',
    86116                        'callback_method' => 'callback_forumid'
    87117                );
    88                                
     118
    89119                // Topic author.
    90120                $this->field_map[] = array(
    91                         'from_tablename' => 'thread', 'from_fieldname' => 'postuserid',
    92                         'to_type' => 'topic', 'to_fieldname' => 'post_author',
     121                        'from_tablename'  => 'thread',
     122                        'from_fieldname'  => 'postuserid',
     123                        'to_type'         => 'topic',
     124                        'to_fieldname'    => 'post_author',
    93125                        'callback_method' => 'callback_userid'
    94126                );
    95                
     127
    96128                // Topic title.
    97129                $this->field_map[] = array(
    98                         'from_tablename' => 'thread', 'from_fieldname' => 'title',
    99                         'to_type' => 'topic', 'to_fieldname' => 'post_title'
     130                        'from_tablename'  => 'thread',
     131                        'from_fieldname'  => 'title',
     132                        'to_type'         => 'topic',
     133                        'to_fieldname'    => 'post_title'
    100134                );
    101                
    102                 // Topic slug. Clean name.
     135
     136                // Topic slug (Clean name to avoid conflicts)
    103137                $this->field_map[] = array(
    104                         'from_tablename' => 'thread', 'from_fieldname' => 'title',
    105                         'to_type' => 'topic', 'to_fieldname' => 'post_name',
     138                        'from_tablename'  => 'thread',
     139                        'from_fieldname'  => 'title',
     140                        'to_type'         => 'topic',
     141                        'to_fieldname'    => 'post_name',
    106142                        'callback_method' => 'callback_slug'
    107143                );
    108                
    109                 // Forum id.  If no parent, than 0.
     144
     145                // Topic parent forum id (If no parent, 0)
    110146                $this->field_map[] = array(
    111                         'from_tablename' => 'thread', 'from_fieldname' => 'forumid',
    112                         'to_type' => 'topic', 'to_fieldname' => 'post_parent',
     147                        'from_tablename'  => 'thread',
     148                        'from_fieldname'  => 'forumid',
     149                        'to_type'         => 'topic',
     150                        'to_fieldname'    => 'post_parent',
    113151                        'callback_method' => 'callback_forumid'
    114152                );
    115153
    116                 // Topic date update.
     154                // Topic dates.
    117155                $this->field_map[] = array(
    118                         'from_tablename' => 'thread', 'from_fieldname' => 'dateline',
    119                         'to_type' => 'topic', 'to_fieldname' => 'post_date',
     156                        'from_tablename'  => 'thread',
     157                        'from_fieldname'  => 'dateline',
     158                        'to_type'         => 'topic',
     159                        'to_fieldname'    => 'post_date',
    120160                        'callback_method' => 'callback_datetime'
    121161                );
    122162                $this->field_map[] = array(
    123                         'from_tablename' => 'thread', 'from_fieldname' => 'dateline',
    124                         'to_type' => 'topic', 'to_fieldname' => 'post_date_gmt',
     163                        'from_tablename'  => 'thread',
     164                        'from_fieldname'  => 'dateline',
     165                        'to_type'         => 'topic',
     166                        'to_fieldname'    => 'post_date_gmt',
    125167                        'callback_method' => 'callback_datetime'
    126168                );
    127169                $this->field_map[] = array(
    128                         'from_tablename' => 'thread', 'from_fieldname' => 'dateline',
    129                         'to_type' => 'topic', 'to_fieldname' => 'post_modified',
     170                        'from_tablename'  => 'thread',
     171                        'from_fieldname'  => 'dateline',
     172                        'to_type'         => 'topic',
     173                        'to_fieldname'    => 'post_modified',
    130174                        'callback_method' => 'callback_datetime'
    131175                );
    132176                $this->field_map[] = array(
    133                         'from_tablename' => 'thread', 'from_fieldname' => 'dateline',
    134                         'to_type' => 'topic', 'to_fieldname' => 'post_modified_gmt',
     177                        'from_tablename'  => 'thread',
     178                        'from_fieldname'  => 'dateline',
     179                        'to_type'         => 'topic',
     180                        'to_fieldname'    => 'post_modified_gmt',
    135181                        'callback_method' => 'callback_datetime'
    136182                );
    137183
    138184                /** Tags Section ******************************************************/
    139                
     185
    140186                // Topic id.
    141187                $this->field_map[] = array(
    142                         'from_tablename' => 'tagcontent', 'from_fieldname' => 'contentid',
    143                         'to_type' => 'tags', 'to_fieldname' => 'objectid',
     188                        'from_tablename'  => 'tagcontent',
     189                        'from_fieldname'  => 'contentid',
     190                        'to_type'         => 'tags',
     191                        'to_fieldname'    => 'objectid',
    144192                        'callback_method' => 'callback_topicid'
    145193                );
    146                
     194
    147195                // Tags text.
    148196                $this->field_map[] = array(
    149                         'from_tablename' => 'tag', 'from_fieldname' => 'tagtext',
    150                         'join_tablename' => 'tagcontent', 'join_type' => 'INNER', 'join_expression' => 'USING (tagid)',
    151                         'to_type' => 'tags', 'to_fieldname' => 'name'
    152                 );             
     197                        'from_tablename'  => 'tag',
     198                        'from_fieldname'  => 'tagtext',
     199                        'join_tablename'  => 'tagcontent',
     200                        'join_type'       => 'INNER',
     201                        'join_expression' => 'USING (tagid)',
     202                        'to_type'         => 'tags',
     203                        'to_fieldname'    => 'name'
     204                );
    153205
    154                 /** Post Section ******************************************************/
     206                /** Reply Section ******************************************************/
    155207
    156                 // Post id. Stores in postmeta.
     208                // Reply post id (Stored in postmeta)
    157209                $this->field_map[] = array(
    158                         'from_tablename' => 'post', 'from_fieldname' => 'postid',
    159                         'to_type' => 'reply', 'to_fieldname' => '_bbp_post_id'
     210                        'from_tablename'  => 'post',
     211                        'from_fieldname'  => 'postid',
     212                        'to_type'         => 'reply',
     213                        'to_fieldname'    => '_bbp_post_id'
    160214                );
    161                
    162                 // Forum id. Stores in postmeta.
     215
     216                // Forum id (Stored in postmeta)
    163217                $this->field_map[] = array(
    164                         'from_tablename' => 'post', 'from_fieldname' => 'threadid',
    165                         'to_type' => 'reply', 'to_fieldname' => '_bbp_forum_id',
     218                        'from_tablename'  => 'post',
     219                        'from_fieldname'  => 'threadid',
     220                        'to_type'         => 'reply',
     221                        'to_fieldname'    => '_bbp_forum_id',
    166222                        'callback_method' => 'callback_topicid_to_forumid'
    167223                );
    168                
    169                 // Topic id. Stores in postmeta.
     224
     225                // Topic id (Stored in postmeta)
    170226                $this->field_map[] = array(
    171                         'from_tablename' => 'post', 'from_fieldname' => 'threadid',
    172                         'to_type' => 'reply', 'to_fieldname' => '_bbp_topic_id',
     227                        'from_tablename'  => 'post',
     228                        'from_fieldname'  => 'threadid',
     229                        'to_type'         => 'reply',
     230                        'to_fieldname'    => '_bbp_topic_id',
    173231                        'callback_method' => 'callback_topicid'
    174232                );
    175                
    176                 // Author ip.
     233
     234                // Author ip (Stored in postmeta)
    177235                $this->field_map[] = array(
    178                         'from_tablename' => 'post', 'from_fieldname' => 'ipaddress',
    179                         'to_type' => 'reply', 'to_fieldname' => '__bbp_author_ip'
    180                 );     
    181                        
    182                 // Post author.
     236                        'from_tablename'  => 'post',
     237                        'from_fieldname'  => 'ipaddress',
     238                        'to_type'         => 'reply',
     239                        'to_fieldname'    => '__bbp_author_ip'
     240                );
     241       
     242                // Reply author.
    183243                $this->field_map[] = array(
    184                         'from_tablename' => 'post', 'from_fieldname' => 'userid',
    185                         'to_type' => 'reply', 'to_fieldname' => 'post_author',
     244                        'from_tablename'  => 'post',
     245                        'from_fieldname'  => 'userid',
     246                        'to_type'         => 'reply',
     247                        'to_fieldname'    => 'post_author',
    186248                        'callback_method' => 'callback_userid'
    187249                );
    188                
    189                 // Topic title.
     250
     251                // Topic title  (for reply title)
    190252                $this->field_map[] = array(
    191                         'from_tablename' => 'post', 'from_fieldname' => 'title',
    192                         'to_type' => 'reply', 'to_fieldname' => 'post_title'
     253                        'from_tablename'  => 'post',
     254                        'from_fieldname'  => 'title',
     255                        'to_type'         => 'reply',
     256                        'to_fieldname'    => 'post_title'
    193257                );
    194                
    195                 // Topic slug. Clean name.
     258
     259                // Reply slug (Clean name to avoid conflicts)
    196260                $this->field_map[] = array(
    197                         'from_tablename' => 'post', 'from_fieldname' => 'title',
    198                         'to_type' => 'reply', 'to_fieldname' => 'post_name',
     261                        'from_tablename'  => 'post',
     262                        'from_fieldname'  => 'title',
     263                        'to_type'         => 'reply',
     264                        'to_fieldname'    => 'post_name',
    199265                        'callback_method' => 'callback_slug'
    200266                );
    201                
    202                 // Post content.
     267
     268                // Reply content.
    203269                $this->field_map[] = array(
    204                         'from_tablename' => 'post', 'from_fieldname' => 'pagetext',
    205                         'to_type' => 'reply', 'to_fieldname' => 'post_content',
     270                        'from_tablename'  => 'post',
     271                        'from_fieldname'  => 'pagetext',
     272                        'to_type'         => 'reply',
     273                        'to_fieldname'    => 'post_content',
    206274                        'callback_method' => 'callback_html'
    207275                );
    208                
    209                 // Topic id.  If no parent, than 0.
     276
     277                // Reply parent topic id (If no parent, than 0)
    210278                $this->field_map[] = array(
    211                         'from_tablename' => 'post', 'from_fieldname' => 'threadid',
    212                         'to_type' => 'reply', 'to_fieldname' => 'post_parent',
     279                        'from_tablename'  => 'post',
     280                        'from_fieldname'  => 'threadid',
     281                        'to_type'         => 'reply',
     282                        'to_fieldname'    => 'post_parent',
    213283                        'callback_method' => 'callback_topicid'
    214284                );
    215285
    216                 // Topic date update.
     286                // Reply dates.
    217287                $this->field_map[] = array(
    218                         'from_tablename' => 'post', 'from_fieldname' => 'dateline',
    219                         'to_type' => 'reply', 'to_fieldname' => 'post_date',
     288                        'from_tablename'  => 'post',
     289                        'from_fieldname'  => 'dateline',
     290                        'to_type'         => 'reply',
     291                        'to_fieldname'    => 'post_date',
    220292                        'callback_method' => 'callback_datetime'
    221293                );
    222294                $this->field_map[] = array(
    223                         'from_tablename' => 'post', 'from_fieldname' => 'dateline',
    224                         'to_type' => 'reply', 'to_fieldname' => 'post_date_gmt',
     295                        'from_tablename'  => 'post',
     296                        'from_fieldname'  => 'dateline',
     297                        'to_type'         => 'reply',
     298                        'to_fieldname'    => 'post_date_gmt',
    225299                        'callback_method' => 'callback_datetime'
    226300                );
    227301                $this->field_map[] = array(
    228                         'from_tablename' => 'post', 'from_fieldname' => 'dateline',
    229                         'to_type' => 'reply', 'to_fieldname' => 'post_modified',
     302                        'from_tablename'  => 'post',
     303                        'from_fieldname'  => 'dateline',
     304                        'to_type'         => 'reply',
     305                        'to_fieldname'    => 'post_modified',
    230306                        'callback_method' => 'callback_datetime'
    231307                );
    232308                $this->field_map[] = array(
    233                         'from_tablename' => 'post', 'from_fieldname' => 'dateline',
    234                         'to_type' => 'reply', 'to_fieldname' => 'post_modified_gmt',
     309                        'from_tablename'  => 'post',
     310                        'from_fieldname'  => 'dateline',
     311                        'to_type'         => 'reply',
     312                        'to_fieldname'    => 'post_modified_gmt',
    235313                        'callback_method' => 'callback_datetime'
    236314                );
    237315
    238316                /** User Section ******************************************************/
    239317
    240                 // Store old User id. Stores in usermeta.
     318                // Store old User id (Stored in usermeta)
    241319                $this->field_map[] = array(
    242                         'from_tablename' => 'user', 'from_fieldname' => 'userid',
    243                         'to_type' => 'user', 'to_fieldname' => '_bbp_user_id'
     320                        'from_tablename'  => 'user',
     321                        'from_fieldname'  => 'userid',
     322                        'to_type'         => 'user',
     323                        'to_fieldname'    => '_bbp_user_id'
    244324                );
    245                
    246                 // Store old User password. Stores in usermeta serialized with salt.
     325
     326                // Store old User password (Stored in usermeta serialized with salt)
    247327                $this->field_map[] = array(
    248                         'from_tablename' => 'user', 'from_fieldname' => 'password',
    249                         'to_type' => 'user', 'to_fieldname' => '_bbp_password',
     328                        'from_tablename'  => 'user',
     329                        'from_fieldname'  => 'password',
     330                        'to_type'         => 'user',
     331                        'to_fieldname'    => '_bbp_password',
    250332                        'callback_method' => 'callback_savepass'
    251333                );
    252334
    253                 // Store old User Salt. This is only used for the SELECT row info for the above password save
     335                // Store old User Salt (This is only used for the SELECT row info for the above password save)
    254336                $this->field_map[] = array(
    255                         'from_tablename' => 'user', 'from_fieldname' => 'salt',
    256                         'to_type' => 'user', 'to_fieldname' => ''
     337                        'from_tablename'  => 'user',
     338                        'from_fieldname'  => 'salt',
     339                        'to_type'         => 'user',
     340                        'to_fieldname'    => ''
    257341                );
    258                                
    259                 // User password verify class. Stores in usermeta for verifying password.
     342
     343                // User password verify class (Stored in usermeta for verifying password)
    260344                $this->field_map[] = array(
    261                         'to_type' => 'user', 'to_fieldname' => '_bbp_class',
    262                         'default' => 'Vbulletin'
     345                        'to_type'         => 'user',
     346                        'to_fieldname'    => '_bbp_class',
     347                        'default' => 'Example'
    263348                );
    264                
     349
    265350                // User name.
    266351                $this->field_map[] = array(
    267                         'from_tablename' => 'user', 'from_fieldname' => 'username',
    268                         'to_type' => 'user', 'to_fieldname' => 'user_login'
     352                        'from_tablename'  => 'user',
     353                        'from_fieldname'  => 'username',
     354                        'to_type'         => 'user',
     355                        'to_fieldname'    => 'user_login'
    269356                );
    270                                
     357
    271358                // User email.
    272359                $this->field_map[] = array(
    273                         'from_tablename' => 'user', 'from_fieldname' => 'email',
    274                         'to_type' => 'user', 'to_fieldname' => 'user_email'
     360                        'from_tablename'  => 'user',
     361                        'from_fieldname'  => 'email',
     362                        'to_type'         => 'user',
     363                        'to_fieldname'    => 'user_email'
    275364                );
    276                
     365
    277366                // User homepage.
    278367                $this->field_map[] = array(
    279                         'from_tablename' => 'user', 'from_fieldname' => 'homepage',
    280                         'to_type' => 'user', 'to_fieldname' => 'user_url'
     368                        'from_tablename'  => 'user',
     369                        'from_fieldname'  => 'homepage',
     370                        'to_type'         => 'user',
     371                        'to_fieldname'    => 'user_url'
    281372                );
    282                
     373
    283374                // User registered.
    284375                $this->field_map[] = array(
    285                         'from_tablename' => 'user', 'from_fieldname' => 'joindate',
    286                         'to_type' => 'user', 'to_fieldname' => 'user_registered',
     376                        'from_tablename'  => 'user',
     377                        'from_fieldname'  => 'joindate',
     378                        'to_type'         => 'user',
     379                        'to_fieldname'    => 'user_registered',
    287380                        'callback_method' => 'callback_datetime'
    288381                );
    289                
    290                 // User aim.
     382
     383                // User AIM (Stored in usermeta)
    291384                $this->field_map[] = array(
    292                         'from_tablename' => 'user', 'from_fieldname' => 'aim',
    293                         'to_type' => 'user', 'to_fieldname' => 'aim'
     385                        'from_tablename'  => 'user',
     386                        'from_fieldname'  => 'aim',
     387                        'to_type'         => 'user',
     388                        'to_fieldname'    => 'aim'
    294389                );
    295                
    296                 // User yahoo.
     390
     391                // User Yahoo (Stored in usermeta)
    297392                $this->field_map[] = array(
    298                         'from_tablename' => 'user', 'from_fieldname' => 'yahoo',
    299                         'to_type' => 'user', 'to_fieldname' => 'yim'
    300                 );     
     393                        'from_tablename'  => 'user',
     394                        'from_fieldname'  => 'yahoo',
     395                        'to_type'         => 'user',
     396                        'to_fieldname'    => 'yim'
     397                );
    301398        }
    302        
     399
    303400        /**
    304401         * This method allows us to indicates what is or is not converted for each
    305402         * converter.