public/wordpress/wp-content/plugins/backupbuddy/destinations/live/live_periodic.php
/* _step_process_file_deletions()
	 *
	 * Handles cleanup of any locally deletes files that need removed from the Live servers.
	 *
	 */
_step_process_file_deletions()
Handles cleanup of any locally deletes files that need removed from the Live servers.
_step_process_file_deletions () Handles cleanup of any locally deletes files that need removed from the Live servers .
private static function _step_process_file_deletions( $startAt = 0 ) {
		if ( $startAt < 0 ) {
			$startAt = 0;
		}
		$start_time = microtime( true );
		if ( false === self::_load_catalog() ) {
			return false;
		}
		$destination_settings = self::get_destination_settings();
		pb_backupbuddy::status( 'details', 'Starting deletions at point: `' . $startAt . '`.' );
		$loopCount = 0;
		$checkCount = 0;
		$filesDeleted = 0;
		$deleteQueue = array(); 
		$last_save = microtime( true );
		foreach( self::$_catalog as $signatureFile => &$signatureDetails ) {
			if ( 0 != $startAt ) { 
				if ( $loopCount < $startAt ) {
					$loopCount++;
					continue;
				}
			} else {
				$loopCount++;
			}
			$checkCount++;
			if ( isset( $signatureDetails['d'] ) && ( false === $signatureDetails['d'] ) ) {
				unset( $signatureDetails['d'] );
			}
			if ( !isset( $signatureDetails['d'] ) || ( true !== $signatureDetails['d'] ) ) {
				continue;
			}
			$sendFileoptions = glob( backupbuddy_core::getLogDirectory() . 'fileoptions/send-live_' . md5( $signatureFile ) . '-*.txt' );
			if ( ! is_array( $sendFileoptions ) ) {
				$sendFileoptions  = array();
			}
			foreach( $sendFileoptions as $sendFileoption ) {
				$fileoptions_obj = new pb_backupbuddy_fileoptions( $sendFileoption, $read_only = false, $ignore_lock = true, $create_file = false );
				if ( true !== ( $result = $fileoptions_obj->is_ok() ) ) {
					pb_backupbuddy::status( 'error', __('Error #9034.32393. Unable to access fileoptions data related to file `' . $signatureFile  . '`. Skipping cleanup of file send.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
					continue;
				}
				if ( ! isset( $fileoptions_obj->options['status'] ) ) {
					continue;
				}
				if ( ( 'success' == $fileoptions_obj->options['status'] ) || ( 'failure' == $fileoptions_obj->options['status'] ) || ( -1 == $fileoptions_obj->options['finish_time'] ) ) {
					continue;
				}
				$fileoptions_obj->options['finish_time'] = -1;
				$fileoptions_obj->save();
				pb_backupbuddy::status( 'details', 'Cancelled in-progress send of deleted file `' . $signatureFile . '`.' );
				unset( $fileoptions_obj );
			}
			if ( 0 != $signatureDetails['b'] ) {
				$deleteQueue[] = $signatureFile;
			} else { 
				self::$_state['stats']['files_pending_delete'] = ( self::$_state['stats']['files_pending_delete'] - 1 );
				if ( self::$_state['stats']['files_pending_delete'] < 0 ) {
					self::$_state['stats']['files_pending_delete'] = 0;
				}
				self::$_state['stats']['files_pending_delete'] = ( self::$_state['stats']['files_pending_send'] - 1 );
				if ( self::$_state['stats']['files_pending_send'] < 0 ) {
					self::$_state['stats']['files_pending_send'] = 0;
				}
				unset( self::$_catalog[ $signatureFile ] );
			}
			if ( count( $deleteQueue ) >= $destination_settings['max_delete_burst'] ) {
				pb_backupbuddy::status( 'details', 'File deletion queue full to burst limit. Triggering deletions call.' );
				self::_process_internal_delete_queue( $destination_settings, $deleteQueue, $filesDeleted ); 
			}
			if ( ( time() - $last_save ) > self::SAVE_SIGNATURES_EVERY_X_SECONDS ) {
				pb_backupbuddy::status( 'details', 'Time to save progress so far. Triggering deletions call then saving.' );
				self::_process_internal_delete_queue( $destination_settings, $deleteQueue, $filesDeleted ); 
				self::$_stateObj->save();
				self::$_catalogObj->save();
				$last_save = microtime( true );
			}
						if ( ( microtime( true ) - $start_time + self::TIME_WIGGLE_ROOM ) > $destination_settings['_max_time'] ) { 
				pb_backupbuddy::status( 'details', 'Running out of time processing deletions. Took `' . ( microtime( true ) - $start_time ) . '` seconds. Triggering deletions call then saving.' );
				//self::_process_internal_delete_queue( $destination_settings, $deleteQueue, $filesDeleted ); 
				self::$_stateObj->save();
				self::$_catalogObj->save();
				return array( 'Processing deletions', array() ); 
			}
		} 
		pb_backupbuddy::status( 'details', 'Processing any lingering deletions in queue (' . count( $deleteQueue ) . ') at finish then saving.' );
		self::_process_internal_delete_queue( $destination_settings, $deleteQueue, $filesDeleted ); 
		self::$_stateObj->save();
		self::$_catalogObj->save();
		pb_backupbuddy::status( 'details', 'Deletions processed. Checked `' . $checkCount . '` files. Deleted `' . $filesDeleted . '` files. Took `' . ( microtime( true ) - $start_time ) . '` seconds.' );
		return true;
	}
private static function _step_process_file_deletions ( $ startAt = 0 ) { if ( $ startAt < 0 ) { $ startAt = 0 ; } $ start_time = microtime ( true ) ; if ( false === self :: _load_catalog ( ) ) { return false ; } $ destination_settings = self :: get_destination_settings ( ) ; pb_backupbuddy :: status ( 'details' , 'Starting deletions at point: `' . $ startAt . '`.' ) ; $ loopCount = 0 ; $ checkCount = 0 ; $ filesDeleted = 0 ; $ deleteQueue = array ( ) ; $ last_save = microtime ( true ) ; foreach ( self :: $ _catalog as $ signatureFile => & $ signatureDetails ) { if ( 0 != $ startAt ) { if ( $ loopCount < $ startAt ) { $ loopCount ++ ; continue ; } } else { $ loopCount ++ ; } $ checkCount ++ ; if ( isset ( $ signatureDetails [ 'd' ] ) && ( false === $ signatureDetails [ 'd' ] ) ) { unset ( $ signatureDetails [ 'd' ] ) ; } if ( ! isset ( $ signatureDetails [ 'd' ] ) || ( true !== $ signatureDetails [ 'd' ] ) ) { continue ; } $ sendFileoptions = glob ( backupbuddy_core :: getLogDirectory ( ) . 'fileoptions/send-live_' . md5 ( $ signatureFile ) . '-*.txt' ) ; if ( ! is_array ( $ sendFileoptions ) ) { $ sendFileoptions = array ( ) ; } foreach ( $ sendFileoptions as $ sendFileoption ) { $ fileoptions_obj = new pb_backupbuddy_fileoptions ( $ sendFileoption , $ read_only = false , $ ignore_lock = true , $ create_file = false ) ; if ( true !== ( $ result = $ fileoptions_obj -> is_ok ( ) ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Error #9034.32393. Unable to access fileoptions data related to file `' . $ signatureFile . '`. Skipping cleanup of file send.' , 'it-l10n-backupbuddy' ) . ' Error: ' . $ result ) ; continue ; } if ( ! isset ( $ fileoptions_obj -> options [ 'status' ] ) ) { continue ; } if ( ( 'success' == $ fileoptions_obj -> options [ 'status' ] ) || ( 'failure' == $ fileoptions_obj -> options [ 'status' ] ) || ( - 1 == $ fileoptions_obj -> options [ 'finish_time' ] ) ) { continue ; } $ fileoptions_obj -> options [ 'finish_time' ] = - 1 ; $ fileoptions_obj -> save ( ) ; pb_backupbuddy :: status ( 'details' , 'Cancelled in-progress send of deleted file `' . $ signatureFile . '`.' ) ; unset ( $ fileoptions_obj ) ; } if ( 0 != $ signatureDetails [ 'b' ] ) { $ deleteQueue [ ] = $ signatureFile ; } else { self :: $ _state [ 'stats' ] [ 'files_pending_delete' ] = ( self :: $ _state [ 'stats' ] [ 'files_pending_delete' ] - 1 ) ; if ( self :: $ _state [ 'stats' ] [ 'files_pending_delete' ] < 0 ) { self :: $ _state [ 'stats' ] [ 'files_pending_delete' ] = 0 ; } self :: $ _state [ 'stats' ] [ 'files_pending_delete' ] = ( self :: $ _state [ 'stats' ] [ 'files_pending_send' ] - 1 ) ; if ( self :: $ _state [ 'stats' ] [ 'files_pending_send' ] < 0 ) { self :: $ _state [ 'stats' ] [ 'files_pending_send' ] = 0 ; } unset ( self :: $ _catalog [ $ signatureFile ] ) ; } if ( count ( $ deleteQueue ) >= $ destination_settings [ 'max_delete_burst' ] ) { pb_backupbuddy :: status ( 'details' , 'File deletion queue full to burst limit. Triggering deletions call.' ) ; self :: _process_internal_delete_queue ( $ destination_settings , $ deleteQueue , $ filesDeleted ) ; } if ( ( time ( ) - $ last_save ) > self :: SAVE_SIGNATURES_EVERY_X_SECONDS ) { pb_backupbuddy :: status ( 'details' , 'Time to save progress so far. Triggering deletions call then saving.' ) ; self :: _process_internal_delete_queue ( $ destination_settings , $ deleteQueue , $ filesDeleted ) ; self :: $ _stateObj -> save ( ) ; self :: $ _catalogObj -> save ( ) ; $ last_save = microtime ( true ) ; } if ( ( microtime ( true ) - $ start_time + self :: TIME_WIGGLE_ROOM ) > $ destination_settings [ '_max_time' ] ) { pb_backupbuddy :: status ( 'details' , 'Running out of time processing deletions. Took `' . ( microtime ( true ) - $ start_time ) . '` seconds. Triggering deletions call then saving.' ) ; self :: $ _stateObj -> save ( ) ; self :: $ _catalogObj -> save ( ) ; return array ( 'Processing deletions' , array ( ) ) ; } } pb_backupbuddy :: status ( 'details' , 'Processing any lingering deletions in queue (' . count ( $ deleteQueue ) . ') at finish then saving.' ) ; self :: _process_internal_delete_queue ( $ destination_settings , $ deleteQueue , $ filesDeleted ) ; self :: $ _stateObj -> save ( ) ; self :: $ _catalogObj -> save ( ) ; pb_backupbuddy :: status ( 'details' , 'Deletions processed. Checked `' . $ checkCount . '` files. Deleted `' . $ filesDeleted . '` files. Took `' . ( microtime ( true ) - $ start_time ) . '` seconds.' ) ; return true ; }
_step_process_file_deletions()
 Handles cleanup of any locally deletes files that need removed from the Live servers.
_step_process_file_deletions () Handles cleanup of any locally deletes files that need removed from the Live servers .
// Build Stash2/Stash3 destination settings based on Live settings. // Loop through files in the catalog. // Files queued to delete. // Resuming... // NOTE: BB v8 cleanup removes default false to conserve memory. TODO: Remove at BB v9. // Skip non-deleted files. // Made it here then we will be deleting a file. // Cancel any in-process remote sends of deleted files. // Something wrong with fileoptions. Let cleanup handle it later. // Don't do anything for success, failure, or already-marked as -1 finish time. // Cancel this send. // If file has been backed up to server then we need to QUEUE the file for deletion. // Remove item from queue immediately since not sent. // Is the queue full to the delete burst limit? Process queue. // Process any items in the deletion queue. $deleteQueue and $filesDeleted are references. // See if it's time to save our progress so far. // Process any items in the deletion queue. $deleteQueue and $filesDeleted are references. // Do we have enough time to continue or do we need to chunk?
 // Running out of time! Chunk. //self::_process_internal_delete_queue( $destination_settings, $deleteQueue, $filesDeleted ); // Process any items in the deletion queue. $deleteQueue and $filesDeleted are references. // Do not process queue here. Anything in the queuecan be handled during the next chunk. //array( $startAt+$loopCount-$filesDeleted ) ); // end foreach. // Wrap up any lingering deletions. // Process any items in the deletion queue. $deleteQueue and $filesDeleted are references. // Save and finish.