Changeset 42 for trunk/lib/RecordLock.inc.php
- Timestamp:
- Dec 18, 2005 12:16:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/RecordLock.inc.php
r41 r42 33 33 { 34 34 static $instances = array(); 35 35 36 36 if (!isset($instances[$auth_object->getVal('auth_name')])) { 37 37 $instances[$auth_object->getVal('auth_name')] = new RecordLock($auth_object); … … 53 53 54 54 $this->_auth = $auth_object; 55 55 56 56 // Get create tables config from global context. 57 57 if (!is_null(App::getParam('db_create_tables'))) { … … 70 70 { 71 71 static $_db_tested = false; 72 72 73 73 if ($recreate_db || !$_db_tested && $this->getParam('create_table')) { 74 74 if ($recreate_db) { … … 89 89 KEY record_val (record_val) 90 90 )"); 91 91 92 92 if (!DB::columnExists($this->getParam('db_table'), array( 93 94 95 96 97 98 99 93 'lock_id', 94 'record_table', 95 'record_key', 96 'record_val', 97 'title', 98 'set_by_admin_id', 99 'lock_datetime', 100 100 ), false, false)) { 101 101 App::logMsg(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), LOG_ALERT, __FILE__, __LINE__); 102 102 trigger_error(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), E_USER_ERROR); 103 103 } 104 } 104 } 105 105 $_db_tested = true; 106 106 } … … 151 151 // Expire old locks. 152 152 $this->_auto_timeout(); 153 153 154 154 if (is_numeric($record_table_or_lock_id) && !isset($record_key) && !isset($record_val)) { 155 155 // Get lock data by lock_id. 156 156 $qid = DB::query(" 157 SELECT * FROM " . $this->getParam('db_table') . " 157 SELECT * FROM " . $this->getParam('db_table') . " 158 158 WHERE lock_id = '" . addslashes($record_table_or_lock_id) . "' 159 159 "); … … 161 161 // Get lock data by record specs 162 162 $qid = DB::query(" 163 SELECT * FROM " . $this->getParam('db_table') . " 163 SELECT * FROM " . $this->getParam('db_table') . " 164 164 WHERE record_table = '" . addslashes($record_table_or_lock_id) . "' 165 165 AND record_key = '" . addslashes($record_key) . "' … … 189 189 190 190 /** 191 * Returns the status of who set the lock. Use this to ignore locks set by 191 * Returns the status of who set the lock. Use this to ignore locks set by 192 192 * the current user. 193 193 * … … 197 197 { 198 198 $this->initDB(); 199 199 200 200 if (isset($this->data['lock_id'])) { 201 201 $qid = DB::query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . addslashes($this->data['lock_id']) . "'"); … … 221 221 */ 222 222 function set($record_table, $record_key, $record_val, $title='') 223 { 223 { 224 224 $this->initDB(); 225 225 226 226 // Expire old locks. 227 227 $this->_auto_timeout(); 228 228 229 229 // Remove previous locks if exist. Is this better than using a REPLACE INTO? 230 230 DB::query(" 231 DELETE FROM " . $this->getParam('db_table') . " 231 DELETE FROM " . $this->getParam('db_table') . " 232 232 WHERE record_table = '" . addslashes($record_table) . "' 233 233 AND record_key = '" . addslashes($record_key) . "' 234 234 AND record_val = '" . addslashes($record_val) . "' 235 235 "); 236 236 237 237 // Set new lock. 238 238 DB::query(" … … 254 254 "); 255 255 $lock_id = mysql_insert_id(DB::getDBH()); 256 256 257 257 // Must register this locked record as the current. 258 258 $this->select($lock_id); 259 259 260 260 return $lock_id; 261 261 } … … 270 270 // Expire old locks. 271 271 $this->_auto_timeout(); 272 272 273 273 // Delete a specific lock. 274 274 DB::query(" 275 DELETE FROM " . $this->getParam('db_table') . " 275 DELETE FROM " . $this->getParam('db_table') . " 276 276 WHERE lock_id = '" . addslashes($this->data['lock_id']) . "' 277 277 "); 278 278 279 279 App::logMsg(sprintf('Removing lock: %s', $this->data['lock_id']), LOG_DEBUG, __FILE__, __LINE__); 280 280 } … … 284 284 */ 285 285 function removeAll($user_id=null) 286 { 286 { 287 287 $this->initDB(); 288 288 289 289 // Expire old locks. 290 290 $this->_auto_timeout(); 291 291 292 292 if (isset($user_id)) { 293 293 // Delete specific user's locks. … … 309 309 310 310 $this->initDB(); 311 311 312 312 if (!$_timeout_run) { 313 313 // Delete all old locks. 314 314 DB::query(" 315 DELETE FROM " . $this->getParam('db_table') . " 315 DELETE FROM " . $this->getParam('db_table') . " 316 316 WHERE DATE_ADD(lock_datetime, INTERVAL '" . $this->getParam('auto_timeout') . "' SECOND) < NOW() 317 317 "); … … 337 337 <?php App::printHiddenSession() ?> 338 338 <input type="hidden" name="lock_id" value="<?php echo $this->getID(); ?>" /> 339 339 340 340 <p><?php 341 printf(_("The record <strong>%s</strong> is currently being edited by <strong>%s</strong> (%d minutes elapsed). You cannot modify the record while it is locked by another user."), 342 $this->getTitle(), 343 $this->getEditor(), 341 printf(_("The record <strong>%s</strong> is currently being edited by <strong>%s</strong> (%d minutes elapsed). You cannot modify the record while it is locked by another user."), 342 $this->getTitle(), 343 $this->getEditor(), 344 344 date('i', $this->getSecondsElapsed() + 60) 345 345 ); 346 346 ?></p> 347 347 348 348 <?php if ($this->getSecondsElapsed() > $this->getParam('timeout')) { ?> 349 349 <p><?php printf(_("You can forcibly unlock the record if you believe the editing session has expired. You might want to confirm with %s before doing this."), $this->getEditor()) ?></p> 350 350 <input type="submit" name="unlock" value="<?php echo _("Unlock"); ?>" /> 351 351 <?php } ?> 352 352 353 353 <input type="submit" name="cancel" value="<?php echo _("Cancel"); ?>" /> 354 354 </form>
Note: See TracChangeset
for help on using the changeset viewer.