/[drupal]/contributions/modules/media_mover/class_media_mover_file.php
ViewVC logotype

Diff of /contributions/modules/media_mover/class_media_mover_file.php

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

revision 1.1.2.10, Mon Oct 19 11:45:53 2009 UTC revision 1.1.2.11, Tue Oct 20 00:48:11 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: class_media_mover_file.php,v 1.1.2.9 2009/10/19 02:52:57 arthuregg Exp $  // $Id: class_media_mover_file.php,v 1.1.2.10 2009/10/19 11:45:53 arthuregg Exp $
4    
5  class media_mover_file {  class media_mover_file {
6    
7    // set the default step id of the file    // set the default step id of the file
8    var $sid = 1;    var $sid = 1;
9    
   
10    /**    /**
11     * Get file data for the requested id.     * Get file data for the requested id.
12     *     *
# Line 26  class media_mover_file { Line 25  class media_mover_file {
25        $this->{$key} = $value;        $this->{$key} = $value;
26      }      }
27    
28        // Create the container for step data
29        if (! $this->data->steps) {
30          $this->data->steps = array();
31        }
32    
33      // @TODO fix up api, figure out file paths, etc      // @TODO fix up api, figure out file paths, etc
34    
35      // load any additional data associated assigned by a MM module      // load any additional data associated assigned by a MM module
# Line 50  class media_mover_file { Line 54  class media_mover_file {
54     *   false if you want to save the full file object     *   false if you want to save the full file object
55     */     */
56    function save($advance = false, $single_step = true) {    function save($advance = false, $single_step = true) {
57        $this->build_steps();
58      // if the file does not have a mmfid, it is a new file      // if the file does not have a mmfid, it is a new file
59      // so we need to build a new record for it. A file could also      // so we need to build a new record for it. A file could also
60      // be programatically pushed through- it will not have a mmfid,      // be programatically pushed through- it will not have a mmfid,
61      // but it should have $this->passthrough = true      // but it should have $this->passthrough = true
62      if (! $this->mmfid  && ! $this->passthrough) {      if (! $this->mmfid  && ! $this->passthrough) {
63        db_query('INSERT INTO {media_mover_files} (nid, fid, cid, sid, filepath, status, date, data, filepath_in) VALUES (%d, %d, %d, %d, "%s", "%s", %d, "%s", "%s")',        db_query('INSERT INTO {media_mover_files} (nid, fid, cid, sid, filepath, status, date, data, steps, filepath_in) VALUES (%d, %d, %d, %d, "%s", "%s", %d, "%s", "%s", "%s")',
64          $this->nid, $this->fid, $this->cid, $this->sid, $this->filepath, $this->status, time(), $this->data, $this->filepath_in);          $this->nid, $this->fid, $this->cid, $this->sid, $this->filepath, MMA_FILE_STATUS_READY, time(), $this->data, $this->steps, $this->filepath);
65        // get the mmfid        // get the mmfid
66        $this->mmfid = db_last_insert_id('media_mover_files', 'mmfid');        $this->mmfid = db_last_insert_id('media_mover_files', 'mmfid');
67      }      }
# Line 68  class media_mover_file { Line 73  class media_mover_file {
73        // Sanity check saving file        // Sanity check saving file
74        if ($this->lock() && ! $this->passthrough) {        if ($this->lock() && ! $this->passthrough) {
75          // update the top level file data          // update the top level file data
76          db_query('UPDATE {media_mover_files} SET filepath = "%s", current_step = %d, status = "%s", data = "%s" WHERE mmfid = %d',          db_query('UPDATE {media_mover_files} SET filepath = "%s", sid = %d, status = "%s", data = "%s" steps = "%s" WHERE mmfid = %d',
77            $this->filepath, $this->current_step, $this->status, serialize($this->data), $this->mmfid            $this->filepath, $this->sid, $this->status, serialize($this->data), serialize($this->steps), $this->mmfid
78          );          );
79          $this->unlock();          $this->unlock();
80        }        }
# Line 86  class media_mover_file { Line 91  class media_mover_file {
91    
92    
93    /**    /**
94       * Builds the step data for this file
95       *
96       */
97      function build_step_data() {
98        // If no steps exist make sure we have something to insert into
99        if (! is_array($this->steps)) {
100          $this->steps = array();
101        }
102        // load the configuration
103        $configuration = media_mover_api_configuration_get($this->cid);
104        // get the step
105        $step = $configuration->steps[$file->sid];
106        $this->steps[$this->sid] = array_merge($this->steps[$this->sid], $step);
107        }
108      }
109    
110    
111      /**
112     * Locks a media mover file to prevent it from being used     * Locks a media mover file to prevent it from being used
113     * by multiple processes at the same time     * by multiple processes at the same time
114     *     *
115     * @return boolean     * @return boolean
116     */     */
117    private function lock(){    function lock() {
118      // only lock if the file is in the db, note that this      // only lock if the file is in the db, note that this
119      // prevents locking if we are passing through a file      // prevents locking if we are passing through a file
120      // rather than saving it to the db      // rather than saving it to the db
# Line 126  class media_mover_file { Line 149  class media_mover_file {
149     * Unlock the tables     * Unlock the tables
150     *     *
151     */     */
152    private function unlock() {    function unlock() {
153      // Set this file status to ready      // Set this file status to ready
154      db_query('UPDATE {media_mover_files} SET status = %d WHERE mmfid = %d', MMA_FILE_STATUS_READY, $this->mmfid);      db_query('UPDATE {media_mover_files} SET status = %d WHERE mmfid = %d', MMA_FILE_STATUS_READY, $this->mmfid);
155      // unlock the tables      // unlock the tables
# Line 180  class media_mover_file { Line 203  class media_mover_file {
203     * Moves the file one step forward and sets the file status     * Moves the file one step forward and sets the file status
204     * If the file is in the last step, mark completed.     * If the file is in the last step, mark completed.
205     */     */
206    function step_next($configuration) {    function step_next() {
207        // Load the configuration
208        $configuration = media_mover_api_configuration_get($this->cid);
209      // if we are not on the final step, advance the file      // if we are not on the final step, advance the file
210      if ($this->current_step < $configuration->steps_total() ) {      if ($this->sid < $configuration->total_steps() ) {
211        $this->current_step = $this->current_step + 1;        $this->sid = $this->sid + 1;
212        $file->status = MMA_FILE_STATUS_READY;        $file->status = MMA_FILE_STATUS_READY;
213      }      }
214      // we are finished      // we are finished
# Line 191  class media_mover_file { Line 216  class media_mover_file {
216        $file->status = MMA_FILE_STATUS_FINISHED;        $file->status = MMA_FILE_STATUS_FINISHED;
217      }      }
218    }    }
219    
220    
221    /**    /**
222     * Delete a file     * Delete a file
223     */     */

Legend:
Removed from v.1.1.2.10  
changed lines
  Added in v.1.1.2.11

  ViewVC Help
Powered by ViewVC 1.1.2