Changeset 42 for trunk/lib/RecordVersion.inc.php
- Timestamp:
- Dec 18, 2005 12:16:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/RecordVersion.inc.php
r41 r42 1 1 <?php 2 2 /** 3 * The RecordVersion:: class provides a system for saving, reviewing, and 3 * The RecordVersion:: class provides a system for saving, reviewing, and 4 4 * restoring versions of a record of any DB table. All the data in the record is 5 5 * serialized, compressed, and saved in a blob in the version_tbl. Restoring a 6 6 * version simply does a REPLACE INTO of the data. It is very simple, and works 7 7 * 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 9 9 * be saved, but not categories associated to the record in a category_article_tbl. 10 10 * The restored article will simple retain the relationships that the previous … … 40 40 { 41 41 static $instances = array(); 42 42 43 43 if (!isset($instances[$auth_object->getVal('auth_name')])) { 44 44 $instances[$auth_object->getVal('auth_name')] = new RecordVersion($auth_object); … … 58 58 trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR); 59 59 } 60 60 61 61 $this->_auth = $auth_object; 62 62 63 63 // Get create tables config from global context. 64 64 if (!is_null(App::getParam('db_create_tables'))) { … … 66 66 } 67 67 } 68 68 69 69 /** 70 70 * Setup the database table for this class. … … 77 77 { 78 78 static $_db_tested = false; 79 79 80 80 if ($recreate_db || !$_db_tested && $this->getParam('create_table')) { 81 81 if ($recreate_db) { … … 98 98 KEY record_val (record_val) 99 99 )"); 100 100 101 101 if (!DB::columnExists($this->getParam('db_table'), array( 102 102 'version_id', … … 113 113 trigger_error(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), E_USER_ERROR); 114 114 } 115 } 115 } 116 116 $_db_tested = true; 117 117 } … … 160 160 { 161 161 $this->initDB(); 162 162 163 163 // Get current record. 164 164 if (!$record = $this->getCurrent($record_table, $record_key, $record_val)) { … … 166 166 return false; 167 167 } 168 168 169 169 // Clean-up old versions. 170 170 $this->deleteOld($record_table, $record_key, $record_val); 171 171 172 172 // Save as new version. 173 173 DB::query(" … … 206 206 { 207 207 $this->initDB(); 208 208 209 209 // Get version data. 210 210 $qid = DB::query(" 211 SELECT * FROM " . $this->getParam('db_table') . " 211 SELECT * FROM " . $this->getParam('db_table') . " 212 212 WHERE version_id = '" . addslashes($version_id) . "' 213 213 "); … … 228 228 // SQLize the keys of the specified versioned record. 229 229 $replace_keys = join(",\n", array_map('addslashes', array_keys($data))); 230 230 231 231 // SQLize the keys of the values of the specified versioned record. (These are more complex because we need to account for SQL null values.) 232 232 $replace_values = ''; … … 236 236 $comma = ','; 237 237 } 238 238 239 239 // Replace current record with specified versioned record. 240 240 DB::query(" … … 245 245 ) 246 246 "); 247 247 248 248 return $record; 249 249 } … … 252 252 * Version garbage collection. Deletes versions older than min_days 253 253 * 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 255 255 * quantity back down to min_qty. 256 256 * … … 264 264 { 265 265 $this->initDB(); 266 266 267 267 // Get total number of versions for this record. 268 268 $qid = DB::query(" … … 273 273 "); 274 274 list($v_count) = mysql_fetch_row($qid); 275 275 276 276 if ($v_count > $this->getParam('min_qty')) { 277 277 if ($v_count > $this->getParam('max_qty')) { … … 329 329 { 330 330 $this->initDB(); 331 331 332 332 // Get versions of this record. 333 333 $qid = DB::query(" … … 358 358 { 359 359 $this->initDB(); 360 360 361 361 // Get version data. 362 362 $qid = DB::query(" 363 SELECT * FROM " . $this->getParam('db_table') . " 363 SELECT * FROM " . $this->getParam('db_table') . " 364 364 WHERE version_id = '" . addslashes($version_id) . "' 365 365 "); … … 377 377 { 378 378 $this->initDB(); 379 379 380 380 // Get version data. 381 381 $qid = DB::query(" 382 SELECT * FROM " . $this->getParam('db_table') . " 382 SELECT * FROM " . $this->getParam('db_table') . " 383 383 WHERE version_id = '" . addslashes($version_id) . "' 384 384 "); … … 401 401 { 402 402 $this->initDB(); 403 403 404 404 $qid = DB::query(" 405 405 SELECT * FROM " . addslashes($record_table) . "
Note: See TracChangeset
for help on using the changeset viewer.