PATH:
home
/
thebhoeo
/
.trash
/
backwpup
/
inc
<?php declare(strict_types=1); use WPMedia\BackWPup\StorageProviders\Rackspace\RackspaceProvider as Rackspace; /** * RCS Downloader. * * @since 5.5 */ class BackWPup_Destination_RSC_Downloader implements BackWPup_Destination_Downloader_Interface { /** * Local handle. * * @var resource */ private $local_handle; /** * BackWpUp_Destination_Downloader_Data Instance, * * @var BackWpUp_Destination_Downloader_Data */ private BackWpUp_Destination_Downloader_Data $data; /** * Rackspace instance. * * @var Rackspace */ private Rackspace $rackspace; /** * BackWPup_Destination_RSC_Downloader constructor. * * @param BackWpUp_Destination_Downloader_Data $data Destination downloader instance. */ public function __construct( BackWpUp_Destination_Downloader_Data $data ) { $this->data = $data; $this->rackspace = $this->initialise(); } /** * Destruct, clean up stuff after download is complete. */ public function __destruct() { fclose( $this->local_handle ); // phpcs:ignore } /** * Download part of the backup file. * * @param int $start_byte * @param int $end_byte * * @throws Exception In case something went wrong. * @throws RuntimeException Throw runtime error if we can't write to file. */ public function download_chunk( $start_byte, $end_byte ) { $object_name = $this->data->source_file_path(); $container_name = $this->rackspace->get_container_name(); $url = "{$this->rackspace->get_public_url()}/{$container_name}/{$object_name}"; $args = [ 'timeout' => 300, 'headers' => [ 'X-Auth-Token' => $this->rackspace->get_token(), 'Range' => 'bytes=' . $start_byte . '-' . $end_byte, ], ]; try { $this->open_local_handle( $start_byte ); $response = wp_remote_get( $url, $args ); if ( is_wp_error( $response ) ) { throw new Exception( __( 'Chunk download failed: ', 'backwpup' ) . $response->get_error_message() ); } $response_code = wp_remote_retrieve_response_code( $response ); if ( 206 !== $response_code && 200 !== $response_code ) { throw new Exception( __( 'Chunk download failed with status: ', 'backwpup' ) . $response_code ); } $body = wp_remote_retrieve_body( $response ); $content_length = wp_remote_retrieve_header( $response, 'content-length' ); if ( empty( $body ) || '0' === $content_length ) { throw new Exception( __( 'Could not read chunk data. Empty response.', 'backwpup' ) ); } // Write to local file. $bytes = fwrite( $this->local_handle, $body ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite if ( 0 === $bytes || false === $bytes ) { throw new RuntimeException( __( 'Could not write data to file.', 'backwpup' ) ); } } catch ( Exception $e ) { throw new Exception( esc_html__( 'Download failed.', 'backwpup' ) ); } } /** * Handle the local writing of the download process. * * @param int $start_byte Start byte. * * @throws RuntimeException If file could not be opened. * @return void */ public function open_local_handle( int $start_byte ): void { if ( is_resource( $this->local_handle ) ) { return; } $mode = 0 === $start_byte ? 'wb' : 'ab'; $this->local_handle = fopen( $this->data->local_file_path(), $mode ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( ! is_resource( $this->local_handle ) ) { throw new RuntimeException( esc_html__( 'File could not be opened for writing.', 'backwpup' ) ); } } /** * Calculate the size of download. * * @return int * @throws Exception If getting the file size failed. */ public function calculate_size(): int { return $this->rackspace->get_file_size( $this->data->source_file_path() ); } /** * Initialise rackspace cloud * * @return Rackspace * @throws Exception Throw an error if request fails. */ private function initialise(): Rackspace { $storage_provider = new Rackspace( [ 'username' => BackWPup_Option::get( $this->data->job_id(), 'rscusername' ), 'api_key' => BackWPup_Encryption::decrypt( BackWPup_Option::get( $this->data->job_id(), 'rscapikey' ) ), 'container_name' => BackWPup_Option::get( $this->data->job_id(), 'rsccontainer' ), 'region' => BackWPup_Option::get( $this->data->job_id(), 'rscregion' ), ], ); $storage_provider->initialise(); return $storage_provider; } }
[-] class-system-tests-runner.php
[edit]
[-] class-jobtype-dbdump.php
[edit]
[-] class-destination-rsc.php
[edit]
[-] class-encryption.php
[edit]
[-] class-destination-downloader-factory.php
[edit]
[-] class-destination-downloader-interface.php
[edit]
[-] class-destination-ftp-type-ftp.php
[edit]
[-] class-path-fixer.php
[edit]
[-] class-message-box.php
[edit]
[-] class-destination-dropbox-api.php
[edit]
[-] class-option.php
[edit]
[-] class-destination-dropbox-api-request-exception.php
[edit]
[-] class-page-about.php
[edit]
[-] class-migrate.php
[edit]
[-] class-system-requirements.php
[edit]
[-] class-adminbar.php
[edit]
[-] class-msazure-destination-configuration.php
[edit]
[-] class-job.php
[edit]
[-] class-destination-ftp-type-exception.php
[edit]
[-] class-destination-sugarsync-api.php
[edit]
[-] class-download-file-interface.php
[edit]
[-] class-encryption-fallback.php
[edit]
[-] BackWPup.php
[edit]
[-] class-page-backwpup.php
[edit]
[-] class-destination-downloader-data.php
[edit]
[-] class-mysqldump-exception.php
[edit]
[-] class-s3-destination.php
[edit]
[-] class-destination-ftp.php
[edit]
[-] class-cron.php
[edit]
[+]
Notice
[-] class-destination-downloader.php
[edit]
[-] class-destinations.php
[edit]
[-] class-destination-ftp-downloader.php
[edit]
[-] class-destination-dropbox-downloader.php
[edit]
[-] class-download-handler.php
[edit]
[-] class-destination-dropbox.php
[edit]
[-] class-system-tests.php
[edit]
[-] class-destination-folder-downloader.php
[edit]
[-] class-destination-ftp-type.php
[edit]
[-] class-thirdparties.php
[edit]
[-] class-jobtype-wpplugin.php
[edit]
[-] class-directory.php
[edit]
[-] class-recursive-directory.php
[edit]
[-] class-destination-msazure-downloader.php
[edit]
[-] class-destination-connect-interface.php
[edit]
[-] class-install.php
[edit]
[-] class-admin.php
[edit]
[-] class-jobtype-file.php
[edit]
[-] functions.php
[edit]
[+]
Utils
[+]
ThirdParty
[-] class-destination-s3-downloader.php
[edit]
[-] class-destination-rsc-downloader.php
[edit]
[-] class-destination-sugarsync-downloader.php
[edit]
[-] class-destination-email.php
[edit]
[+]
..
[-] class-mysqldump.php
[edit]
[-] class-page-firstbackup.php
[edit]
[-] class-jobtype-wpexp.php
[edit]
[-] class-jobtype-dbcheck.php
[edit]
[-] class-file.php
[edit]
[-] class-sanitize-path.php
[edit]
[+]
Settings
[-] class-destination-s3.php
[edit]
[-] class-page-logs.php
[edit]
[-] class-factory-exception.php
[edit]
[-] class-page-restore.php
[edit]
[+]
dependencies
[-] class-create-archive-exception.php
[edit]
[-] class-page-editjob.php
[edit]
[-] class-page-backups.php
[edit]
[-] class-destination-dropbox-api-exception.php
[edit]
[-] class-create-archive.php
[edit]
[-] class-encryption-openssl.php
[edit]
[-] class-destination-onedrive-config-trait.php
[edit]
[-] class-destination-download-exception.php
[edit]
[-] class-download-file.php
[edit]
[-] class-page-settings.php
[edit]
[-] class-destination-msazure.php
[edit]
[-] class-page-onboarding.php
[edit]
[-] class-destination-folder.php
[edit]
[-] class-jobtypes.php
[edit]
[-] class-destination-connect-exception.php
[edit]
[-] class-destination-sugarsync.php
[edit]
[-] class-page-jobs.php
[edit]
[-] class-destination-sugarsync-api-exception.php
[edit]
[-] class-encryption-mcrypt.php
[edit]