Changeset 468 for trunk/lib/Lock.inc.php
- Timestamp:
- Feb 20, 2014 3:03:59 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
/branches/eli_branch merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/lib/Lock.inc.php
r424 r468 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 31 31 class Lock { 32 32 33 // A place to keep an object instance for the singleton pattern. 34 private static $instance = null; 35 33 36 // Configuration of this object. 34 var$_params = array(37 private $_params = array( 35 38 'timeout' => 600, 36 39 'auto_timeout' => 1800, … … 44 47 45 48 // Store lock data from DB. 46 var$data = array();49 private $data = array(); 47 50 48 51 // Auth_SQL object from which to access a current user_id. 49 var$_auth;52 private $_auth; 50 53 51 54 /** … … 56 59 * @static 57 60 */ 58 static function &getInstance($auth_object) 59 { 60 static $instance = null; 61 62 if ($instance === null) { 63 $instance = new Lock($auth_object); 64 } 65 66 return $instance; 61 public static function &getInstance($auth_object) 62 { 63 if (self::$instance === null) { 64 self::$instance = new self($auth_object); 65 } 66 67 return self::$instance; 67 68 } 68 69 … … 72 73 * @param mixed $auth_object An Auth_SQL or Auth_FILE object. 73 74 */ 74 function Lock($auth_object)75 public function __construct($auth_object) 75 76 { 76 77 $app =& App::getInstance(); … … 95 96 * @since 26 Aug 2005 17:09:36 96 97 */ 97 function initDB($recreate_db=false)98 public function initDB($recreate_db=false) 98 99 { 99 100 $app =& App::getInstance(); … … 142 143 * @param array $params Array of param keys and values to set. 143 144 */ 144 function setParam($params=null)145 public function setParam($params=null) 145 146 { 146 147 if (isset($params) && is_array($params)) { … … 157 158 * @return mixed Configured parameter value. 158 159 */ 159 function getParam($param)160 { 161 $app =& App::getInstance(); 162 160 public function getParam($param) 161 { 162 $app =& App::getInstance(); 163 163 164 if (isset($this->_params[$param])) { 164 165 return $this->_params[$param]; … … 178 179 * @param string $title A title to apply to the lock, for display purposes. 179 180 */ 180 function select($record_table_or_lock_id, $record_key=null, $record_val=null)181 public function select($record_table_or_lock_id, $record_key=null, $record_val=null) 181 182 { 182 183 $app =& App::getInstance(); … … 205 206 if ($this->data = mysql_fetch_assoc($qid)) { 206 207 $app->logMsg(sprintf('Selecting %slocked record: %s %s %s', ($this->data['set_by_admin_id'] == $this->_auth->get('user_id') ? 'self-' : ''), $record_table_or_lock_id, $record_key, $record_val), LOG_DEBUG, __FILE__, __LINE__); 207 // / FIXME: What if admin set lock, but public user is current lock user?208 // FIXME: What if admin set lock, but public user is current lock user? 208 209 $this->data['editor'] = $this->_auth->getUsername($this->data['set_by_admin_id']); 209 210 return true; … … 219 220 * @return bool True if locked. 220 221 */ 221 function isLocked()222 public function isLocked() 222 223 { 223 224 return isset($this->data['lock_id']); … … 230 231 * @return bool True if current user set the lock. 231 232 */ 232 function isMine()233 { 234 $db =& DB::getInstance(); 235 233 public function isMine() 234 { 235 $db =& DB::getInstance(); 236 236 237 $this->initDB(); 237 238 … … 258 259 * @return int The id for the lock (mysql last insert id). 259 260 */ 260 function set($record_table, $record_key, $record_val, $title='')261 { 262 $db =& DB::getInstance(); 263 261 public function set($record_table, $record_key, $record_val, $title='') 262 { 263 $db =& DB::getInstance(); 264 264 265 $this->initDB(); 265 266 … … 304 305 * Unlock the currently selected record. 305 306 */ 306 function remove()307 public function remove() 307 308 { 308 309 $app =& App::getInstance(); … … 326 327 * Unlock all records, or all records for a specified user. 327 328 */ 328 function removeAll($user_id=null)329 public function removeAll($user_id=null) 329 330 { 330 331 $app =& App::getInstance(); … … 350 351 * Deletes all locks that are older than auto_timeout. 351 352 */ 352 function _auto_timeout()353 { 354 $db =& DB::getInstance(); 355 353 public function _auto_timeout() 354 { 355 $db =& DB::getInstance(); 356 356 357 static $_timeout_run = false; 357 358 … … 371 372 * Redirect to record lock error page. 372 373 */ 373 function dieErrorPage()374 public function dieErrorPage() 374 375 { 375 376 $app =& App::getInstance(); … … 381 382 * Print error page. 382 383 */ 383 function printErrorHTML()384 public function printErrorHTML() 384 385 { 385 386 $app =& App::getInstance(); … … 416 417 * Return lock_id of locked record. 417 418 */ 418 function getID()419 public function getID() 419 420 { 420 421 return $this->data['lock_id']; … … 424 425 * Return title of locked record. 425 426 */ 426 function getTitle()427 public function getTitle() 427 428 { 428 429 return $this->data['title']; … … 432 433 * Return administrator username for locked record. 433 434 */ 434 function getEditor()435 public function getEditor() 435 436 { 436 437 return $this->data['editor']; … … 440 441 * Return total seconds since the record was locked. 441 442 */ 442 function getSecondsElapsed()443 public function getSecondsElapsed() 443 444 { 444 445 if (isset($this->data['lock_datetime']) && strtotime($this->data['lock_datetime']) < time()) { … … 451 452 452 453 } // End of class. 453 ?>
Note: See TracChangeset
for help on using the changeset viewer.