' => $refreshToken])); if (!$token->refresh(true)) { throw new Exception(__('Failed to fetch information from Google Drive. Make sure the token is valid.', 'duplicator-pro')); } if (empty($token->getScope())) { throw new Exception(__("Couldn't connect. Google Drive scopes not found.", 'duplicator-pro')); } if (! $token->hasScopes(static::REQUIRED_SCOPES)) { throw new Exception( __( "Authorization failed. You did not allow all required permissions. Try again and make sure that you checked all checkboxes.", 'duplicator-pro' ) ); } $this->config['refresh_token'] = $token->getRefreshToken(); $this->config['token_json'] = wp_json_encode([ 'created' => $token->getCreated(), 'access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken(), 'expires_in' => $token->getExpiresIn(), 'scope' => $token->getScope(), ]); $this->config['client_number'] = self::GDRIVE_CLIENT_LATEST; $this->config['authorized'] = $token->isValid(); } catch (Exception $e) { DUP_PRO_Log::traceException($e, "Problem authorizing Google Drive access token"); DUP_PRO_Log::traceObject('Token pair string from authorization:', $tokenPairString); $message = $e->getMessage(); return false; } $this->save(); $message = __('Google Drive is connected successfully and Storage Provider Updated.', 'duplicator-pro'); return true; } /** * Revokes authorization * * @param string $message Message * * @return bool True if authorized, false if failed */ public function revokeAuthorization(&$message = '') { if (!$this->isAuthorized()) { $message = __('Google Drive isn\'t authorized.', 'duplicator-pro'); return true; } try { $client = $this->getAdapter()->getService()->getClient(); if (!empty($this->config['refresh_token'])) { $client->revokeToken($this->config['refresh_token']); } $accessTokenObj = json_decode($this->config['token_json']); if (is_object($accessTokenObj) && property_exists($accessTokenObj, 'access_token')) { $gdrive_access_token = $accessTokenObj->access_token; } else { $gdrive_access_token = false; } if (!empty($gdrive_access_token)) { $client->revokeToken($gdrive_access_token); } } catch (Exception $e) { DUP_PRO_Log::trace("Problem revoking Google Drive access token msg: " . $e->getMessage()); $message = $e->getMessage(); return false; } finally { $this->config['token_json'] = ''; $this->config['refresh_token'] = ''; $this->config['client_number'] = -1; $this->config['authorized'] = false; } $message = __('Google Drive is disconnected successfully.', 'duplicator-pro'); return true; } /** * Get authorization URL * * @return string */ public function getAuthorizationUrl() { return (new TokenService(static::getSType()))->getRedirectUri(); } /** * Get storage adapter * * @return GDriveAdapter */ public function getAdapter() { $global = DUP_PRO_Global_Entity::getInstance(); $token = $this->getTokenFromConfig(); if (! $this->adapter) { $storageFolderId = ''; if (! empty($this->config['storage_folder_id'])) { $storageFolderId = $this->config['storage_folder_id']; } $this->adapter = new GDriveAdapter( $token, $this->config['storage_folder'], $storageFolderId, !$global->ssl_disableverify, ($global->ssl_useservercerts ? '' : DUPLICATOR_PRO_CERT_PATH), $global->ipv4_only ); $this->adapter->initialize(); if ($token->isValid() && empty($this->config['storage_folder_id'])) { $storageFolder = $this->adapter->getPathInfo('/'); $this->config['storage_folder_id'] = $storageFolder->id; $this->config['storage_folder_web_url'] = $storageFolder->webUrl; $this->save(); } } if (! $token->isValid()) { return $this->adapter; } // This check is only needed if we have a valid storage. $storageFolder = $this->adapter->getPathInfo('/'); if ($storageFolder->name !== basename($this->getStorageFolder())) { // root folder id & storage folder name is different. $this->adapter = new GDriveAdapter( $token, $this->config['storage_folder'], '', !$global->ssl_disableverify, ($global->ssl_useservercerts ? '' : DUPLICATOR_PRO_CERT_PATH), $global->ipv4_only ); $this->adapter->initialize(); $storageFolder = $this->adapter->getPathInfo('/'); $this->config['storage_folder_id'] = $storageFolder->id; $this->config['storage_folder_web_url'] = $storageFolder->webUrl; $this->save(); } return $this->adapter; } /** * Returns the config fields template data * * @return array */ protected function getConfigFieldsData() { $userInfo = false; $quotaString = ''; $adapter = $this->getAdapter(); if ($this->isAuthorized() && $adapter->isValid()) { try { $serviceDrive = $adapter->getService(); $optParams = array('fields' => '*'); $about = $serviceDrive->about->get($optParams); $storageQuota = $about->getStorageQuota(); $quota_total = max($storageQuota->getLimit(), 1); $quota_used = $storageQuota->getUsage(); $userInfo = $about->getUser(); if (is_numeric($quota_total) && is_numeric($quota_used)) { $available_quota = $quota_total - $quota_used; $used_perc = round($quota_used * 100 / $quota_total, 1); $quotaString = sprintf( __('%1$s%% used, %2$s available', 'duplicator-pro'), $used_perc, size_format($available_quota) ); } } catch (\Exception $e) { DUP_PRO_Log::info("Problem getting Google Drive user info and quota: " . $e->getMessage()); $userInfo = $quotaString = null; } } // Adapter is invalid, but we have a refresh token, so it has been revoked if (! $adapter->isValid() && ! empty($this->config['refresh_token'])) { $errorMessage = __('Google Drive has been disconnected. Please connect to Google Drive again.', 'duplicator-pro'); AdminNotices::displayGeneralAdminNotice($errorMessage, AdminNotices::GEN_ERROR_NOTICE); } return array_merge($this->getDefaultConfigFieldsData(), [ 'userInfo' => $userInfo, 'quotaString' => $quotaString, ]); } /** * Returns the default config fields template data * * @return array */ protected function getDefaultConfigFieldsData() { return [ 'storage' => $this, 'storageFolder' => $this->config['storage_folder'], 'maxPackages' => $this->config['max_packages'], 'userInfo' => null, 'quotaString' => null, ]; } /** * Returns the config fields template path * * @return string */ protected function getConfigFieldsTemplatePath() { return 'gdriveaddon/configs/google_drive'; } /** * Update data from http request, this method don't save data, just update object properties * * @param string $message Message * * @return bool True if success and all data is valid, false otherwise */ public function updateFromHttpRequest(&$message = '') { if ((parent::updateFromHttpRequest($message) === false)) { return false; } $previousStorageFolder = $this->config['storage_folder']; $this->config['max_packages'] = SnapUtil::sanitizeIntInput(SnapUtil::INPUT_REQUEST, 'gdrive_max_files', 10); $this->config['storage_folder'] = self::getSanitizedInputFolder('_gdrive_storage_folder', 'remove'); if ($previousStorageFolder !== $this->config['storage_folder']) { $this->config['storage_folder_id'] = ''; $this->config['storage_folder_web_url'] = ''; } $message = sprintf( __('Google Drive Storage Updated.', 'duplicator-pro'), $this->config['server'], $this->getStorageFolder() ); return true; } /** * Get the token entity from config * * @return TokenEntity */ protected function getTokenFromConfig() { $token = new TokenEntity(static::getSType(), $this->config['token_json']); if ($token->isValid() && $token->isAboutToExpire()) { try { if (! $token->refresh(true)) { $token->updateProperties(['access_token' => '']); // clear access token $this->config['authorized'] = false; $this->save(); return $token; } } catch (Exception $e) { DUP_PRO_Log::traceException($e, "Problem refreshing Google Drive access token"); } $this->config['token_json'] = wp_json_encode([ 'created' => $token->getCreated(), 'access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken(), 'expires_in' => $token->getExpiresIn(), 'scope' => $token->getScope(), ]); $this->save(); } return $token; } /** * @return void */ public static function registerType() { parent::registerType(); add_action('duplicator_update_global_storage_settings', function () { $dGlobal = DynamicGlobalEntity::getInstance(); foreach (static::getDefaultSettings() as $key => $default) { $value = SnapUtil::sanitizeIntInput(SnapUtil::INPUT_REQUEST, $key, $default); $dGlobal->setVal($key, $value); } }); } /** * Get default settings * * @return array */ protected static function getDefaultSettings() { return [ 'gdrive_upload_chunksize_in_kb' => 1024, 'gdrive_download_chunksize_in_kb' => 10 * 1024, 'gdrive_transfer_mode' => DUP_PRO_Google_Drive_Transfer_Mode::Auto, ]; } /** * @return void */ public static function renderGlobalOptions() { $dGlobal = DynamicGlobalEntity::getInstance(); TplMng::getInstance()->render( 'gdriveaddon/configs/global_options', [ 'uploadChunkSize' => $dGlobal->getVal('gdrive_upload_chunksize_in_kb', 1024), 'downloadChunkSize' => $dGlobal->getVal('gdrive_download_chunksize_in_kb', 10 * 1024), 'transferMode' => $dGlobal->getVal('gdrive_transfer_mode', DUP_PRO_Google_Drive_Transfer_Mode::Auto), ] ); } }
Fatal error: Uncaught Error: Class 'Duplicator\Addons\GDriveAddon\Models\GDriveStorage' not found in /var/www/html/cineorna.com/web/wp-content/plugins/duplicator-pro/addons/gdriveaddon/GDriveAddon.php:50 Stack trace: #0 /var/www/html/cineorna.com/web/wp-includes/class-wp-hook.php(324): Duplicator\Addons\GDriveAddon\GDriveAddon->registerStorages('') #1 /var/www/html/cineorna.com/web/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #2 /var/www/html/cineorna.com/web/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /var/www/html/cineorna.com/web/wp-content/plugins/duplicator-pro/src/Models/Storages/StoragesUtil.php(249): do_action('duplicator_pro_...') #4 /var/www/html/cineorna.com/web/wp-content/plugins/duplicator-pro/src/Core/Bootstrap.php(84): Duplicator\Models\Storages\StoragesUtil::registerTypes() #5 /var/www/html/cineorna.com/web/wp-content/plugins/duplicator-pro/duplicator-pro-main.php(32): Duplicator\Core\Bootstrap::init('7b2272223a5b225...') #6 /var/www/html/cineorna.com/web/wp-content in /var/www/html/cineorna.com/web/wp-content/plugins/duplicator-pro/addons/gdriveaddon/GDriveAddon.php on line 50