Changeset 6184 for trunk/src/includes/admin/converter.php
- Timestamp:
- 12/27/2016 09:39:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/converter.php
r6129 r6184 4 4 * bbPress Converter 5 5 * 6 * Based on the hard work of Adam Ellis at http://bbconverter.com6 * Based on the hard work of Adam Ellis 7 7 * 8 8 * @package bbPress … … 636 636 $bbp_db = bbp_db(); 637 637 $table_name = $bbp_db->prefix . 'bbp_converter_translator'; 638 if ( ! empty( $drop ) && $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {638 if ( ! empty( $drop ) && $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) { 639 639 $bbp_db->query( "DROP TABLE {$table_name}" ); 640 640 } … … 653 653 $max_index_length = 191; 654 654 655 /** Translator **************************************************** /655 /** Translator ********************************************************/ 656 656 657 657 $sql[] = "CREATE TABLE {$table_name} ( … … 765 765 */ 766 766 $this->sync_table_name = $this->wpdb->prefix . 'bbp_converter_translator'; 767 if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) == $this->sync_table_name ) {767 if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) { 768 768 $this->sync_table = true; 769 769 } else { … … 772 772 773 773 /** 774 * Char set774 * Character set 775 775 */ 776 776 if ( empty( $this->wpdb->charset ) ) { … … 927 927 928 928 // Are we usig a sync table, or postmeta? 929 if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) == $this->sync_table_name ) {929 if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) { 930 930 $this->sync_table = true; 931 931 } else { … … 949 949 950 950 case 'forum_subscriptions' : 951 $tablename = $this->wpdb-> usermeta;951 $tablename = $this->wpdb->postmeta; 952 952 break; 953 953 954 954 case 'topic_subscriptions' : 955 $tablename = $this->wpdb-> usermeta;955 $tablename = $this->wpdb->postmeta; 956 956 break; 957 957 958 958 case 'favorites' : 959 $tablename = $this->wpdb-> usermeta;959 $tablename = $this->wpdb->postmeta; 960 960 break; 961 961 … … 975 975 976 976 // Yay a match, and we have a from table, too 977 if ( ( $item['to_type'] == $to_type ) && ! empty( $item['from_tablename'] ) ) {977 if ( ( $item['to_type'] === $to_type ) && ! empty( $item['from_tablename'] ) ) { 978 978 979 979 // $from_tablename was set from a previous loop iteration … … 1036 1036 // Types match and to_fieldname is present. This means 1037 1037 // we have some work to do here. 1038 if ( ( $row['to_type'] == $to_type ) && isset( $row['to_fieldname'] ) ) {1038 if ( ( $row['to_type'] === $to_type ) && isset( $row['to_fieldname'] ) ) { 1039 1039 1040 1040 // This row has a destination that matches one of the … … 1044 1044 // Allows us to set default fields. 1045 1045 if ( isset( $row['default'] ) ) { 1046 $insert_post[ $row['to_fieldname']] = $row['default'];1046 $insert_post[ $row['to_fieldname'] ] = $row['default']; 1047 1047 1048 1048 // Translates a field from the old forum. 1049 1049 } elseif ( isset( $row['callback_method'] ) ) { 1050 if ( ( 'callback_userid' == $row['callback_method'] ) && empty( $_POST['_bbp_converter_convert_users'] ) ) {1051 $insert_post[ $row['to_fieldname']] = $forum[$row['from_fieldname']];1050 if ( ( 'callback_userid' === $row['callback_method'] ) && empty( $_POST['_bbp_converter_convert_users'] ) ) { 1051 $insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; 1052 1052 } else { 1053 $insert_post[ $row['to_fieldname']] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[$row['from_fieldname']], $forum ) );1053 $insert_post[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) ); 1054 1054 } 1055 1055 1056 1056 // Maps the field from the old forum. 1057 1057 } else { 1058 $insert_post[ $row['to_fieldname']] = $forum[$row['from_fieldname']];1058 $insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; 1059 1059 } 1060 1060 … … 1065 1065 // Allows us to set default fields. 1066 1066 if ( isset( $row['default'] ) ) { 1067 $insert_postmeta[ $row['to_fieldname']] = $row['default'];1067 $insert_postmeta[ $row['to_fieldname'] ] = $row['default']; 1068 1068 1069 1069 // Translates a field from the old forum. 1070 1070 } elseif ( isset( $row['callback_method'] ) ) { 1071 if ( ( $row['callback_method'] == 'callback_userid' ) && ( 0 == $_POST['_bbp_converter_convert_users'] ) ) {1072 $insert_postmeta[ $row['to_fieldname']] = $forum[$row['from_fieldname']];1071 if ( ( $row['callback_method'] === 'callback_userid' ) && ( 0 == $_POST['_bbp_converter_convert_users'] ) ) { 1072 $insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; 1073 1073 } else { 1074 $insert_postmeta[ $row['to_fieldname']] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[$row['from_fieldname']], $forum ) );1074 $insert_postmeta[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) ); 1075 1075 } 1076 1076 1077 1077 // Maps the field from the old forum. 1078 1078 } else { 1079 $insert_postmeta[ $row['to_fieldname']] = $forum[$row['from_fieldname']];1079 $insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ]; 1080 1080 } 1081 1081 } … … 1129 1129 break; 1130 1130 1131 /** Forum Subscriptions *************************** ******/1131 /** Forum Subscriptions ***************************/ 1132 1132 1133 1133 case 'forum_subscriptions': 1134 1134 $user_id = $insert_post['user_id']; 1135 if ( is_numeric( $user_id ) ) { 1136 foreach ($insert_postmeta as $key => $value) { 1137 1138 // Only extract values from the key _bbp_forum_subscriptions 1139 if ( '_bbp_forum_subscriptions' == $key ) { 1140 1141 // Get the new forum ID 1142 $forum_id = $this->callback_forumid( $value ); 1143 1144 // Add the topic ID to the users subscribed forums 1145 bbp_add_user_forum_subscription( $user_id, $forum_id ); 1135 $items = wp_list_pluck( $insert_postmeta, '_bbp_forum_subscriptions' ); 1136 if ( is_numeric( $user_id ) && ! empty( $items ) ) { 1137 foreach ( $items as $value ) { 1138 1139 // Maybe string with commas 1140 $value = is_string( $value ) 1141 ? explode( ',', $value ) 1142 : (array) $value; 1143 1144 // Add user ID to forums subscribed users 1145 foreach ( $value as $fav ) { 1146 bbp_add_user_forum_subscription( $user_id, $this->callback_forumid( $fav ) ); 1146 1147 } 1147 1148 } … … 1153 1154 case 'topic_subscriptions': 1154 1155 $user_id = $insert_post['user_id']; 1155 if ( is_numeric( $user_id ) ) { 1156 foreach ($insert_postmeta as $key => $value) { 1157 1158 // Only extract values from the key _bbp_subscriptions 1159 if ( '_bbp_subscriptions' == $key ) { 1160 1161 // Get the new topic ID 1162 $topic_id = $this->callback_topicid( $value ); 1163 1164 // Add the topic ID to the users subscribed topics 1165 bbp_add_user_topic_subscription( $user_id, $topic_id ); 1156 $items = wp_list_pluck( $insert_postmeta, '_bbp_subscriptions' ); 1157 if ( is_numeric( $user_id ) && ! empty( $items ) ) { 1158 foreach ( $items as $value ) { 1159 1160 // Maybe string with commas 1161 $value = is_string( $value ) 1162 ? explode( ',', $value ) 1163 : (array) $value; 1164 1165 // Add user ID to topics subscribed users 1166 foreach ( $value as $fav ) { 1167 bbp_add_user_topic_subscription( $user_id, $this->callback_topicid( $fav ) ); 1166 1168 } 1167 1169 } … … 1169 1171 break; 1170 1172 1171 /** Favorites ********************************* /1173 /** Favorites *************************************/ 1172 1174 1173 1175 case 'favorites': 1174 1176 $user_id = $insert_post['user_id']; 1175 if ( is_numeric( $user_id ) ) { 1176 1177 // Loop through the array 1178 foreach ($insert_postmeta as $key => $value) { 1179 1180 // Only extract values from the key _bbp_favorites 1181 if ( '_bbp_favorites' == $key ) { 1182 1183 // Our array may contain comma delimited favorites so lets explode these 1184 $insert_postmeta = explode(",", $insert_postmeta['_bbp_favorites']); 1185 1186 // Loop through our updated exploded array 1187 foreach ($insert_postmeta as $key => $value) { 1188 1189 // Get the new topic ID 1190 $topic_id = $this->callback_topicid( $value ); 1191 1192 // Add the topic ID to the users favorites 1193 bbp_add_user_favorite( $user_id, $topic_id ); 1194 } 1177 $items = wp_list_pluck( $insert_postmeta, '_bbp_favorites' ); 1178 if ( is_numeric( $user_id ) && ! empty( $items ) ) { 1179 foreach ( $items as $value ) { 1180 1181 // Maybe string with commas 1182 $value = is_string( $value ) 1183 ? explode( ',', $value ) 1184 : (array) $value; 1185 1186 // Add user ID to topics favorited users 1187 foreach ( $value as $fav ) { 1188 bbp_add_user_favorite( $user_id, $this->callback_topicid( $fav ) ); 1195 1189 } 1196 1190 } … … 1226 1220 * _bbp_old_reply_to_id // The old reply to ID 1227 1221 */ 1228 if ( '_id' == substr( $key, -3 ) && ( true === $this->sync_table ) ) {1222 if ( '_id' === substr( $key, -3 ) && ( true === $this->sync_table ) ) { 1229 1223 $this->wpdb->insert( $this->sync_table_name, array( 'value_type' => 'post', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value ) ); 1230 1224 } … … 1236 1230 * value using convert_reply_to_parents() 1237 1231 */ 1238 if ( ( 'reply' == $to_type ) && ( '_bbp_old_reply_to_id'== $key ) ) {1232 if ( ( 'reply' === $to_type ) && ( '_bbp_old_reply_to_id' === $key ) ) { 1239 1233 add_post_meta( $post_id, '_bbp_reply_to', $value ); 1240 1234 } … … 1600 1594 } 1601 1595 1602 if ( $tablename == $this->wpdb->users ) {1596 if ( $tablename === $this->wpdb->users ) { 1603 1597 $rval[] = 'role'; 1604 1598 $rval[] = 'yim'; … … 1606 1600 $rval[] = 'jabber'; 1607 1601 } 1602 1608 1603 return $rval; 1609 1604 } … … 1638 1633 */ 1639 1634 private function callback_forumid( $field ) { 1640 if ( ! isset( $this->map_forumid[ $field] ) ) {1635 if ( ! isset( $this->map_forumid[ $field ] ) ) { 1641 1636 if ( ! empty( $this->sync_table ) ) { 1642 1637 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_forum_id" AND meta_value = "%s" LIMIT 1', $field ) ); … … 1646 1641 1647 1642 if ( !is_null( $row ) ) { 1648 $this->map_forumid[ $field] = $row->value_id;1643 $this->map_forumid[ $field ] = $row->value_id; 1649 1644 } else { 1650 $this->map_forumid[ $field] = 0;1651 } 1652 } 1653 return $this->map_forumid[ $field];1645 $this->map_forumid[ $field ] = 0; 1646 } 1647 } 1648 return $this->map_forumid[ $field ]; 1654 1649 } 1655 1650 … … 1661 1656 */ 1662 1657 private function callback_topicid( $field ) { 1663 if ( ! isset( $this->map_topicid[ $field] ) ) {1658 if ( ! isset( $this->map_topicid[ $field ] ) ) { 1664 1659 if ( ! empty( $this->sync_table ) ) { 1665 1660 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_topic_id" AND meta_value = "%s" LIMIT 1', $field ) ); … … 1669 1664 1670 1665 if ( !is_null( $row ) ) { 1671 $this->map_topicid[ $field] = $row->value_id;1666 $this->map_topicid[ $field ] = $row->value_id; 1672 1667 } else { 1673 $this->map_topicid[ $field] = 0;1674 } 1675 } 1676 return $this->map_topicid[ $field];1668 $this->map_topicid[ $field ] = 0; 1669 } 1670 } 1671 return $this->map_topicid[ $field ]; 1677 1672 } 1678 1673 … … 1686 1681 */ 1687 1682 private function callback_reply_to( $field ) { 1688 if ( ! isset( $this->map_reply_to[ $field] ) ) {1683 if ( ! isset( $this->map_reply_to[ $field ] ) ) { 1689 1684 if ( ! empty( $this->sync_table ) ) { 1690 1685 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_reply_id" AND meta_value = "%s" LIMIT 1', $field ) ); … … 1694 1689 1695 1690 if ( !is_null( $row ) ) { 1696 $this->map_reply_to[ $field] = $row->value_id;1691 $this->map_reply_to[ $field ] = $row->value_id; 1697 1692 } else { 1698 $this->map_reply_to[ $field] = 0;1699 } 1700 } 1701 return $this->map_reply_to[ $field];1693 $this->map_reply_to[ $field ] = 0; 1694 } 1695 } 1696 return $this->map_reply_to[ $field ]; 1702 1697 } 1703 1698 … … 1709 1704 */ 1710 1705 private function callback_userid( $field ) { 1711 if ( ! isset( $this->map_userid[ $field] ) ) {1706 if ( ! isset( $this->map_userid[ $field ] ) ) { 1712 1707 if ( ! empty( $this->sync_table ) ) { 1713 1708 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) ); … … 1717 1712 1718 1713 if ( !is_null( $row ) ) { 1719 $this->map_userid[ $field] = $row->value_id;1714 $this->map_userid[ $field ] = $row->value_id; 1720 1715 } else { 1721 if ( ! empty( $_POST['_bbp_converter_convert_users'] ) && ( $_POST['_bbp_converter_convert_users']== 1 ) ) {1722 $this->map_userid[ $field] = 0;1723 } else { 1724 $this->map_userid[ $field] = $field;1725 } 1726 } 1727 } 1728 return $this->map_userid[ $field];1716 if ( ! empty( $_POST['_bbp_converter_convert_users'] ) && ( (int) $_POST['_bbp_converter_convert_users'] === 1 ) ) { 1717 $this->map_userid[ $field ] = 0; 1718 } else { 1719 $this->map_userid[ $field ] = $field; 1720 } 1721 } 1722 } 1723 return $this->map_userid[ $field ]; 1729 1724 } 1730 1725 … … 1757 1752 $topicid = $this->callback_topicid( $field ); 1758 1753 if ( empty( $topicid ) ) { 1759 $this->map_topicid_to_forumid[ $topicid] = 0;1760 } elseif ( ! isset( $this->map_topicid_to_forumid[ $topicid] ) ) {1754 $this->map_topicid_to_forumid[ $topicid ] = 0; 1755 } elseif ( ! isset( $this->map_topicid_to_forumid[ $topicid ] ) ) { 1761 1756 $row = $this->wpdb->get_row( 'SELECT post_parent FROM ' . $this->wpdb->posts . ' WHERE ID = "' . $topicid . '" LIMIT 1' ); 1762 1757 1763 1758 if ( !is_null( $row ) ) { 1764 $this->map_topicid_to_forumid[ $topicid] = $row->post_parent;1759 $this->map_topicid_to_forumid[ $topicid ] = $row->post_parent; 1765 1760 } else { 1766 $this->map_topicid_to_forumid[ $topicid] = 0;1767 } 1768 } 1769 1770 return $this->map_topicid_to_forumid[ $topicid];1761 $this->map_topicid_to_forumid[ $topicid ] = 0; 1762 } 1763 } 1764 1765 return $this->map_topicid_to_forumid[ $topicid ]; 1771 1766 } 1772 1767 … … 1820 1815 if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === FALSE ) { 1821 1816 $file = preg_replace( '/.php/', '', $file ); 1822 if ( $platform == $file ) {1817 if ( $platform === $file ) { 1823 1818 $found = true; 1824 1819 continue;
Note: See TracChangeset
for help on using the changeset viewer.