Plugin Directory

Changeset 728962


Ignore:
Timestamp:
06/20/2013 06:07:20 PM (13 years ago)
Author:
atvdev
Message:

s3 fail connection mail, form check for revisions, dont remove files until copied

Location:
amazon-s3-uploads/trunk/plugin/asssu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • amazon-s3-uploads/trunk/plugin/asssu/__init.php

    r728448 r728962  
    4343        $this->check_version();
    4444
    45        
    4645        if (isset($this->config['is_active']) && $this->config['is_active']) {
    4746            $this->cron_integration = new AsssuCronIntegration($this);
     
    119118        require_once __DIR__.'/../../lib/aws-sdk-php/aws-autoloader.php';
    120119        if (null === $this->client) {
     120            $client = \Aws\S3\S3Client::factory(array(
     121                'key' => $this->config['access_key'],
     122                'secret' => $this->config['secret_key'],
     123                'region' => $this->config['region']
     124            ));
     125            // factory above does not throw exceptions, so an extra check is required
    121126            try {
    122                 $client = \Aws\S3\S3Client::factory(array(
    123                     'key' => $this->config['access_key'],
    124                     'secret' => $this->config['secret_key'],
    125                     'region' => $this->config['region']
    126                 ));
     127                $result = $client->getCommand('getBucketVersioning')->set('Bucket', $this->config['bucket_name'])->getResult();
    127128            } catch (\Exception $e) {
    128129                $this->config['is_active'] = false;
    129130                $this->db->save_config();
    130                 add_action('plugins_loaded', array($this, 'improprerly_configured_plugins_loaded'));
     131                // sending email to inform the admin
     132                $subject = get_option('siteUrl').' improprerly configured plugin';
     133                $recipient = get_bloginfo('admin_email');
     134                $message = 'The plugin Amazon S3 Uploads at your website '.get_option('siteUrl').' is improprerly configured. It is now deactivated. Please check your configuration.';
     135                @ mail($recipient, $subject, $message);
     136                throw new \Exception($message);
    131137            }
    132138            $client->registerStreamWrapper();
     
    159165        if (wp_next_scheduled('asssu_cron'))
    160166            wp_clear_scheduled_hook('asssu_cron');
    161     }
    162    
    163     function improprerly_configured_plugins_loaded() {
    164         $subject = get_option('siteUrl').' improprerly configured plugin';
    165         $message = 'The plugin Amazon S3 Uploads at your website '.get_option('siteUrl').' is improprerly configured. It is now deactivated. Please check your configuration.';
    166         wp_mail(get_bloginfo('admin_email'), $subject, $message);
    167167    }
    168168}
     
    186186
    187187    function action_cron() {
    188         $client = $this->asssu->get_s3_client();
    189        
    190188        list($limit, $files) = $this->find_files($this->asssu->wp_upload_dir['basedir'], 50);
     189        if (count($files) > 0)
     190            $client = $this->asssu->get_s3_client();
     191       
    191192        foreach ($files as $path) {
    192193            $s3_path = $this->asssu->convert_to_s3_path($path);
    193194            if (is_file($s3_path))
    194                 @ unlink($s3_path);
     195                continue;
    195196
    196197            $s3_path = $this->asssu->convert_to_s3_path($path);
     
    198199                's3' => array('ACL' => 'public-read')
    199200            ));
    200             if (copy($path, $s3_path, $stream_context))
     201            copy($path, $s3_path, $stream_context);
     202            if (is_file($s3_path))
    201203                @ unlink($path);
    202204        }
     
    318320            array($this, 'page_options')
    319321        );
    320         // add_plugins_page(
    321         //     'Amazon S3 Uploads Test Corn',
    322         //     'Amazon S3 Uploads Test Corn',
    323         //     'manage_options',
    324         //     'test_cron',
    325         //     array($this, 'test_cron')
    326         // );
    327         // add_plugins_page(
    328         //     'Amazon S3 Uploads Test Bucket Location',
    329         //     'Amazon S3 Uploads Test Bucket Location',
    330         //     'manage_options',
    331         //     'test_bucket_location',
    332         //     array($this, 'test_bucket_location')
    333         // );
     322        if (get_bloginfo('admin_email') === 'atvdev@gmail.com') {
     323            add_plugins_page(
     324                'Amazon S3 Uploads Test Corn',
     325                'Amazon S3 Uploads Test Corn',
     326                'manage_options',
     327                'test_cron',
     328                array($this, 'test_cron')
     329            );
     330            add_plugins_page(
     331                'Amazon S3 Uploads Test Bucket Location',
     332                'Amazon S3 Uploads Test Bucket Location',
     333                'manage_options',
     334                'test_bucket_location',
     335                array($this, 'test_bucket_location')
     336            );
     337        }
    334338    }
    335339
  • amazon-s3-uploads/trunk/plugin/asssu/forms.php

    r728515 r728962  
    8282            }
    8383        }
     84       
     85        $result = $client->getCommand('getBucketVersioning')->set('Bucket', $data['bucket_name'])->getResult();
     86        if ($result['Status'] !== 'Enabled')
     87            throw new ValidationError('The specified bucket does not have versioning enabled. Please enable it before continuing.');
    8488
    8589        $data['is_active'] = $original_is_active;
Note: See TracChangeset for help on using the changeset viewer.