Example #1
0
 /**
  * Deletes backup file from Amazon S3.
  *
  * @param array $args arguments passed to the function
  *                    [as3_bucket_region] -> Amazon S3 bucket region
  *                    [as3_bucket] -> Amazon S3 bucket
  *                    [as3_access_key] -> Amazon S3 access key
  *                    [as3_secure_key] -> Amazon S3 secure key
  *                    [as3_directory] -> folder on user's Amazon S3 account which backup file should be deleted from
  *                    [as3_site_folder] -> subfolder with site name in as3_directory which backup file should be deleted from
  *                    [backup_file] -> absolute path of backup file on local server
  *
  * @return void
  */
 public function remove_amazons3_backup($args)
 {
     if (!mwp_container()->getSystemEnvironment()->isCurlEnabled()) {
         throw new MWP_Worker_Exception(MWP_Worker_Exception::PHP_EXTENSION_REQUIRED_CURL, 'The cURL PHP extension is required for Amazon S3 backup functionality to work. Please, enquire your hosting provider on how to enable that extension.');
     }
     if ($args['as3_site_folder'] == true) {
         $args['as3_directory'] .= '/' . $this->site_name;
     }
     $endpoint = isset($args['as3_bucket_region']) ? $args['as3_bucket_region'] : 's3.amazonaws.com';
     mwp_logger()->info('Removing the backup file from Amazon S3', array('directory' => $args['as3_directory'], 'bucket' => $args['as3_bucket'], 'endpoint' => $endpoint, 'backup_file' => $args['backup_file']));
     try {
         $s3 = new S3_Client(trim($args['as3_access_key']), trim(str_replace(' ', '+', $args['as3_secure_key'])), false, $endpoint);
         $s3->setExceptions(true);
         $s3->deleteObject($args['as3_bucket'], $args['as3_directory'] . '/' . $args['backup_file']);
     } catch (Exception $e) {
         // @todo what now?
     }
 }