/**
  * Migrate a single attachment's files to S3
  *
  * @subcommand migrate-attachment
  * @synopsis <attachment-id> [--delete-local]
  */
 public function migrate_attachment_to_s3($args, $args_assoc)
 {
     // Ensure things are active
     $instance = S3_Uploads::get_instance();
     if (!s3_uploads_enabled()) {
         $instance->setup();
     }
     $old_upload_dir = $instance->get_original_upload_dir();
     $upload_dir = wp_upload_dir();
     $files = array(get_post_meta($args[0], '_wp_attached_file', true));
     $meta_data = wp_get_attachment_metadata($args[0]);
     if (!empty($meta_data['sizes'])) {
         foreach ($meta_data['sizes'] as $file) {
             $files[] = path_join(dirname($meta_data['file']), $file['file']);
         }
     }
     foreach ($files as $file) {
         if (file_exists($path = $old_upload_dir['basedir'] . '/' . $file)) {
             if (!copy($path, $upload_dir['basedir'] . '/' . $file)) {
                 WP_CLI::line(sprintf('Failed to moved %s to S3', $file));
             } else {
                 if (!empty($args_assoc['delete-local'])) {
                     unlink($path);
                 }
                 WP_CLI::success(sprintf('Moved file %s to S3', $file));
             }
         } else {
             WP_CLI::line(sprintf('Already moved to %s S3', $file));
         }
     }
 }
 public function test_s3_uploads_enabled()
 {
     $this->assertTrue(s3_uploads_enabled());
     update_option('s3_uploads_enabled', 'enabled');
     $this->assertTrue(s3_uploads_enabled());
     delete_option('s3_uploads_enabled');
     define('S3_UPLOADS_AUTOENABLE', false);
     $this->assertFalse(s3_uploads_enabled());
     update_option('s3_uploads_enabled', 'enabled');
     $this->assertTrue(s3_uploads_enabled());
 }
Exemple #3
0
function s3_uploads_init()
{
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}
Exemple #4
0
function s3_uploads_init()
{
    if (!s3_uploads_check_requirements()) {
        return;
    }
    if (!defined('S3_UPLOADS_BUCKET')) {
        return;
    }
    if ((!defined('S3_UPLOADS_KEY') || !defined('S3_UPLOADS_SECRET')) && !defined('S3_UPLOADS_USE_INSTANCE_PROFILE')) {
        return;
    }
    if (!s3_uploads_enabled()) {
        return;
    }
    if (!defined('S3_UPLOADS_REGION')) {
        wp_die('S3_UPLOADS_REGION constant is required. Please define it in your wp-config.php');
    }
    $instance = S3_Uploads::get_instance();
    $instance->setup();
}