Changeset 6191
- Timestamp:
- 12/28/2016 04:24:52 AM (9 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 7 edited
-
admin/converter.php (modified) (23 diffs)
-
admin/converters/e107v1.php (modified) (1 diff)
-
admin/tools.php (modified) (55 diffs)
-
common/functions.php (modified) (1 diff)
-
topics/functions.php (modified) (3 diffs)
-
users/capabilities.php (modified) (2 diffs)
-
users/functions.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/converter.php
r6184 r6191 664 664 KEY value_id (value_id), 665 665 KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length})) 666 ) {$charset_collate} ;";666 ) {$charset_collate}"; 667 667 668 668 dbDelta( $sql ); … … 1016 1016 // Get some data from the old forums 1017 1017 $field_list = array_unique( $field_list ); 1018 $forum_query = 'SELECT ' . implode( ',', $field_list ) . ' FROM ' . $this->opdb->prefix . $from_tablename . ' LIMIT ' . $start . ', ' . $this->max_rows; 1018 $fields = implode( ',', $field_list ); 1019 $forum_query = "SELECT {$fields} FROM {$this->opdb->prefix}{$from_tablename} LIMIT {$start}, {$this->max_rows}"; 1019 1020 $forum_array = $this->opdb->get_results( $forum_query, ARRAY_A ); 1020 1021 … … 1254 1255 1255 1256 if ( ! empty( $this->sync_table ) ) { 1256 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;1257 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 1257 1258 } else { 1258 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_forum_parent_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;1259 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 1259 1260 } 1260 1261 … … 1265 1266 foreach ( (array) $forum_array as $row ) { 1266 1267 $parent_id = $this->callback_forumid( $row->meta_value ); 1267 $this->wpdb->query( 'UPDATE ' . $this->wpdb->posts . ' SET post_parent = "' . $parent_id . '" WHERE ID = "' . $row->value_id . '" LIMIT 1');1268 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) ); 1268 1269 $has_update = true; 1269 1270 } … … 1286 1287 1287 1288 if ( ! empty( $this->sync_table ) ) { 1288 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_sticky_status_id" AND meta_value = "sticky" LIMIT ' . $start . ', ' . $this->max_rows;1289 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 1289 1290 } else { 1290 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_sticky_status_id" AND meta_value = "sticky" LIMIT ' . $start . ', ' . $this->max_rows;1291 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 1291 1292 } 1292 1293 … … 1317 1318 1318 1319 if ( ! empty( $this->sync_table ) ) { 1319 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_sticky_status_id" AND meta_value = "super-sticky" LIMIT ' . $start . ', ' . $this->max_rows;1320 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 1320 1321 } else { 1321 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_sticky_status_id" AND meta_value = "super-sticky" LIMIT ' . $start . ', ' . $this->max_rows;1322 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 1322 1323 } 1323 1324 … … 1348 1349 1349 1350 if ( ! empty( $this->sync_table ) ) { 1350 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_closed_status_id" AND meta_value = "closed" LIMIT ' . $start . ', ' . $this->max_rows;1351 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 1351 1352 } else { 1352 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_closed_status_id" AND meta_value = "closed" LIMIT ' . $start . ', ' . $this->max_rows;1353 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 1353 1354 } 1354 1355 … … 1375 1376 1376 1377 if ( ! empty( $this->sync_table ) ) { 1377 $query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;1378 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 1378 1379 } else { 1379 $query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;1380 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 1380 1381 } 1381 1382 … … 1386 1387 foreach ( (array) $reply_to_array as $row ) { 1387 1388 $reply_to = $this->callback_reply_to( $row->meta_value ); 1388 $this->wpdb->query( 'UPDATE ' . $this->wpdb->postmeta . ' SET meta_value = "' . $reply_to . '" WHERE meta_key = "_bbp_reply_to" AND post_id = "' . $row->value_id . '" LIMIT 1');1389 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) ); 1389 1390 $has_update = true; 1390 1391 } … … 1405 1406 1406 1407 if ( ! empty( $this->sync_table ) ) { 1407 $query = 'SELECT sync_table1.value_id AS topic_id, sync_table1.meta_value AS topic_is_anonymous, sync_table2.meta_value AS topic_author1408 FROM ' . $this->sync_table_name . 'AS sync_table11409 INNER JOIN ' . $this->sync_table_name . 'AS sync_table21408 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS topic_id, sync_table1.meta_value AS topic_is_anonymous, sync_table2.meta_value AS topic_author 1409 FROM {$this->sync_table_name} AS sync_table1 1410 INNER JOIN {$this->sync_table_name} AS sync_table2 1410 1411 ON ( sync_table1.value_id = sync_table2.value_id ) 1411 WHERE sync_table1.meta_value = "true"1412 AND sync_table2.meta_key = "_bbp_old_topic_author_name_id"1413 LIMIT ' . $start . ', ' . $this->max_rows;1412 WHERE sync_table1.meta_value = %s 1413 AND sync_table2.meta_key = %s 1414 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 1414 1415 } else { 1415 $query = 'SELECT wp_postmeta1.post_id AS topic_id, wp_postmeta1.meta_value AS topic_is_anonymous, wp_postmeta2.meta_value AS topic_author1416 FROM ' . $this->wpdb->postmeta . 'AS wp_postmeta11417 INNER JOIN ' . $this->wpdb->postmeta . 'AS wp_postmeta21416 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS topic_id, wp_postmeta1.meta_value AS topic_is_anonymous, wp_postmeta2.meta_value AS topic_author 1417 FROM {$this->wpdb->postmeta} AS wp_postmeta1 1418 INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2 1418 1419 ON ( wp_postmeta1.post_id = wp_postmeta2.post_id ) 1419 WHERE wp_postmeta1.meta_value = "true"1420 AND wp_postmeta2.meta_key = "_bbp_old_topic_author_name_id"1421 LIMIT ' . $start . ', ' . $this->max_rows;1420 WHERE wp_postmeta1.meta_value = %s 1421 AND wp_postmeta2.meta_key = %s 1422 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 1422 1423 1423 1424 } … … 1429 1430 foreach ( (array) $anonymous_topics as $row ) { 1430 1431 $anonymous_topic_author_id = 0; 1431 $this->wpdb->query( 'UPDATE ' . $this->wpdb->posts . ' SET post_author = "' . $anonymous_topic_author_id . '" WHERE ID = "' . $row->topic_id . '" LIMIT 1');1432 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) ); 1432 1433 1433 1434 add_post_meta( $row->topic_id, '_bbp_anonymous_name', $row->topic_author ); … … 1451 1452 1452 1453 if ( ! empty( $this->sync_table ) ) { 1453 $query = 'SELECT sync_table1.value_id AS reply_id, sync_table1.meta_value AS reply_is_anonymous, sync_table2.meta_value AS reply_author1454 FROM ' . $this->sync_table_name . 'AS sync_table11455 INNER JOIN ' . $this->sync_table_name . 'AS sync_table21454 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS reply_id, sync_table1.meta_value AS reply_is_anonymous, sync_table2.meta_value AS reply_author 1455 FROM {$this->sync_table_name} AS sync_table1 1456 INNER JOIN {$this->sync_table_name} AS sync_table2 1456 1457 ON ( sync_table1.value_id = sync_table2.value_id ) 1457 WHERE sync_table1.meta_value = "true"1458 AND sync_table2.meta_key = "_bbp_old_reply_author_name_id"1459 LIMIT ' . $start . ', ' . $this->max_rows;1458 WHERE sync_table1.meta_value = %s 1459 AND sync_table2.meta_key = %s 1460 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_reply_author_name_id' ); 1460 1461 } else { 1461 $query = 'SELECT wp_postmeta1.post_id AS reply_id, wp_postmeta1.meta_value AS reply_is_anonymous, wp_postmeta2.meta_value AS reply_author1462 FROM ' . $this->wpdb->postmeta . 'AS wp_postmeta11463 INNER JOIN ' . $this->wpdb->postmeta . 'AS wp_postmeta21462 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS reply_id, wp_postmeta1.meta_value AS reply_is_anonymous, wp_postmeta2.meta_value AS reply_author 1463 FROM {$this->wpdb->postmeta} AS wp_postmeta1 1464 INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2 1464 1465 ON ( wp_postmeta1.post_id = wp_postmeta2.post_id ) 1465 WHERE wp_postmeta1.meta_value = "true"1466 AND wp_postmeta2.meta_key = "_bbp_old_reply_author_name_id"1467 LIMIT ' . $start . ', ' . $this->max_rows;1466 WHERE wp_postmeta1.meta_value = %s 1467 AND wp_postmeta2.meta_key = %s 1468 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_reply_author_name_id' ); 1468 1469 1469 1470 } … … 1475 1476 foreach ( (array) $anonymous_replies as $row ) { 1476 1477 $anonymous_reply_author_id = 0; 1477 $this->wpdb->query( 'UPDATE ' . $this->wpdb->posts . ' SET post_author = "' . $anonymous_reply_author_id . '" WHERE ID = "' . $row->reply_id . '" LIMIT 1');1478 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) ); 1478 1479 1479 1480 add_post_meta( $row->reply_id, '_bbp_anonymous_name', $row->reply_author ); … … 1496 1497 1497 1498 if ( true === $this->sync_table ) { 1498 $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->posts . ' ON(value_id = ID) WHERE meta_key LIKE "_bbp_%" AND value_type = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows;1499 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE '_bbp_%' AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", 'post' ); 1499 1500 } else { 1500 $query = 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key LIKE "_bbp_%" GROUP BY post_id ORDER BY post_id DESC LIMIT ' . $this->max_rows;1501 $query = $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE '_bbp_%' GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}" ); 1501 1502 } 1502 1503 … … 1515 1516 1516 1517 if ( true === $this->sync_table ) { 1517 $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_old_user_id" AND value_type = "user" LIMIT ' . $this->max_rows;1518 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->users} ON(value_id = ID) WHERE meta_key = %s AND value_type = %s LIMIT {$this->max_rows}", '_bbp_old_user_id', 'user' ); 1518 1519 } else { 1519 $query = 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" LIMIT ' . $this->max_rows;1520 $query = $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$this->max_rows}", '_bbp_old_user_id' ); 1520 1521 } 1521 1522 … … 1548 1549 /** Delete bbconverter passwords **************************************/ 1549 1550 1550 $query = 'SELECT user_id, meta_value FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" LIMIT ' . $start . ', ' . $this->max_rows;1551 $query = $this->wpdb->prepare( "SELECT user_id, meta_value FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$start}, {$this->max_rows}", '_bbp_password' ); 1551 1552 update_option( '_bbp_converter_query', $query ); 1552 1553 … … 1557 1558 foreach ( $bbconverter as $value ) { 1558 1559 if ( is_serialized( $value['meta_value'] ) ) { 1559 $this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "" ' . 'WHERE ID = "' . $value['user_id'] . '"');1560 } else { 1561 $this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "' . $value['meta_value'] . '" ' . 'WHERE ID = "' . $value['user_id'] . '"');1562 $this->wpdb->query( 'DELETE FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" AND user_id = "' . $value['user_id'] . '"');1560 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) ); 1561 } else { 1562 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) ); 1563 $this->wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) ); 1563 1564 } 1564 1565 } … … 1613 1614 */ 1614 1615 public function callback_pass( $username, $password ) { 1615 $user = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT * FROM ' . $this->wpdb->users . ' WHERE user_login = "%s" AND user_pass = "" LIMIT 1', $username ) );1616 $user = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) ); 1616 1617 if ( ! empty( $user ) ) { 1617 $usermeta = $this->wpdb->get_row( 'SELECT * FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" AND user_id = "' . $user->ID . '" LIMIT 1');1618 $usermeta = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d LIMIT 1", '_bbp_password', $user->ID ) ); 1618 1619 1619 1620 if ( ! empty( $usermeta ) ) { 1620 1621 if ( $this->authenticate_pass( $password, $usermeta->meta_value ) ) { 1621 $this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "' . wp_hash_password( $password ) . '" ' . 'WHERE ID = "' . $user->ID . '"');1622 $this->wpdb->query( 'DELETE FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" AND user_id = "' . $user->ID . '"');1622 $this->wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", wp_hash_password( $password ), $user->ID ) ); 1623 $this->wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) ); 1623 1624 } 1624 1625 } … … 1635 1636 if ( ! isset( $this->map_forumid[ $field ] ) ) { 1636 1637 if ( ! empty( $this->sync_table ) ) { 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 ) );1638 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 1638 1639 } else { 1639 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_forum_id" AND meta_value = "%s" LIMIT 1', $field ) );1640 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 1640 1641 } 1641 1642 … … 1658 1659 if ( ! isset( $this->map_topicid[ $field ] ) ) { 1659 1660 if ( ! empty( $this->sync_table ) ) { 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 ) );1661 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1661 1662 } else { 1662 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_topic_id" AND meta_value = "%s" LIMIT 1', $field ) );1663 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1663 1664 } 1664 1665 … … 1683 1684 if ( ! isset( $this->map_reply_to[ $field ] ) ) { 1684 1685 if ( ! empty( $this->sync_table ) ) { 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 ) );1686 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1686 1687 } else { 1687 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_reply_id" AND meta_value = "%s" LIMIT 1', $field ) );1688 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1688 1689 } 1689 1690 … … 1706 1707 if ( ! isset( $this->map_userid[ $field ] ) ) { 1707 1708 if ( ! empty( $this->sync_table ) ) { 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 ) );1709 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1709 1710 } else { 1710 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) );1711 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1711 1712 } 1712 1713 … … 1754 1755 $this->map_topicid_to_forumid[ $topicid ] = 0; 1755 1756 } elseif ( ! isset( $this->map_topicid_to_forumid[ $topicid ] ) ) { 1756 $row = $this->wpdb->get_row( 'SELECT post_parent FROM ' . $this->wpdb->posts . ' WHERE ID = "' . $topicid . '" LIMIT 1');1757 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_parent FROM {$this->wpdb->posts} WHERE ID = %d LIMIT 1", $topicid ) ); 1757 1758 1758 1759 if ( !is_null( $row ) ) { -
trunk/src/includes/admin/converters/e107v1.php
r5951 r6191 577 577 if ( ! isset( $this->map_userid[ $field ] ) ) { 578 578 if ( ! empty( $this->sync_table ) ) { 579 $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 ) );579 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 580 580 } else { 581 $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) );581 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 582 582 } 583 583 -
trunk/src/includes/admin/tools.php
r6189 r6191 1090 1090 WHERE `topics`.`post_type` = '{$tpt}' 1091 1091 AND `topics`.`post_status` IN ( '{$pps}', '{$cps}' ) 1092 GROUP BY `topics`.`ID`) ;";1092 GROUP BY `topics`.`ID`)"; 1093 1093 1094 1094 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { … … 1119 1119 $result = __( 'Failed!', 'bbpress' ); 1120 1120 1121 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_voice_count' ;";1121 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_voice_count'"; 1122 1122 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1123 1123 return array( 1, sprintf( $statement, $result ) ); … … 1139 1139 AND `posts`.`post_status` IN ( '{$pps}', '{$cps}' ) 1140 1140 AND `posts`.`post_author` != '0' 1141 GROUP BY `postmeta`.`meta_value`) ;";1141 GROUP BY `postmeta`.`meta_value`)"; 1142 1142 1143 1143 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { … … 1168 1168 $result = __( 'Failed!', 'bbpress' ); 1169 1169 1170 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden' ;";1170 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden'"; 1171 1171 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1172 1172 return array( 1, sprintf( $statement, $result ) ); … … 1179 1179 $pps = bbp_get_pending_status_id(); 1180 1180 1181 $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}', '{$pps}' ) GROUP BY `post_parent`) ;";1181 $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}', '{$pps}' ) GROUP BY `post_parent`)"; 1182 1182 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { 1183 1183 return array( 2, sprintf( $statement, $result ) ); … … 1216 1216 AND `forummeta`.`meta_key` = '_bbp_old_forum_id' 1217 1217 WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "' 1218 GROUP BY `forum`.`ID` ;" );1218 GROUP BY `forum`.`ID`" ); 1219 1219 1220 1220 // Bail if forum IDs returned an error … … 1235 1235 1236 1236 // Attempt to update group meta 1237 $updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}' ;" );1237 $updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}'" ); 1238 1238 1239 1239 // Bump the count … … 1243 1243 1244 1244 // Update group to forum relationship data 1245 $group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}' ;" );1245 $group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}'" ); 1246 1246 if ( ! empty( $group_id ) ) { 1247 1247 … … 1250 1250 1251 1251 // Get the group status 1252 $group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}' ;" );1252 $group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}'" ); 1253 1253 1254 1254 // Sync up forum visibility based on group status … … 1343 1343 $result = __( 'Failed!', 'bbpress' ); 1344 1344 1345 $sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count', '_bbp_topic_count_hidden' ) ;";1345 $sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count', '_bbp_topic_count_hidden' )"; 1346 1346 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1347 1347 return array( 1, sprintf( $statement, $result ) ); … … 1425 1425 $result = __( 'Failed!', 'bbpress' ); 1426 1426 1427 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author` ;";1427 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`"; 1428 1428 $insert_rows = $bbp_db->get_results( $sql_select ); 1429 1429 … … 1442 1442 } 1443 1443 1444 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;";1444 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'"; 1445 1445 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1446 1446 return array( 3, sprintf( $statement, $result ) ); … … 1449 1449 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { 1450 1450 $chunk = "\n" . implode( ",\n", $chunk ); 1451 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk} ;";1451 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk}"; 1452 1452 1453 1453 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { … … 1477 1477 $result = __( 'Failed!', 'bbpress' ); 1478 1478 1479 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author` ;";1479 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`"; 1480 1480 $insert_rows = $bbp_db->get_results( $sql_select ); 1481 1481 … … 1494 1494 } 1495 1495 1496 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;";1496 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'"; 1497 1497 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1498 1498 return array( 3, sprintf( $statement, $result ) ); … … 1501 1501 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { 1502 1502 $chunk = "\n" . implode( ",\n", $chunk ); 1503 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk} ;";1503 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk}"; 1504 1504 1505 1505 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { … … 1530 1530 1531 1531 $key = $bbp_db->prefix . '_bbp_favorites'; 1532 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;" );1532 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'" ); 1533 1533 1534 1534 if ( is_wp_error( $users ) ) { … … 1536 1536 } 1537 1537 1538 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' ;" );1538 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "'" ); 1539 1539 1540 1540 if ( is_wp_error( $topics ) ) { … … 1565 1565 } 1566 1566 1567 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;";1567 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'"; 1568 1568 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1569 1569 return array( 4, sprintf( $statement, $result ) ); … … 1572 1572 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 1573 1573 $chunk = "\n" . implode( ",\n", $chunk ); 1574 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk} ;";1574 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk}"; 1575 1575 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 1576 1576 return array( 5, sprintf( $statement, $result ) ); … … 1600 1600 1601 1601 $key = $bbp_db->prefix . '_bbp_subscriptions'; 1602 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;" );1602 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'" ); 1603 1603 1604 1604 if ( is_wp_error( $users ) ) { … … 1606 1606 } 1607 1607 1608 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' ;" );1608 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "'" ); 1609 1609 if ( is_wp_error( $topics ) ) { 1610 1610 return array( 2, sprintf( $statement, $result ) ); … … 1634 1634 } 1635 1635 1636 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;";1636 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'"; 1637 1637 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1638 1638 return array( 4, sprintf( $statement, $result ) ); … … 1641 1641 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 1642 1642 $chunk = "\n" . implode( ",\n", $chunk ); 1643 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk} ;";1643 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk}"; 1644 1644 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 1645 1645 return array( 5, sprintf( $statement, $result ) ); … … 1669 1669 1670 1670 $key = $bbp_db->prefix . '_bbp_forum_subscriptions'; 1671 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;" );1671 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'" ); 1672 1672 1673 1673 if ( is_wp_error( $users ) ) { … … 1675 1675 } 1676 1676 1677 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' ;" );1677 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "'" ); 1678 1678 if ( is_wp_error( $forums ) ) { 1679 1679 return array( 2, sprintf( $statement, $result ) ); … … 1703 1703 } 1704 1704 1705 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}' ;";1705 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}'"; 1706 1706 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 1707 1707 return array( 4, sprintf( $statement, $result ) ); … … 1710 1710 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 1711 1711 $chunk = "\n" . implode( ",\n", $chunk ); 1712 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk} ;";1712 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk}"; 1713 1713 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 1714 1714 return array( 5, sprintf( $statement, $result ) ); … … 1801 1801 1802 1802 // First, delete everything. 1803 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' ) ;" ) ) ) {1803 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' )" ) ) ) { 1804 1804 return array( 1, sprintf( $statement, $result ) ); 1805 1805 } … … 1816 1816 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1817 1817 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1818 GROUP BY `topic`.`ID` ) ;" ) ) ) {1818 GROUP BY `topic`.`ID` )" ) ) ) { 1819 1819 return array( 2, sprintf( $statement, $result ) ); 1820 1820 } … … 1825 1825 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1826 1826 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id' 1827 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' ) ;" ) ) ) {1827 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' )" ) ) ) { 1828 1828 return array( 3, sprintf( $statement, $result ) ); 1829 1829 } … … 1834 1834 FROM `{$bbp_db->posts}` AS `forum` INNER JOIN `{$bbp_db->posts}` AS `topic` ON `forum`.`ID` = `topic`.`post_parent` 1835 1835 WHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}' 1836 GROUP BY `forum`.`ID` ) ;" ) ) ) {1836 GROUP BY `forum`.`ID` )" ) ) ) { 1837 1837 return array( 4, sprintf( $statement, $result ) ); 1838 1838 } … … 1843 1843 FROM `{$bbp_db->posts}` AS `forum` LEFT JOIN `{$bbp_db->postmeta}` AS `topic` 1844 1844 ON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id' 1845 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' ) ;" ) ) ) {1845 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' )" ) ) ) { 1846 1846 return array( 5, sprintf( $statement, $result ) ); 1847 1847 } … … 1852 1852 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1853 1853 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1854 GROUP BY `topic`.`ID` ) ;" ) ) ) {1854 GROUP BY `topic`.`ID` )" ) ) ) { 1855 1855 return array( 6, sprintf( $statement, $result ) ); 1856 1856 } … … 1861 1861 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1862 1862 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id' 1863 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' ) ;" ) ) ) {1863 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' )" ) ) ) { 1864 1864 return array( 7, sprintf( $statement, $result ) ); 1865 1865 } … … 1870 1870 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1871 1871 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1872 GROUP BY `topic`.`ID` ) ;" ) ) ) {1872 GROUP BY `topic`.`ID` )" ) ) ) { 1873 1873 return array( 8, sprintf( $statement, $result ) ); 1874 1874 } … … 1879 1879 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1880 1880 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' 1881 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' ) ;" ) ) ) {1881 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' )" ) ) ) { 1882 1882 return array( 9, sprintf( $statement, $result ) ); 1883 1883 } 1884 1884 1885 1885 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 1886 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft' ;" );1886 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft'" ); 1887 1887 if ( is_wp_error( $forums ) ) { 1888 1888 return array( 10, sprintf( $statement, $result ) ); … … 1928 1928 $result = __( 'Failed!', 'bbpress' ); 1929 1929 1930 $forums = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' ;" );1930 $forums = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "'" ); 1931 1931 1932 1932 // Bail if no forums found … … 1997 1997 $changed = 0; 1998 1998 1999 $closed_topics = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = 'closed' ;" );1999 $closed_topics = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = 'closed'" ); 2000 2000 2001 2001 // Bail if no closed topics found … … 2066 2066 2067 2067 // First, delete everything. 2068 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_forum_id' ;" ) ) ) {2068 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_forum_id'" ) ) ) { 2069 2069 return array( 1, sprintf( $statement, $result ) ); 2070 2070 } … … 2080 2080 AS `topic` 2081 2081 WHERE `topic`.`post_type` = '{$tpt}' 2082 GROUP BY `topic`.`ID` ) ;" ) ) ) {2082 GROUP BY `topic`.`ID` )" ) ) ) { 2083 2083 return array( 2, sprintf( $statement, $result ) ); 2084 2084 } … … 2094 2094 WHERE `topic`.`post_type` = '{$tpt}' 2095 2095 AND `reply`.`post_type` = '{$rpt}' 2096 GROUP BY `reply`.`ID` ) ;" ) ) ) {2096 GROUP BY `reply`.`ID` )" ) ) ) { 2097 2097 return array( 3, sprintf( $statement, $result ) ); 2098 2098 } … … 2121 2121 2122 2122 // First, delete everything. 2123 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_topic_id' ;" ) ) ) {2123 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_topic_id'" ) ) ) { 2124 2124 return array( 1, sprintf( $statement, $result ) ); 2125 2125 } … … 2135 2135 AS `topic` 2136 2136 WHERE `topic`.`post_type` = '{$tpt}' 2137 GROUP BY `topic`.`ID` ) ;" ) ) ) {2137 GROUP BY `topic`.`ID` )" ) ) ) { 2138 2138 return array( 3, sprintf( $statement, $result ) ); 2139 2139 } … … 2149 2149 WHERE `topic`.`post_type` = '{$tpt}' 2150 2150 AND `reply`.`post_type` = '{$rpt}' 2151 GROUP BY `reply`.`ID` ) ;" ) ) ) {2151 GROUP BY `reply`.`ID` )" ) ) ) { 2152 2152 return array( 4, sprintf( $statement, $result ) ); 2153 2153 } … … 2176 2176 2177 2177 // Delete cases where `_bbp_reply_to` was accidentally set to itself 2178 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value` ;" ) ) ) {2178 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`" ) ) ) { 2179 2179 return array( 1, sprintf( $statement, $result ) ); 2180 2180 } … … 2193 2193 ON `a`.`menu_order` = `b`.`menu_order` 2194 2194 AND `a`.`post_parent` = `b`.`post_parent` 2195 WHERE `post_type` = '{$rpt}' ;", OBJECT_K );2195 WHERE `post_type` = '{$rpt}'", OBJECT_K ); 2196 2196 2197 2197 // Bail if no replies returned … … 2229 2229 $changed = $total = 0; 2230 2230 $key = $bbp_db->prefix . '_bbp_favorites'; 2231 $favorites = $bbp_db->get_results( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = '{$key}'");2231 $favorites = $bbp_db->get_results( $bbp_db->prepare( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s", $key ) ); 2232 2232 2233 2233 // Bail if no closed topics found … … 2292 2292 $changed = $total = 0; 2293 2293 $key = $bbp_db->prefix . '_bbp_subscriptions'; 2294 $subscriptions = $bbp_db->get_results( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = '{$key}'");2294 $subscriptions = $bbp_db->get_results( $bbp_db->prepare( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s", $key ) ); 2295 2295 2296 2296 // Bail if no closed topics found … … 2468 2468 $statement = __( 'Deleting Post Meta… %s', 'bbpress' ); 2469 2469 $sql_meta = implode( "', '", $sql_meta ); 2470 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}') ;";2470 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}')"; 2471 2471 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2472 2472 $messages[] = sprintf( $statement, $result ); … … 2482 2482 $statement = __( 'Deleting Post Revisions… %s', 'bbpress' ); 2483 2483 $sql_meta = implode( "', '", $sql_meta ); 2484 $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_parent` IN ('{$sql_meta}') AND `post_type` = 'revision' ;";2484 $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_parent` IN ('{$sql_meta}') AND `post_type` = 'revision'"; 2485 2485 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2486 2486 $messages[] = sprintf( $statement, $result ); … … 2490 2490 2491 2491 $statement = __( 'Deleting Forum Moderators… %s', 'bbpress' ); 2492 $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'forum-mod' ;";2492 $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'forum-mod'"; 2493 2493 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2494 2494 $messages[] = sprintf( $statement, $result ); … … 2497 2497 2498 2498 $statement = __( 'Deleting Topic Tags… %s', 'bbpress' ); 2499 $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag' ;";2499 $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag'"; 2500 2500 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2501 2501 $messages[] = sprintf( $statement, $result ); … … 2513 2513 $statement = __( 'Deleting Imported Users… %s', 'bbpress' ); 2514 2514 $sql_meta = implode( "', '", $sql_meta ); 2515 $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}') ;";2515 $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}')"; 2516 2516 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2517 2517 $messages[] = sprintf( $statement, $result ); 2518 2518 $statement = __( 'Deleting Imported User Meta… %s', 'bbpress' ); 2519 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}') ;";2519 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}')"; 2520 2520 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2521 2521 $messages[] = sprintf( $statement, $result ); … … 2525 2525 // Next, if we still have users that were not imported delete that meta data 2526 2526 $statement = __( 'Deleting User Meta… %s', 'bbpress' ); 2527 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%' ;";2527 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%'"; 2528 2528 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 2529 2529 $messages[] = sprintf( $statement, $result ); -
trunk/src/includes/common/functions.php
r6141 r6191 1758 1758 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1759 1759 $bbp_db = bbp_db(); 1760 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type );1760 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = %s ORDER BY ID DESC", $parent_id, $post_type ); 1761 1761 $child_ids = (array) $bbp_db->get_col( $query ); 1762 1762 -
trunk/src/includes/topics/functions.php
r6146 r6191 2795 2795 $post_status = "'" . implode( "','", $statuses ) . "'"; 2796 2796 $bbp_db = bbp_db(); 2797 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() );2797 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = %s", $topic_id, bbp_get_reply_post_type() ); 2798 2798 $reply_count = $bbp_db->get_var( $query ); 2799 2799 } … … 2970 2970 // Query the DB to get voices in this topic 2971 2971 $bbp_db = bbp_db(); 2972 $query = $bbp_db->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() );2972 $query = $bbp_db->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = %s AND post_type = %s ) OR ( ID = %d AND post_type = %s )", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2973 2973 $voices = (int) $bbp_db->get_var( $query ); 2974 2974 … … 3011 3011 // Query the DB to get anonymous replies in this topic 3012 3012 $bbp_db = bbp_db(); 3013 $query = $bbp_db->prepare( "SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() );3013 $query = $bbp_db->prepare( "SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = %s AND post_type = %s AND post_author = 0 ) OR ( ID = %d AND post_type = %s AND post_author = 0 )", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 3014 3014 $replies = (int) $bbp_db->get_var( $query ); 3015 3015 -
trunk/src/includes/users/capabilities.php
r6116 r6191 505 505 506 506 // Get topics and replies 507 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = '%s'AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() );507 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = %s AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() ); 508 508 $posts = $bbp_db->get_col( $query ); 509 509 … … 596 596 597 597 // Get topics and replies 598 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = '%s'AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id() );598 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = %s AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id() ); 599 599 $posts = $bbp_db->get_col( $query ); 600 600 -
trunk/src/includes/users/functions.php
r6141 r6191 1866 1866 1867 1867 $bbp_db = bbp_db(); 1868 $count = (int) $bbp_db->get_var( "SELECT COUNT(*) 1869 FROM {$bbp_db->posts} 1870 WHERE post_type = '" . bbp_get_topic_post_type() . "' 1871 AND post_status = '" . bbp_get_closed_status_id() . "' 1872 AND post_author = $user_id;" 1873 ); 1868 $count = (int) $bbp_db->get_var( $bbp_db->prepare( 1869 "SELECT COUNT(*) 1870 FROM {$bbp_db->posts} 1871 WHERE post_type = %s 1872 AND post_status = %s 1873 AND post_author = %d" 1874 ), bbp_get_topic_post_type(), bbp_get_closed_status_id(), $user_id ); 1874 1875 1875 1876 return (int) apply_filters( 'bbp_get_user_closed_topic_count', $count, $user_id ); … … 2185 2186 // Bail if no user password to convert 2186 2187 $bbp_db = bbp_db(); 2187 $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->users} INNER JOIN {$bbp_db->usermeta} ON user_id = ID WHERE meta_key = '_bbp_class' AND user_login = '%s' LIMIT 1", $username );2188 $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->users} INNER JOIN {$bbp_db->usermeta} ON user_id = ID WHERE meta_key = %s AND user_login = %s LIMIT 1", '_bbp_class', $username ); 2188 2189 $row = $bbp_db->get_row( $query ); 2189 2190 if ( empty( $row ) || is_wp_error( $row ) ) {
Note: See TracChangeset
for help on using the changeset viewer.