public/wordpress/wp-content/plugins/backupbuddy/classes/housekeeping.php
/* cleanup_transients()
	 *
	 * Cleans up expired or corrupted transients.
	 *
	 * bool	$remote_unexpiring	When true unexpiring transients (value row exists but expiration row does NOT exist) will be purged. Useful if expiration row is missing resulting in infinite lasting transient(s). Default: false.
	 *
	 */
cleanup_transients()
Cleans up expired or corrupted transients.

bool $remote_unexpiring      When true unexpiring transients (value row exists but expiration row does NOT exist) will be purged. Useful if expiration row is missing resulting in infinite lasting transient(s). Default: false.
cleanup_transients () Cleans up expired or corrupted transients . bool $remote_unexpiring When true unexpiring transients ( value row exists but expiration row does NOT exist ) will be purged . Useful if expiration row is missing resulting in infinite lasting transient ( s ) . Default : false .
public static function cleanup_transients( $remove_unexpiring = false ) {
		pb_backupbuddy::status( 'details', 'Cleaning up expired or corrupt transients.' );
		if ( true === $remove_unexpiring ) {
			pb_backupbuddy::status( 'details', 'Option selected to purge unexpiring transients.' );
		} else {
			pb_backupbuddy::status( 'details', 'Option NOT selected to purge unexpiring transients.' );
		}
		global $wpdb;
		$sql = "SELECT `option_name` AS `name`, `option_value` AS `value`
			  FROM  `" . $wpdb->options . "`
			  WHERE `option_name` LIKE '%transient_%'
			  ORDER BY `option_name` LIMIT 1000"; 
		$results = $wpdb->get_results( $sql );
		$transients = array();
		foreach ( $results as $result ) {
			if ( 0 === strpos( $result->name, '_site_transient_' ) ) {
				if ( 0 === strpos( $result->name, '_site_transient_timeout_') ) {
					$transients[ str_replace( '_site_transient_timeout_', '', $result->name ) ]['expires'] = $result->value;
					$transients[ str_replace( '_site_transient_timeout_', '', $result->name ) ]['type'] = 'site';
				} else {
					$transients[ str_replace( '_site_transient_', '', $result->name ) ]['found'] = true;
					$transients[ str_replace( '_site_transient_', '', $result->name ) ]['type'] = 'site';
				}
			} else {
				if ( 0 === strpos( $result->name, '_transient_timeout_') ) {
					$transients[ str_replace( '_transient_timeout_', '', $result->name ) ]['expires'] = $result->value;
					$transients[ str_replace( '_transient_timeout_', '', $result->name ) ]['type'] = 'normal';
				} else {
					$transients[ str_replace( '_transient_', '', $result->name ) ]['found'] = true;
					$transients[ str_replace( '_transient_', '', $result->name ) ]['type'] = 'normal';
				}
			}
		}
		pb_backupbuddy::status( 'details', 'Found `' . count( $transients ) . '` transients.' );
		foreach( $transients as $transient_name => $transient ) {
			if ( isset( $transient['found'] ) && ( true === $transient['found'] ) ) { 
				if ( ! isset( $transient['expires'] ) ) { 
					if ( true === $remove_unexpiring ) { 
						if ( 'site' == $transient['type'] ) { 
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_site_transient_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; no expire)' );
						} else { 
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_transient_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; no expire)' );
						}
					}
				} else { 
					if ( $transient['expires'] > time() ) { 
						if ( 'site' == $transient['type'] ) { 
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_site_transient_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; expires; PAST expiration)' );
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_site_transient_timeout_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; expires; PAST expiration)' );
						} else { 
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_transient_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; expires; PAST expiration)' );
							$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_transient_timeout_' . $transient_name . "' LIMIT 1";
							$wpdb->query( $sql );
							pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (value found; expires; PAST expiration)' );
						}
					}
				}
			} else { 
				if ( 'site' == $transient['type'] ) { 
					$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_site_transient_timeout_' . $transient_name . "' LIMIT 1";
					$wpdb->query( $sql );
					pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (no value found)' );
				} else { 
					$sql = "DELETE FROM `" . $wpdb->options . "` WHERE option_name='" . '_transient_timeout_' . $transient_name . "' LIMIT 1";
					$wpdb->query( $sql );
					pb_backupbuddy::status( 'details', 'SQL: `' . $sql . '`. Rows affected: `' . $wpdb->rows_affected . '`. (no value found)' );
				}
			}
		}
		pb_backupbuddy::status( 'details', 'Completed transient cleanup.' );
	}
public static function cleanup_transients ( $ remove_unexpiring = false ) { pb_backupbuddy :: status ( 'details' , 'Cleaning up expired or corrupt transients.' ) ; if ( true === $ remove_unexpiring ) { pb_backupbuddy :: status ( 'details' , 'Option selected to purge unexpiring transients.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Option NOT selected to purge unexpiring transients.' ) ; } global $ wpdb ; $ sql = " SELECT `option_name` AS `name`, `option_value` AS `value`
			  FROM  ` " . $ wpdb -> options . " `
			  WHERE `option_name` LIKE '%transient_%'
			  ORDER BY `option_name` LIMIT 1000 " ; $ results = $ wpdb -> get_results ( $ sql ) ; $ transients = array ( ) ; foreach ( $ results as $ result ) { if ( 0 === strpos ( $ result -> name , '_site_transient_' ) ) { if ( 0 === strpos ( $ result -> name , '_site_transient_timeout_' ) ) { $ transients [ str_replace ( '_site_transient_timeout_' , '' , $ result -> name ) ] [ 'expires' ] = $ result -> value ; $ transients [ str_replace ( '_site_transient_timeout_' , '' , $ result -> name ) ] [ 'type' ] = 'site' ; } else { $ transients [ str_replace ( '_site_transient_' , '' , $ result -> name ) ] [ 'found' ] = true ; $ transients [ str_replace ( '_site_transient_' , '' , $ result -> name ) ] [ 'type' ] = 'site' ; } } else { if ( 0 === strpos ( $ result -> name , '_transient_timeout_' ) ) { $ transients [ str_replace ( '_transient_timeout_' , '' , $ result -> name ) ] [ 'expires' ] = $ result -> value ; $ transients [ str_replace ( '_transient_timeout_' , '' , $ result -> name ) ] [ 'type' ] = 'normal' ; } else { $ transients [ str_replace ( '_transient_' , '' , $ result -> name ) ] [ 'found' ] = true ; $ transients [ str_replace ( '_transient_' , '' , $ result -> name ) ] [ 'type' ] = 'normal' ; } } } pb_backupbuddy :: status ( 'details' , 'Found `' . count ( $ transients ) . '` transients.' ) ; foreach ( $ transients as $ transient_name => $ transient ) { if ( isset ( $ transient [ 'found' ] ) && ( true === $ transient [ 'found' ] ) ) { if ( ! isset ( $ transient [ 'expires' ] ) ) { if ( true === $ remove_unexpiring ) { if ( 'site' == $ transient [ 'type' ] ) { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_site_transient_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; no expire)' ) ; } else { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_transient_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; no expire)' ) ; } } } else { if ( $ transient [ 'expires' ] > time ( ) ) { if ( 'site' == $ transient [ 'type' ] ) { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_site_transient_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; expires; PAST expiration)' ) ; $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_site_transient_timeout_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; expires; PAST expiration)' ) ; } else { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_transient_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; expires; PAST expiration)' ) ; $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_transient_timeout_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (value found; expires; PAST expiration)' ) ; } } } } else { if ( 'site' == $ transient [ 'type' ] ) { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_site_transient_timeout_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (no value found)' ) ; } else { $ sql = " DELETE FROM ` " . $ wpdb -> options . " ` WHERE option_name=' " . '_transient_timeout_' . $ transient_name . " ' LIMIT 1 " ; $ wpdb -> query ( $ sql ) ; pb_backupbuddy :: status ( 'details' , 'SQL: `' . $ sql . '`. Rows affected: `' . $ wpdb -> rows_affected . '`. (no value found)' ) ; } } } pb_backupbuddy :: status ( 'details' , 'Completed transient cleanup.' ) ; }
cleanup_transients()
 Cleans up expired or corrupted transients.
cleanup_transients () Cleans up expired or corrupted transients .
// Currently capping at 1000 per cleanup to prevent using too much memory. // Check if we found a value. // Value was found. // Check if we found a paired expiration time. (NORMALLY we should find this. if not then something is wrong!). // Either never expires or glitched missing expiration date. // Only remove if specified. It's valid for a transient to be set to never expire so this should not be used regularly. // Delete transient. NOTE: No expiration entry exists so only need to remove value row here. // site // normal // Expiration found. See if it already expired. If so, delete it to clean up options table. // Transient expired. Remove from WP to clean up table. // Delete transient. !!!!!! IMPORTANT: Expiration exists so we MUST delete both value row AND expiration row !!!!!! // site // normal // No value found but expiration was. Should never happen. Delete expiration entry. // Delete transient. NOTE: No value entry exists so only need to remove expiration row here. // site // normal