public static function backupProcessor($siteIDs, $params) { $accountInfo = array('account_info' => $params['accountInfo']); if (!empty($accountInfo['account_info']['iwp_gdrive'])) { //$accountInfo['account_info']['iwp_gdrive']['gDriveEmail'] = unserialize(getOption('googleDriveAccessToken')); $repoID = $accountInfo['account_info']['iwp_gdrive']['gDriveEmail']; if (function_exists('backupRepositorySetGoogleDriveArgs')) { $accountInfo['account_info']['iwp_gdrive'] = backupRepositorySetGoogleDriveArgs($accountInfo['account_info']['iwp_gdrive']); } else { addNotification($type = 'E', $title = 'Cloud backup Addon Missing', $message = "Check if cloud backup addon exists and is active", $state = 'U', $callbackOnClose = '', $callbackReference = ''); return false; } } $config = $params['config']; $timeout = 20 * 60; //20 mins $type = "backup"; $action = $config['mechanism'] == 'multiCall' ? "multiCallNow" : "now"; $requestAction = "scheduled_backup"; if (empty($config['taskName'])) { $config['taskName'] = 'Backup Now'; } $exclude = explode(',', $config['exclude']); $include = explode(',', $config['include']); array_walk($exclude, 'trimValue'); array_walk($include, 'trimValue'); $requestParams = array('task_name' => $config['taskName'], 'mechanism' => $config['mechanism'], 'args' => array('type' => $type, 'action' => $action, 'what' => $config['what'], 'optimize_tables' => $config['optimizeDB'], 'exclude' => $exclude, 'exclude_file_size' => (int) $config['excludeFileSize'], 'exclude_extensions' => $config['excludeExtensions'], 'include' => $include, 'del_host_file' => $config['delHostFile'], 'disable_comp' => $config['disableCompression'], 'fail_safe_db' => $config['failSafeDB'], 'fail_safe_files' => $config['failSafeFiles'], 'limit' => $config['limit'], 'backup_name' => $config['backupName']), 'secure' => $accountInfo); if ($action == "multiCallNow") { //this function set the multicall options value from config.php if available setMultiCallOptions($requestParams); } $historyAdditionalData = array(); $historyAdditionalData[] = array('uniqueName' => $config['taskName'], 'detailedAction' => $type); $incTime = 20 * 60; //20 mins $i = 0; $lastHistoryID = ''; if (empty($params['timeScheduled'])) { $params['timeScheduled'] = time(); } foreach ($siteIDs as $siteID) { $siteData = getSiteData($siteID); $events = 1; $PRP = array(); $PRP['requestAction'] = $requestAction; $PRP['requestParams'] = $requestParams; $PRP['siteData'] = $siteData; $PRP['type'] = $type; $PRP['action'] = $action; $PRP['events'] = $events; $PRP['historyAdditionalData'] = $historyAdditionalData; $PRP['timeout'] = $timeout; $PRP['status'] = 'pending'; $PRP['timeScheduled'] = $params['timeScheduled']; if ($lastHistoryID) { $runCondition = array(); $runCondition['satisfyType'] = 'OR'; $runCondition['query'] = array('table' => "history_additional_data", 'select' => 'historyID', 'where' => "historyID = " . $lastHistoryID . " AND status IN('success', 'error', 'netError')"); //$runCondition['maxWaitTime'] = $params['timeScheduled'] + $incTime * $i; $PRP['runCondition'] = serialize($runCondition); $PRP['status'] = 'scheduled'; } $lastHistoryID = prepareRequestAndAddHistory($PRP); $i++; } }
function repositoryGDrive($args) { if (!empty($args['gDriveEmail'])) { //return googleDriveHelper::testConnectionGoogle($args); include_once APP_ROOT . '/lib/googleAPIs/src/Google_Client.php'; include_once APP_ROOT . '/lib/googleAPIs/src/contrib/Google_DriveService.php'; include_once APP_ROOT . '/lib/googleAPIs/src/contrib/Google_Oauth2Service.php'; include_once APP_ROOT . '/lib/googleAPIs/storage.php'; include_once APP_ROOT . '/lib/googleAPIs/authHelper.php'; if (function_exists('backupRepositorySetGoogleDriveArgs')) { $gDriveArgs = backupRepositorySetGoogleDriveArgs($args); } else { addNotification($type = 'E', $title = 'Cloud backup Addon Missing', $message = "Check if cloud backup addon exists and is active", $state = 'U', $callbackOnClose = '', $callbackReference = ''); return array('status' => 'error', 'errorMsg' => 'Cloud backup addon missing'); } if (!empty($gDriveArgs) && !empty($gDriveArgs['clientID']) && !empty($gDriveArgs['clientSecretKey'])) { $accessToken = $gDriveArgs['token']; $client = new Google_Client(); $client->setClientId($gDriveArgs['clientID']); $client->setClientSecret($gDriveArgs['clientSecretKey']); $client->setRedirectUri($gDriveArgs['redirectURL']); $client->setScopes(array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email')); $accessToken = $gDriveArgs['token']; $refreshToken = $accessToken['refresh_token']; try { $client->refreshToken($refreshToken); return array('status' => 'success'); } catch (Exception $e) { echo 'google Error ', $e->getMessage(), "\n"; return array('status' => 'error', 'errorMsg' => $e->getMessage()); } } return array('status' => 'error', 'errorMsg' => 'API key not available.'); } return array('status' => 'error', 'errorMsg' => 'Repository ID not available.'); }