Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/RecordVersion.inc.php

    r41 r42  
    11<?php
    22/**
    3  * The RecordVersion:: class provides a system for saving, reviewing, and 
     3 * The RecordVersion:: class provides a system for saving, reviewing, and
    44 * restoring versions of a record of any DB table. All the data in the record is
    55 * serialized, compressed, and saved in a blob in the version_tbl. Restoring a
    66 * version simply does a REPLACE INTO of the data. It is very simple, and works
    77 * with multiple database tables, but the drawback is that relationships for
    8  * a record cannot be retained. For example, an article from an article_tbl can 
     8 * a record cannot be retained. For example, an article from an article_tbl can
    99 * be saved, but not categories associated to the record in a category_article_tbl.
    1010 * The restored article will simple retain the relationships that the previous
     
    4040    {
    4141        static $instances = array();
    42                
     42
    4343        if (!isset($instances[$auth_object->getVal('auth_name')])) {
    4444            $instances[$auth_object->getVal('auth_name')] = new RecordVersion($auth_object);
     
    5858            trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
    5959        }
    60        
     60
    6161        $this->_auth = $auth_object;
    62        
     62
    6363        // Get create tables config from global context.
    6464        if (!is_null(App::getParam('db_create_tables'))) {
     
    6666        }
    6767    }
    68    
     68
    6969    /**
    7070     * Setup the database table for this class.
     
    7777    {
    7878        static $_db_tested = false;
    79    
     79
    8080        if ($recreate_db || !$_db_tested && $this->getParam('create_table')) {
    8181            if ($recreate_db) {
     
    9898                KEY record_val (record_val)
    9999            )");
    100            
     100
    101101            if (!DB::columnExists($this->getParam('db_table'), array(
    102102                'version_id',
     
    113113                trigger_error(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), E_USER_ERROR);
    114114            }
    115         }   
     115        }
    116116        $_db_tested = true;
    117117    }
     
    160160    {
    161161        $this->initDB();
    162    
     162
    163163        // Get current record.
    164164        if (!$record = $this->getCurrent($record_table, $record_key, $record_val)) {
     
    166166            return false;
    167167        }
    168                
     168
    169169        // Clean-up old versions.
    170170        $this->deleteOld($record_table, $record_key, $record_val);
    171        
     171
    172172        // Save as new version.
    173173        DB::query("
     
    206206    {
    207207        $this->initDB();
    208    
     208
    209209        // Get version data.
    210210        $qid = DB::query("
    211             SELECT * FROM " . $this->getParam('db_table') . " 
     211            SELECT * FROM " . $this->getParam('db_table') . "
    212212            WHERE version_id = '" . addslashes($version_id) . "'
    213213        ");
     
    228228        // SQLize the keys of the specified versioned record.
    229229        $replace_keys = join(",\n", array_map('addslashes', array_keys($data)));
    230        
     230
    231231        // SQLize the keys of the values of the specified versioned record. (These are more complex because we need to account for SQL null values.)
    232232        $replace_values = '';
     
    236236            $comma = ',';
    237237        }
    238        
     238
    239239        // Replace current record with specified versioned record.
    240240        DB::query("
     
    245245            )
    246246        ");
    247        
     247
    248248        return $record;
    249249    }
     
    252252     * Version garbage collection. Deletes versions older than min_days
    253253     * when quantity of versions exceeds min_qty. If quantity
    254      * exceeds 100 within min_days, the oldest are deleted to bring the 
     254     * exceeds 100 within min_days, the oldest are deleted to bring the
    255255     * quantity back down to min_qty.
    256256     *
     
    264264    {
    265265        $this->initDB();
    266    
     266
    267267        // Get total number of versions for this record.
    268268        $qid = DB::query("
     
    273273        ");
    274274        list($v_count) = mysql_fetch_row($qid);
    275        
     275
    276276        if ($v_count > $this->getParam('min_qty')) {
    277277            if ($v_count > $this->getParam('max_qty')) {
     
    329329    {
    330330        $this->initDB();
    331    
     331
    332332        // Get versions of this record.
    333333        $qid = DB::query("
     
    358358    {
    359359        $this->initDB();
    360    
     360
    361361        // Get version data.
    362362        $qid = DB::query("
    363             SELECT * FROM " . $this->getParam('db_table') . " 
     363            SELECT * FROM " . $this->getParam('db_table') . "
    364364            WHERE version_id = '" . addslashes($version_id) . "'
    365365        ");
     
    377377    {
    378378        $this->initDB();
    379    
     379
    380380        // Get version data.
    381381        $qid = DB::query("
    382             SELECT * FROM " . $this->getParam('db_table') . " 
     382            SELECT * FROM " . $this->getParam('db_table') . "
    383383            WHERE version_id = '" . addslashes($version_id) . "'
    384384        ");
     
    401401    {
    402402        $this->initDB();
    403    
     403
    404404        $qid = DB::query("
    405405            SELECT * FROM " . addslashes($record_table) . "
Note: See TracChangeset for help on using the changeset viewer.