function dropbox_backup($historyID = 0, $args = '', $uploadid = null, $offset = 0) { //included two arguments $uploadid and $offset $dBoxStartTime = $this->iwpScriptStartTime; //get the settings //$this -> backup_settings_vals = get_option('iwp_client_multi_backup_temp_values'); //$backup_settings_values = $this -> backup_settings_vals; //$upload_file_block_size = $backup_settings_values['upload_file_block_size']; //$actual_file_size = $backup_settings_values['actual_file_size']; //$del_host_file = $backup_settings_values['del_host_file']; //get the settings other method $requestParams = $this->getRequiredData($historyID, "requestParams"); $upload_loop_break_time = $requestParams['account_info']['upload_loop_break_time']; //darkcode changed $upload_file_block_size = $requestParams['account_info']['upload_file_block_size']; $del_host_file = $requestParams['args']['del_host_file']; $current_file_num = 0; if ($args == '') { //on the next call $args would be '' //set $args, $uploadid, $offset from the DB $responseParams = $this->getRequiredData($historyID, "responseParams"); if (!$responseParams) { $this->statusLog($historyID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'errorGettingDBValues', 'statusCode' => 'error_getting_db_values')); } $args = $responseParams['dropboxArgs']; $prevChunkResults = $responseParams['response_data']; $uploadid = $prevChunkResults['upload_id']; $offset = $prevChunkResults['offset']; $current_file_num = $responseParams['current_file_num']; } $tempArgs = $args; extract($args); $task_result = $this->getRequiredData($historyID, "taskResults"); $task_result['task_results'][$historyID]['dropbox'] = $this->get_files_base_name($backup_file); $task_result['dropbox'] = $this->get_files_base_name($backup_file); if (!is_array($backup_file)) { $temp_backup_file = $backup_file; $backup_file = array(); $backup_file[] = $temp_backup_file; } if (is_array($backup_file)) { $backup_files_count = count($backup_file); $backup_file = $backup_file[$current_file_num]; } $actual_file_size = iwp_mmb_get_file_size($backup_file); $backup_file_size = $actual_file_size; //$backup_file_size = 10394909; //darkCode testing purpose if (!$this->iwp_mmb_function_exists('curl_init')) { return array('error' => 'You cannot use Dropbox on your server. Please enable curl first.', 'partial' => 1, 'error_code' => 'cannot_use_dropbox_enable_curl_first'); } if (isset($consumer_secret) && !empty($consumer_secret)) { require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/dropbox.php'; $dropbox = new IWP_Dropbox($consumer_key, $consumer_secret); $dropbox->setOAuthTokens($oauth_token, $oauth_token_secret); if (isset($dropbox_site_folder) && $dropbox_site_folder == true) { $dropbox_destination .= '/' . $this->site_name . '/' . basename($backup_file); } else { $dropbox_destination .= '/' . basename($backup_file); } try { //$dropbox->upload($backup_file, $dropbox_destination, true); //we are using new multiCAll function // this is the dropbox loop .. $reloop = false; $chunkCount = 0; $chunkTimeTaken = 0; do { if ($chunkCount == 0) { $chunkStartTime = $dBoxStartTime; } else { $chunkStartTime = microtime(true); } if ($backup_file_size - $offset >= $upload_file_block_size) { $readsize = $upload_file_block_size; $isCommit = false; $status = 'partiallyCompleted'; } else { $readsize = $backup_file_size - $offset; $isCommit = true; $status = 'completed'; } $chunkResult = $dropbox->chunked_upload($backup_file, $dropbox_destination, true, $uploadid, $offset, $readsize, $isCommit); $result_arr = array(); $result_arr['response_data'] = $chunkResult; $result_arr['status'] = $status; $result_arr['nextFunc'] = 'dropbox_backup'; $result_arr['dropboxArgs'] = $tempArgs; $result_arr['current_file_num'] = $current_file_num; //updating offset and uploadid values for relooping. $offset = isset($chunkResult['offset']) ? $chunkResult['offset'] : 0; $uploadid = isset($chunkResult['upload_id']) ? $chunkResult['upload_id'] : 0; echo 'completed-size' . $offset / 1024 / 1024; //check time $chunkCompleteTime = microtime(true); $dBoxCompleteTime = microtime(true); $chunkTimeTaken = ($chunkTimeTaken + ($chunkCompleteTime - $chunkStartTime)) / ($chunkCount + 1); // this is the average chunk time echo " thisChunkTimeTaken" . $chunkTimeTaken; $dBoxTimeTaken = $dBoxCompleteTime - $dBoxStartTime; $dBoxTimeLeft = $upload_loop_break_time - $dBoxTimeTaken; //calculating time left for the dBOX upload .. $dBoxTimeLeft = $dBoxTimeLeft - 5; //for safe time limit echo " dBoxTimeLeft" . $dBoxTimeLeft; //$halfOfLoopTime = (($upload_loop_break_time / 2) - 1); if ($dBoxTimeLeft <= $chunkTimeTaken || $status == 'completed') { $reloop = false; } else { $reloop = true; $chunkCount++; } } while ($reloop); $resArray = array('status' => $status, 'backupParentHID' => $historyID); if ($status == 'completed') { $current_file_num += 1; if ($current_file_num == $backup_files_count) { $result_arr['nextFunc'] = 'dropbox_backup_over'; iwp_mmb_print_flush('Dropbox upload: End'); unset($task_result['task_results'][$historyID]['server']); } else { $result_arr['nextFunc'] = 'dropbox_backup'; $result_arr['current_file_num'] = $current_file_num; $result_arr['status'] = 'partiallyCompleted'; $resArray['status'] = 'partiallyCompleted'; } } $this->statusLog($historyID, array('stage' => 'dropboxMultiCall', 'status' => 'completed', 'statusMsg' => 'nextCall', 'nextFunc' => 'dropbox_backup', 'task_result' => $task_result, 'responseParams' => $result_arr)); if ($status == 'completed') { //checking file size and comparing $verificationResult = $this->postUploadVerification($dropbox, $backup_file, $dropbox_destination, $type = "dropbox"); if (!$verificationResult) { return $this->statusLog($historyID, array('stage' => 'uploadDropBox', 'status' => 'error', 'statusMsg' => 'Dropbox verification failed: File may be corrupted.', 'statusCode' => 'dropbox_verification_failed_file_may_be_corrupted')); } if ($del_host_file) { @unlink($backup_file); } } return $resArray; } catch (Exception $e) { $this->_log($e->getMessage()); return array('error' => $e->getMessage(), 'partial' => 1); } //return true; } else { return array('error' => 'Please connect your InfiniteWP panel with your Dropbox account.', 'error_code' => 'please_connect_your_iwp_panel_with_your_dropbox_account'); } }