/[drupal]/contributions/modules/media_mover/media_mover_api.module
ViewVC logotype

Diff of /contributions/modules/media_mover/media_mover_api.module

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

revision 1.1.2.110.2.47.2.34, Mon Oct 19 11:45:53 2009 UTC revision 1.1.2.110.2.47.2.35, Tue Oct 20 00:48:11 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  /* $Id: media_mover_api.module,v 1.1.2.110.2.47.2.33 2009/10/19 02:52:57 arthuregg Exp $ */  /* $Id: media_mover_api.module,v 1.1.2.110.2.47.2.34 2009/10/19 11:45:53 arthuregg Exp $ */
4    
5    
6  /*  /*
# Line 269  function media_mover_api_configuration_s Line 269  function media_mover_api_configuration_s
269    // If we are on the first step of the configuration we need    // If we are on the first step of the configuration we need
270    // to harvest files rather than select them from the DB    // to harvest files rather than select them from the DB
271    if ($step->sid == 1) {    if ($step->sid == 1) {
272        print "here in harvest \n";
273      return media_mover_api_configuration_harvest($configuration);      return media_mover_api_configuration_harvest($configuration);
274    }    }
275      print "out of harvest \n";
276    // How many files should we deal with?    // How many files should we deal with?
277    $limit = $configuration->settings->{'mma_'. $sid .'_num'} ? $configuration->settings->{'mma_'. $step->sid .'_num'} : variable_get('mma_'. $step->sid .'_num', 0);    $limit = $configuration->settings->{'mma_'. $step->sid .'_num'} ? $configuration->settings->{'mma_'. $step->sid .'_num'} : variable_get('mma_'. $step->sid .'_num', 0);
278    // Get the files associated with this step, make sure to not get cached files    // Get the files associated with this step, make sure to not get cached files
279    $files = media_mover_api_files_get($configuration->cid, $step->sid, $limit, MMA_FILE_STATUS_READY);    // @NOTE We always get the last steps files
280      $files = media_mover_api_files_get($configuration->cid, ($step->sid - 1), $limit, MMA_FILE_STATUS_READY);
281    $output = t('Configuration step: %description is acting on %count files', array('%description' => $step->description, '%count' => count($files) )) .'<br />';    $output = t('Configuration step: %description is acting on %count files', array('%description' => $step->description, '%count' => count($files) )) .'<br />';
282    // loop through all of the found files for this status    // loop through all of the found files for this status
283    foreach ($files as $file) {    foreach ($files as $file) {
284          // Only run this if run_control does not try to stop it          // Only run this if run_control does not try to stop it
285      if (! media_mover_api_run_control_extend($configuration, $step->sid .'_run', $file) ) {      if (! media_mover_api_run_control_extend($configuration, $step->sid .'_run', $file) ) {
286        $output .= media_mover_api_configuration_step_file_run($configuration, $file);        $output .= media_mover_api_configuration_step_file_run($configuration, $step, $file);
287          }          }
288    }    }
289    return $output;    return $output;
# Line 301  function media_mover_api_configuration_s Line 303  function media_mover_api_configuration_s
303   * @return $file   * @return $file
304   *   object, the file that has been acted upon   *   object, the file that has been acted upon
305   */   */
306  function media_mover_api_configuration_step_file_run($configuration, &$file) {  function media_mover_api_configuration_step_file_run($configuration, $step, &$file) {
307    // make sure no one else is trying to operate on this file    // make sure no one else is trying to operate on this file
308    if ($this->lock())  {    if ($file->lock())  {
309      // get the current step function to call      // get the current step function to call
310      $function = $file->steps{$file->current_step}->action;      $function = $step->callback;
311      if ($filepath = $function($step, $file)) {      if ($filepath = $function($step, $file)) {
312        // add the new file path to the file object. Some modules may return true instead        // add the new file path to the file object. Some modules may return true instead
313        // of a file path. If this is the case, get the current filepath        // of a file path. If this is the case, get the current filepath
314        $file->filepath = $filepath === true ? $file->filepath : $filepath;        $file->filepath = $filepath === true ? $file->filepath : $filepath;
315        // assign this file path to the correct step        // Keep a record of what file was used in each step
316        $file->steps->{$file->current_step}->filepath = $file_path;        $file->data->steps[$step->sid]['filepath'] = $file_path;
       // advance the file to the next path  
       $file->step_next();  
317        // update the status        // update the status
318        $file->status_update(MMA_FILE_STATUS_READY);        $file->status_update(MMA_FILE_STATUS_READY);
319         // update file record and advance the step        // update file record and advance the step
320        $file->save(true);        $file->save(true);
321          $file->unlock();
322      }      }
323      else {      else {
324        // failed        // failed
325        $file->update_status(MMA_FILE_STATUS_ERROR);        $file->update_status(MMA_FILE_STATUS_ERROR);
326          $file->unlock();
327        return;        return;
328      }      }
329    
330      // call the event triger      // call the event triger
331      media_mover_api_event_trigger('config', 'run', $step, $file);      media_mover_api_event_trigger('config', 'run', $step, $file);
   
     $this->unlock;  
332    }    }
333  }  }
334    
# Line 342  function media_mover_api_configuration_h Line 342  function media_mover_api_configuration_h
342     // Lock the configuration to prevent harvest overruns     // Lock the configuration to prevent harvest overruns
343     if ($configuration->step_lock()) {     if ($configuration->step_lock()) {
344       $function = $configuration->steps[1]->callback;       $function = $configuration->steps[1]->callback;
345       $files = $function($configuration->steps[1]);       if ($files = $function($configuration->steps[1])) {
346       foreach ($files as $harvest_file){         foreach ($files as $harvest_file){
347         $file = new media_mover_file();           $file = new media_mover_file();
348         foreach($harvest_file as $key => $value) {           foreach($harvest_file as $key => $value) {
349           $file->{$key} = $value;             $file->{$key} = $value;
350             }
351             // Set the configuration id
352             $file->cid = $configuration->cid;
353             $file->save(true);
354         }         }
355         // Set the configuration id         $configuration->step_unlock();
        $file->cid = $configuration->cid;  
   
        $file->save();  
356       }       }
      $configuration->step_unlock();  
357       return t('Harvested %count files <br />', array('%count' => count($files)));       return t('Harvested %count files <br />', array('%count' => count($files)));
358     }     }
359  }  }
# Line 535  function media_mover_api_files_get($cid Line 535  function media_mover_api_files_get($cid
535   *   media mover file object   *   media mover file object
536   */   */
537  function media_mover_api_file_get($mmfid, $reset = false) {  function media_mover_api_file_get($mmfid, $reset = false) {
538    static $cached;    // static $cached;
539    // can we return the cached item    // can we return the cached item
540    if (! $cached[$mmfid] || $reset) {    if (! $cached[$mmfid] || $reset) {
541      $file = new media_mover_file();      $file = new media_mover_file();
542      $file->load($mmfid);      $file->load($mmfid);
543      // cache this locally      // cache this locally
544      $cached[$mmfid] = $file;      $cached[$mmfid] = $file;
545    }    }
546    return $cached[$mmfid];    return $cached[$mmfid];
547  }  }
# Line 680  function media_mover_api_configuration_g Line 680  function media_mover_api_configuration_g
680    
681    if (! $configurations[$cid]) {    if (! $configurations[$cid]) {
682      $configuration = new media_mover_configuration();      $configuration = new media_mover_configuration();
683      $configuration->get($cid);      $configuration->load($cid);
684      $configurations[$cid] = $configuration;      $configurations[$cid] = $configuration;
685    }    }
686    

Legend:
Removed from v.1.1.2.110.2.47.2.34  
changed lines
  Added in v.1.1.2.110.2.47.2.35

  ViewVC Help
Powered by ViewVC 1.1.2