Ticket #20316: 20316.2.diff
File 20316.2.diff, 4.3 KB (added by , 12 years ago) |
---|
-
src/wp-admin/includes/schema.php
546 546 547 547 // delete obsolete magpie stuff 548 548 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); 549 549 550 // clear transient data 550 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_%' OR option_name LIKE '\_site\_transient\_%'" ); 551 $time = time(); 552 delete_expired_transients( $time ); 553 554 if ( is_main_site() && is_main_network() ) 555 delete_expired_site_transients( $time ); 551 556 } 552 557 553 558 /** -
src/wp-admin/includes/upgrade.php
1215 1215 */ 1216 1216 function upgrade_network() { 1217 1217 global $wp_current_db_version, $wpdb; 1218 1219 // Always 1220 if ( is_main_network() ) 1221 delete_expired_site_transients(); 1222 1218 1223 // 2.8 1219 1224 if ( $wp_current_db_version < 11549 ) { 1220 1225 $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); -
src/wp-includes/option.php
515 515 } 516 516 517 517 /** 518 * Delete all expired transients from the database 519 * 520 * @package WordPress 521 * @subpackage Option 522 * @since 3.7.0 523 * 524 * @param int|bool $time If timestamp is passed, only expired transients less than the 525 * passed time will be deleted. 526 */ 527 function delete_expired_transients( $time = false ) { 528 global $wpdb; 529 530 $wpdb->suppress_errors(); 531 532 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); 533 534 $wpdb->suppress_errors( false ); 535 536 if ( ! $installed ) 537 return; 538 539 if ( ! $time ) 540 $time = time(); 541 542 $wpdb->query( "DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE 543 a.option_name LIKE '\_transient\_%' AND 544 a.option_name NOT LIKE '\_transient\_timeout\_%' AND 545 b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) 546 AND b.option_value < $time" ); 547 } 548 549 /** 550 * Delete all expired site transients from the database 551 * 552 * @package WordPress 553 * @subpackage Option 554 * @since 3.7.0 555 * 556 * @param int|bool $time If timestamp is passed, only expired transients less than the 557 * passed time will be deleted. 558 */ 559 function delete_expired_site_transients( $time = false ) { 560 global $wpdb; 561 562 $wpdb->suppress_errors(); 563 564 $installed = $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); 565 566 $wpdb->suppress_errors( false ); 567 568 if ( ! $installed ) 569 return; 570 571 if ( ! $time ) 572 $time = time(); 573 574 $wpdb->query( "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b WHERE 575 a.meta_key LIKE '\_site\_transient\_%' AND 576 a.meta_key NOT LIKE '\_site\_transient\_timeout\_%' AND 577 b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) 578 AND b.meta_value < $time" ); 579 } 580 581 /** 518 582 * Saves and restores user interface settings stored in a cookie. 519 583 * 520 584 * Checks if the current user-settings cookie is updated and stores it. When no -
tests/phpunit/tests/option/transient.php
33 33 $this->assertEquals( $value, get_transient( $key ) ); 34 34 $this->assertTrue( delete_transient( $key ) ); 35 35 } 36 37 function get_non_cron_transients() { 38 global $wpdb; 39 $rows = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name LIKE '\_transient\_%'" ); 40 return wp_list_filter( $rows, array( 'option_name' => '_transient_doing_cron' ), 'NOT' ); 41 } 42 43 function test_delete_expired_transients() { 44 $before_time = time(); 45 sleep(1); 46 set_transient( 'foo', 'bar', 1 ); 47 sleep(2); 48 49 $this->assertCount( 2, $this->get_non_cron_transients() ); 50 51 delete_expired_transients( $before_time ); 52 53 $this->assertCount( 2, $this->get_non_cron_transients() ); 54 55 delete_expired_transients(); 56 57 $this->assertCount( 0, $this->get_non_cron_transients() ); 58 } 36 59 }