1383 | | // Get an array of reply id's to update the menu oder for each reply |
1384 | | $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` |
| 1385 | // Set the menu_order of pending replies who have a post_date_gmt of 0 (posts that have been posted but never published) |
| 1386 | $wpdb->update('wp_posts', array('menu_order'=>'0'), array('post_type'=>$rpt, 'post_status'=>$pst, 'post_date_gmt'=>'0000-00-00 00:00:00') ); |
| 1387 | |
| 1388 | // Post type |
| 1389 | $offset = 0; |
| 1390 | $limit = 500; |
| 1391 | $done = false; |
| 1392 | $replies_count = 0; |
| 1393 | |
| 1394 | $queryTimes = array(); |
| 1395 | $updateTimes = array(); |
| 1396 | |
| 1397 | // ready steady GO |
| 1398 | $startTime = microtime(true); |
| 1399 | |
| 1400 | // first look through the menu_order 0 replies. Are there any in topics which aren't spammed or pending? Only topics that are.... |
| 1401 | $replies_mozero = $wpdb->get_results( "SELECT `a`.`post_parent` FROM `{$wpdb->posts}` AS `a` |
1393 | | WHERE `post_type` = '{$rpt}';", OBJECT_K ); |
| 1410 | |
| 1411 | LIMIT {$limit}", OBJECT_K ); |
| 1412 | |
| 1413 | while( !$done ){ |
| 1414 | // Get an array of reply id's to update the menu oder for each reply |
| 1415 | $startQueryTime = microtime(true); |
| 1416 | $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` |
| 1417 | INNER JOIN ( |
| 1418 | SELECT `menu_order`, `post_parent` |
| 1419 | FROM `{$wpdb->posts}` WHERE `post_type` = '{$rpt}' AND `menu_order` != 0 |
| 1420 | GROUP BY `menu_order`, `post_parent` |
| 1421 | HAVING COUNT( * ) >1 |
| 1422 | )`b` |
| 1423 | ON `a`.`menu_order` = `b`.`menu_order` |
| 1424 | AND `a`.`post_parent` = `b`.`post_parent` |
| 1425 | |
| 1426 | LIMIT {$limit}", OBJECT_K ); |
1400 | | // Recalculate the menu order position for each reply |
1401 | | foreach ( $replies as $reply ) { |
1402 | | bbp_update_reply_position( $reply->ID ); |
| 1436 | $replies_count += count( $replies ); |
| 1437 | $offset += $limit; |
| 1438 | |
| 1439 | // Bail if no replies returned |
| 1440 | if ( $replies_count == 0 ) { |
| 1441 | return array( 1, sprintf( $statement, $result ) ); |
| 1442 | } |
| 1443 | |
| 1444 | // Recalculate the menu order position for each reply |
| 1445 | foreach ( $replies as $reply ) { |
| 1446 | $startUpdateTime = microtime(true); |
| 1447 | bbp_update_reply_position( $reply->ID ); |
| 1448 | $endUpdateTime = microtime(true); |
| 1449 | $updateTimes[] = ( $endUpdateTime - $startUpdateTime ); |
| 1450 | |
| 1451 | } |
| 1469 | /** |
| 1470 | * standard deviation thing from http://php.net/manual/en/function.stats-standard-deviation.php |
| 1471 | */ |
| 1472 | |
| 1473 | if (!function_exists('stats_standard_deviation')) { |
| 1474 | /** |
| 1475 | * This user-land implementation follows the implementation quite strictly; |
| 1476 | * it does not attempt to improve the code or algorithm in any way. It will |
| 1477 | * raise a warning if you have fewer than 2 values in your array, just like |
| 1478 | * the extension does (although as an E_USER_WARNING, not E_WARNING). |
| 1479 | * |
| 1480 | * @param array $a |
| 1481 | * @param bool $sample [optional] Defaults to false |
| 1482 | * @return float|bool The standard deviation or false on error. |
| 1483 | */ |
| 1484 | function stats_standard_deviation(array $a, $sample = false) { |
| 1485 | $n = count($a); |
| 1486 | if ($n === 0) { |
| 1487 | trigger_error("The array has zero elements", E_USER_WARNING); |
| 1488 | return false; |
| 1489 | } |
| 1490 | if ($sample && $n === 1) { |
| 1491 | trigger_error("The array has only 1 element", E_USER_WARNING); |
| 1492 | return false; |
| 1493 | } |
| 1494 | $mean = array_sum($a) / $n; |
| 1495 | $carry = 0.0; |
| 1496 | foreach ($a as $val) { |
| 1497 | $d = ((double) $val) - $mean; |
| 1498 | $carry += $d * $d; |
| 1499 | }; |
| 1500 | if ($sample) { |
| 1501 | --$n; |
| 1502 | } |
| 1503 | return sqrt($carry / $n); |
| 1504 | } |
| 1505 | } |
| 1506 | |