Changeset 468 for trunk/lib/Lock.inc.php


Ignore:
Timestamp:
Feb 20, 2014 3:03:59 AM (10 years ago)
Author:
anonymous
Message:

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/lib/Lock.inc.php

    r424 r468  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3131class Lock {
    3232
     33    // A place to keep an object instance for the singleton pattern.
     34    private static $instance = null;
     35
    3336    // Configuration of this object.
    34     var $_params = array(
     37    private $_params = array(
    3538        'timeout' => 600,
    3639        'auto_timeout' => 1800,
     
    4447
    4548    // Store lock data from DB.
    46     var $data = array();
     49    private $data = array();
    4750
    4851    // Auth_SQL object from which to access a current user_id.
    49     var $_auth;
     52    private $_auth;
    5053
    5154    /**
     
    5659     * @static
    5760     */
    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;
    6768    }
    6869
     
    7273     * @param mixed  $auth_object  An Auth_SQL or Auth_FILE object.
    7374     */
    74     function Lock($auth_object)
     75    public function __construct($auth_object)
    7576    {
    7677        $app =& App::getInstance();
     
    9596     * @since   26 Aug 2005 17:09:36
    9697     */
    97     function initDB($recreate_db=false)
     98    public function initDB($recreate_db=false)
    9899    {
    99100        $app =& App::getInstance();
     
    142143     * @param  array $params   Array of param keys and values to set.
    143144     */
    144     function setParam($params=null)
     145    public function setParam($params=null)
    145146    {
    146147        if (isset($params) && is_array($params)) {
     
    157158     * @return mixed               Configured parameter value.
    158159     */
    159     function getParam($param)
    160     {
    161         $app =& App::getInstance();
    162    
     160    public function getParam($param)
     161    {
     162        $app =& App::getInstance();
     163
    163164        if (isset($this->_params[$param])) {
    164165            return $this->_params[$param];
     
    178179     * @param string $title       A title to apply to the lock, for display purposes.
    179180     */
    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)
    181182    {
    182183        $app =& App::getInstance();
     
    205206        if ($this->data = mysql_fetch_assoc($qid)) {
    206207            $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             /// FIX ME: 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?
    208209            $this->data['editor'] = $this->_auth->getUsername($this->data['set_by_admin_id']);
    209210            return true;
     
    219220     * @return bool            True if locked.
    220221     */
    221     function isLocked()
     222    public function isLocked()
    222223    {
    223224        return isset($this->data['lock_id']);
     
    230231     * @return bool            True if current user set the lock.
    231232     */
    232     function isMine()
    233     {
    234         $db =& DB::getInstance();
    235    
     233    public function isMine()
     234    {
     235        $db =& DB::getInstance();
     236
    236237        $this->initDB();
    237238
     
    258259     * @return int            The id for the lock (mysql last insert id).
    259260     */
    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
    264265        $this->initDB();
    265266
     
    304305     * Unlock the currently selected record.
    305306     */
    306     function remove()
     307    public function remove()
    307308    {
    308309        $app =& App::getInstance();
     
    326327     * Unlock all records, or all records for a specified user.
    327328     */
    328     function removeAll($user_id=null)
     329    public function removeAll($user_id=null)
    329330    {
    330331        $app =& App::getInstance();
     
    350351     * Deletes all locks that are older than auto_timeout.
    351352     */
    352     function _auto_timeout()
    353     {
    354         $db =& DB::getInstance();
    355    
     353    public function _auto_timeout()
     354    {
     355        $db =& DB::getInstance();
     356
    356357        static $_timeout_run = false;
    357358
     
    371372     * Redirect to record lock error page.
    372373     */
    373     function dieErrorPage()
     374    public function dieErrorPage()
    374375    {
    375376        $app =& App::getInstance();
     
    381382     * Print error page.
    382383     */
    383     function printErrorHTML()
     384    public function printErrorHTML()
    384385    {
    385386        $app =& App::getInstance();
     
    416417     * Return lock_id of locked record.
    417418     */
    418     function getID()
     419    public function getID()
    419420    {
    420421        return $this->data['lock_id'];
     
    424425     * Return title of locked record.
    425426     */
    426     function getTitle()
     427    public function getTitle()
    427428    {
    428429        return $this->data['title'];
     
    432433     * Return administrator username for locked record.
    433434     */
    434     function getEditor()
     435    public function getEditor()
    435436    {
    436437        return $this->data['editor'];
     
    440441     * Return total seconds since the record was locked.
    441442     */
    442     function getSecondsElapsed()
     443    public function getSecondsElapsed()
    443444    {
    444445        if (isset($this->data['lock_datetime']) && strtotime($this->data['lock_datetime']) < time()) {
     
    451452
    452453} // End of class.
    453 ?>
Note: See TracChangeset for help on using the changeset viewer.