/[drupal]/contributions/modules/media_mover/contrib/mm_s3/mm_s3.module
ViewVC logotype

Diff of /contributions/modules/media_mover/contrib/mm_s3/mm_s3.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.2.2.21, Fri Oct 30 15:23:00 2009 UTC revision 1.1.2.2.2.22, Sun Nov 1 15:38:38 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: mm_s3.module,v 1.1.2.2.2.20 2009/10/05 01:26:30 arthuregg Exp $  // $Id: mm_s3.module,v 1.1.2.2.2.21 2009/10/30 15:23:00 arthuregg Exp $
4    
5  define('ACL_PRIVATE', 'private');  define('ACL_PRIVATE', 'private');
6  define('ACL_PUBLIC_READ', 'public-read');  define('ACL_PUBLIC_READ', 'public-read');
# Line 225  function mm_s3_config($action_id, $confi Line 225  function mm_s3_config($action_id, $confi
225    $form['mm_s3']['mm_s3_bucket'] = array(    $form['mm_s3']['mm_s3_bucket'] = array(
226      '#type' => 'textfield',      '#type' => 'textfield',
227      '#title' => t('S3 Bucket'),      '#title' => t('S3 Bucket'),
228      '#default_value' => $configuration['mm_s3_bucket'] ? $configuration['mm_s3_bucket'] : variable_get('mm_s3_bucket', str_replace(" ", "_", variable_get('site_name', 'my_site'))),      '#default_value' => $configuration['mm_s3_bucket'],
229      '#description' => t('Name of the S3 bucket, note this has to be unique on Amazon\'s servers'),      '#description' => t('Name of the S3 bucket, note this has to be unique on Amazon\'s servers.'),
230    );    );
231    
232    $form['mm_s3']['mm_s3_perm'] = array(    $form['mm_s3']['mm_s3_perm'] = array(
# Line 239  function mm_s3_config($action_id, $confi Line 239  function mm_s3_config($action_id, $confi
239    
240    $form['mm_s3']['mm_s3_delete_source'] = array(    $form['mm_s3']['mm_s3_delete_source'] = array(
241      '#type' => 'checkbox',      '#type' => 'checkbox',
242        '#title' => t('Use full Drupal filepath on S3'),
243        '#description' => t('Selecting this will store your files on S3 with the Drupal directory path as
244          part of the file name- for example <em>sites/default/files/myfile.jpg</em> This is useful if you
245          are concerned about duplicate filenames or using URL rewriting to serve files from Amazon'),
246        '#default_value' => $configuration['mm_s3_delete_source'],
247      );
248    
249      $form['mm_s3']['mm_s3_drupal_file_path'] = array(
250        '#type' => 'checkbox',
251      '#title' => t('Delete source material after succesfully moving to S3'),      '#title' => t('Delete source material after succesfully moving to S3'),
252      '#description' => t('Be very careful when you select this option. This will remove your original material, which will prevent future harvests and potentially removing it from the Drupal file system. Do not activate thus UNLESS you understand that you may loose your source material.'),      '#description' => t('Be very careful when you select this option. This will remove your original material, which will prevent future harvests and potentially removing it from the Drupal file system. Do not activate thus UNLESS you understand that you may loose your source material.'),
253      '#default_value' => $configuration['mm_s3_delete_source'],      '#default_value' => $configuration['mm_s3_drupal_file_path'],
254    );    );
255    
256    $form['mm_s3']['advanced'] = array(    $form['mm_s3']['advanced'] = array(
# Line 253  function mm_s3_config($action_id, $confi Line 262  function mm_s3_config($action_id, $confi
262    $form['mm_s3']['advanced']['mm_s3_server_url'] = array(    $form['mm_s3']['advanced']['mm_s3_server_url'] = array(
263      '#type' => 'textfield',      '#type' => 'textfield',
264      '#title' => t('Server URL'),      '#title' => t('Server URL'),
265      '#default_value' => $configuration['mm_s3_server_url'] ? $configuration['mm_s3_server_url'] : variable_get('mm_s3_server_url', "https://s3.amazonaws.com/"),      '#default_value' => $configuration['mm_s3_server_url'] ? $configuration['mm_s3_server_url'] : variable_get('mm_s3_server_url', 'https://s3.amazonaws.com/'),
266      '#description' => t('Server URL. Use this to set the URL where your files will be served from. Normally this is s3.amazonaws.com'),      '#description' => t('Server URL. Use this to set the URL where your files will be served from. Normally this is s3.amazonaws.com, however you can define your own S3 URL with your DNS service.'),
267    );    );
268    
269    return $form;    return $form;
# Line 326  function mm_s3_send($file, $configuratio Line 335  function mm_s3_send($file, $configuratio
335    // assign bucket name, order: specific conf, general conf, sitename    // assign bucket name, order: specific conf, general conf, sitename
336    $bucket = $configuration['mm_s3_bucket'] ? $configuration['mm_s3_bucket'] : variable_get('mm_s3_bucket', str_replace(" ", "_", $conf['site_name']));    $bucket = $configuration['mm_s3_bucket'] ? $configuration['mm_s3_bucket'] : variable_get('mm_s3_bucket', str_replace(" ", "_", $conf['site_name']));
337    
   // we handle two types of file moving here  
   if ($verb = 'storage') { $previous = 'process'; }  
   else {$previous = 'storage'; }  
   
338    // set the permisisons    // set the permisisons
339    $perms = $configuration['mm_s3_perm'] ? $configuration['mm_s3_perm'] : ACL_PUBLIC_READ;    $perms = $configuration['mm_s3_perm'] ? $configuration['mm_s3_perm'] : ACL_PUBLIC_READ;
340    $perms = $perms;    $perms = constant('S3::'. $perms);
341    
342    // create the bucket if it does not exist    // Create the bucket on S3 if it does not exist
343    $s3->putBucket($bucket, $perms);    $s3->putBucket($bucket, $perms);
344    
345      // We need to set the filename based on the setting in this configuration
346      // Sometimes it is a good idea to save the full $filepath as the filename
347      if (! $configuration['mm_s3_drupal_file_path']) {
348            $s3_filename = basebath($filepath);
349      }
350      else {
351            $s3_filename = $filepath;
352      }
353    
354    // Put file on amazon. Note that we are using the full path as the file name on S3    // Put file on amazon. Note that we are using the full path as the file name on S3
355    $s3->putObjectFile($filepath, $bucket, $filepath, $perms, array(), file_get_mimetype($filepath));    $s3->putObjectFile($filepath, $bucket, $s3_filename, $perms, array(), file_get_mimetype($filepath));
356    
357    // Make sure the file made it to amazon    // Make sure the file made it to amazon
358    $info = $s3->getObjectInfo($bucket, $filepath);    $info = $s3->getObjectInfo($bucket, $s3_filename);
359    // Error check    // Error check
360    if (! $info['hash']) {    if (! $info['hash']) {
361      // Error condition when trying to put file up      // Error condition when trying to put file up
# Line 353  function mm_s3_send($file, $configuratio Line 367  function mm_s3_send($file, $configuratio
367    
368    // do we have additional files to push up?    // do we have additional files to push up?
369    // This is somewhat hacky. Media Mover needs to clarify this stuff    // This is somewhat hacky. Media Mover needs to clarify this stuff
370      // @TODO this is all hacky
371    if ($file['additional_items']) {    if ($file['additional_items']) {
372      foreach ($file['additional_items'] as $module_name => $actions ) {      foreach ($file['additional_items'] as $module_name => $actions ) {
373        foreach ($actions as $action => $items) {        foreach ($actions as $action => $items) {
# Line 384  function mm_s3_send($file, $configuratio Line 399  function mm_s3_send($file, $configuratio
399    }    }
400    
401    // create the return file    // create the return file
402    return $configuration['mm_s3_server_url'] . $bucket ."/". $filepath;    return $configuration['mm_s3_server_url'] . $filename;
403  }  }
404    
405    

Legend:
Removed from v.1.1.2.2.2.21  
changed lines
  Added in v.1.1.2.2.2.22

  ViewVC Help
Powered by ViewVC 1.1.2