public/wordpress/wp-content/plugins/backupbuddy/classes/remote_api.php
/* _verb_runBackup()
	 *
	 * Run a backup with a specified custom profile; eg a db backup for pulling deployment.
	 * Params: POST "profile" - Base64 encoded json encoded profile array.
	 *
	 */
_verb_runBackup()
Run a backup with a specified custom profile; eg a db backup for pulling deployment.
Params: POST "profile" - Base64 encoded json encoded profile array.
_verb_runBackup () Run a backup with a specified custom profile ; eg a db backup for pulling deployment . Params : POST " profile " - Base64 encoded json encoded profile array .
private static function _verb_runBackup() {
		$backupSerial = pb_backupbuddy::random_string( 10 );
		$profileArray = self::$_incomingPayload[ 'profile' ];
		if ( false === ( $profileArray = base64_decode( $profileArray ) ) ) {
			$message = 'Error #8343728: Unable to base64 decode profile data.';
			pb_backupbuddy::status( 'error', $message, $backupSerial );
			self::_reply( array( 'success' => false, 'error' => $message ) );
		}
		if ( NULL === ( $profileArray = json_decode( $profileArray, true ) ) ) {
			$message = 'Error #3272383: Unable to json decode profile data.';
			pb_backupbuddy::status( 'error', $message, $backupSerial );
			self::_reply( array( 'success' => false, 'error' => $message ) ) ;
		}
		if ( isset( $profileArray['sessionTokens'] ) && ( is_array( $profileArray['sessionTokens'] ) ) ) {
			pb_backupbuddy::status( 'details', 'Remote session tokens need updated.', $backupSerial );
			if ( ! is_numeric( $profileArray['sessionID'] ) ) {
				$message = 'Error #328989893. Invalid session ID. Must be numeric.';
				pb_backupbuddy::status( 'error', $message );
				self::_reply( array( 'success' => false, 'error' => $message ) );
			}
			global $wpdb;
			$sql = "SELECT meta_value FROM `" . DB_NAME . "`.`" . $wpdb->prefix . "usermeta` WHERE `user_id` = '" . $profileArray['sessionID'] . "' AND `meta_key` = 'session_tokens';";
			$results = $wpdb->get_var( $sql );
			$oldSessionTokens = @unserialize( $results );
			if ( ! is_array( $oldSessionTokens ) ) {
				$oldSessionTokens = array();
			}
			$newSessionTokens = array_merge( $oldSessionTokens, $profileArray['sessionTokens'] );
			$newSessionTokens = serialize( $newSessionTokens );
			$sql = "UPDATE `" . DB_NAME . "`.`" . $wpdb->prefix . "usermeta` SET meta_value= %s WHERE `user_id` = '" . $profileArray['sessionID'] . "' AND `meta_key` = 'session_tokens';";
			$stringedSessionTokens = serialize( $profileArray['sessionTokens'] );
			if ( false === $wpdb->query( $wpdb->prepare( $sql, $stringedSessionTokens ) ) ) {
				$message = 'Error #43734784: Unable to update remote session token.';
				pb_backupbuddy::status( 'error', $message, $backupSerial );
				self::_reply( array( 'success' => false, 'error' => $message ) );
			}
			pb_backupbuddy::status( 'details', 'Updated remote session tokens.', $backupSerial );
		}
		if ( true !== ( $maybeMessage = backupbuddy_api::runBackup( $profileArray, $triggerTitle = 'deployment_pulling', $backupMode = '', $backupSerial ) ) ) {
			$message = 'Error #48394873: Unable to launch backup at source. Details: `' . $maybeMessage . '`.';
			pb_backupbuddy::status( 'error', $message, $backupSerial );
			self::_reply( array( 'success' => false, 'error' => $message ) );
		} else {
			$archiveFilename = basename( backupbuddy_core::calculateArchiveFilename( $backupSerial, $profileArray['type'], $profileArray ) );
			self::_reply( array( 'success' => true, 'backupSerial' => $backupSerial, 'backupFile' => $archiveFilename ) );
		}
	}
private static function _verb_runBackup ( ) { $ backupSerial = pb_backupbuddy :: random_string ( 10 ) ; $ profileArray = self :: $ _incomingPayload [ 'profile' ] ; if ( false === ( $ profileArray = base64_decode ( $ profileArray ) ) ) { $ message = 'Error #8343728: Unable to base64 decode profile data.' ; pb_backupbuddy :: status ( 'error' , $ message , $ backupSerial ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } if ( NULL === ( $ profileArray = json_decode ( $ profileArray , true ) ) ) { $ message = 'Error #3272383: Unable to json decode profile data.' ; pb_backupbuddy :: status ( 'error' , $ message , $ backupSerial ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } if ( isset ( $ profileArray [ 'sessionTokens' ] ) && ( is_array ( $ profileArray [ 'sessionTokens' ] ) ) ) { pb_backupbuddy :: status ( 'details' , 'Remote session tokens need updated.' , $ backupSerial ) ; if ( ! is_numeric ( $ profileArray [ 'sessionID' ] ) ) { $ message = 'Error #328989893. Invalid session ID. Must be numeric.' ; pb_backupbuddy :: status ( 'error' , $ message ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } global $ wpdb ; $ sql = " SELECT meta_value FROM ` " . DB_NAME . " `.` " . $ wpdb -> prefix . " usermeta` WHERE `user_id` = ' " . $ profileArray [ 'sessionID' ] . " ' AND `meta_key` = 'session_tokens'; " ; $ results = $ wpdb -> get_var ( $ sql ) ; $ oldSessionTokens = @ unserialize ( $ results ) ; if ( ! is_array ( $ oldSessionTokens ) ) { $ oldSessionTokens = array ( ) ; } $ newSessionTokens = array_merge ( $ oldSessionTokens , $ profileArray [ 'sessionTokens' ] ) ; $ newSessionTokens = serialize ( $ newSessionTokens ) ; $ sql = " UPDATE ` " . DB_NAME . " `.` " . $ wpdb -> prefix . " usermeta` SET meta_value= %s WHERE `user_id` = ' " . $ profileArray [ 'sessionID' ] . " ' AND `meta_key` = 'session_tokens'; " ; $ stringedSessionTokens = serialize ( $ profileArray [ 'sessionTokens' ] ) ; if ( false === $ wpdb -> query ( $ wpdb -> prepare ( $ sql , $ stringedSessionTokens ) ) ) { $ message = 'Error #43734784: Unable to update remote session token.' ; pb_backupbuddy :: status ( 'error' , $ message , $ backupSerial ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } pb_backupbuddy :: status ( 'details' , 'Updated remote session tokens.' , $ backupSerial ) ; } if ( true !== ( $ maybeMessage = backupbuddy_api :: runBackup ( $ profileArray , $ triggerTitle = 'deployment_pulling' , $ backupMode = '' , $ backupSerial ) ) ) { $ message = 'Error #48394873: Unable to launch backup at source. Details: `' . $ maybeMessage . '`.' ; pb_backupbuddy :: status ( 'error' , $ message , $ backupSerial ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } else { $ archiveFilename = basename ( backupbuddy_core :: calculateArchiveFilename ( $ backupSerial , $ profileArray [ 'type' ] , $ profileArray ) ) ; self :: _reply ( array ( 'success' => true , 'backupSerial' => $ backupSerial , 'backupFile' => $ archiveFilename ) ) ; } }
_verb_runBackup()
 Run a backup with a specified custom profile; eg a db backup for pulling deployment.
_verb_runBackup () Run a backup with a specified custom profile ; eg a db backup for pulling deployment .
// Appends session tokens from the pulling site so they wont get logged out when this database is restored there. //error_log( 'needtoken' ); // Get current session tokens. // Add remote tokens. // Re-serialize. // Save merged tokens here.