<commit_before><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2011 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                            *
********************************************************************************************************/

/**
 * The lockmanager takes care of locking and unlocking systemrecords.
 * It provides the methods to check if a record is locked or not.
 *
 * @package modul_system
 * @author <EMAIL>
 * @since 3.3.0
 */
class class_lockmanager  {

    /**
     *
     * @var class_modul_system_common
     */
    private $objSystemCommon;

    private $strSystemid = "";

	/**
	 * Contructor
	 */
	public function __construct($strSystemid = "") {
        $this->objSystemCommon = new class_modul_system_common($strSystemid);
        $this->strSystemid = $strSystemid;

        $this->unlockOldRecords();
	}

    /**
	 * Locks a systemrecord for the current user
	 *
	 * @return bool
	 */
    public function lockRecord() {
		$strQuery = "UPDATE "._dbprefix_."system
						SET system_lock_id=?,
						    system_lock_time = ?
						WHERE system_id =?";

		if(class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array(class_carrier::getInstance()->getObjSession()->getUserID(), time(), $this->strSystemid ))) {
            class_carrier::getInstance()->getObjDB()->flushQueryCache();
            return true;
        }

        return false;
    }

    /**
     * Checks if the current record is locked, ignoring the locking user-id.
     *
     * @return bool
     */
    public function isLocked() {
        return $this->getLockId() != "0";
    }

    /**
	 * Unlocks a dataRecord as long as the record is locked by the current one
	 *
     * @param bool $bitForceUnlock unlocks the record, even if the user is not the owner of the lock. must be an admin therefore!
	 * @return bool
	 */
	public function unlockRecord($bitForceUnlock = false)	{
        if($this->isLockedByCurrentUser() ||
            ($bitForceUnlock && class_carrier::getInstance()->getObjRights()->userIsAdmin(class_carrier::getInstance()->getObjSession()->getUserID()) )) {
            
            
            $strQuery = "UPDATE "._dbprefix_."system
                            SET system_lock_id='0'
                            WHERE system_id=? ";
            if(class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array($this->strSystemid))) {
                class_carrier::getInstance()->getObjDB()->flushQueryCache();
                return true;
            }
        }

        return false;
	}

    /**
     * Checks if the record is locked for the current user and so not accessible.
     * If the record is locked by someone else, false will be returned, true otherwise.
     *
     * @return bool
     */
    public function isAccessibleForCurrentUser() {
        $strLockId = $this->getLockId();
        if(validateSystemid($strLockId)) {<commit_msg>BUG: lockmanager missed to unlock records in rare cases<commit_after><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2011 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                            *
********************************************************************************************************/

/**
 * The lockmanager takes care of locking and unlocking systemrecords.
 * It provides the methods to check if a record is locked or not.
 *
 * @package modul_system
 * @author <EMAIL>
 * @since 3.3.0
 */
class class_lockmanager  {

    /**
     *
     * @var class_modul_system_common
     */
    private $objSystemCommon;

    private $strSystemid = "";

	/**
	 * Contructor
	 */
	public function __construct($strSystemid = "") {
        $this->objSystemCommon = new class_modul_system_common($strSystemid);
        $this->strSystemid = $strSystemid;

        $this->unlockOldRecords();
	}

    /**
	 * Locks a systemrecord for the current user
	 *
	 * @return bool
	 */
    public function lockRecord() {
		$strQuery = "UPDATE "._dbprefix_."system
						SET system_lock_id=?,
						    system_lock_time = ?
						WHERE system_id =?";

		if(class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array(class_carrier::getInstance()->getObjSession()->getUserID(), time(), $this->strSystemid ))) {
            class_carrier::getInstance()->getObjDB()->flushQueryCache();
            $this->objSystemCommon = new class_modul_system_common($this->strSystemid);
            return true;
        }

        return false;
    }

    /**
     * Checks if the current record is locked, ignoring the locking user-id.
     *
     * @return bool
     */
    public function isLocked() {
        return $this->getLockId() != "0";
    }

    /**
	 * Unlocks a dataRecord as long as the record is locked by the current one
	 *
     * @param bool $bitForceUnlock unlocks the record, even if the user is not the owner of the lock. must be an admin therefore!
	 * @return bool
	 */
	public function unlockRecord($bitForceUnlock = false)	{
        if($this->isLockedByCurrentUser() ||
            ($bitForceUnlock && class_carrier::getInstance()->getObjRights()->userIsAdmin(class_carrier::getInstance()->getObjSession()->getUserID()) )) {
            
            
            $strQuery = "UPDATE "._dbprefix_."system
                            SET system_lock_id='0'
                            WHERE system_id=? ";
            if(class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array($this->strSystemid))) {
                class_carrier::getInstance()->getObjDB()->flushQueryCache();
                $this->objSystemCommon = new class_modul_system_common($this->strSystemid);
                return true;
            }
        }

        return false;
	}

    /**
     * Checks if the record is locked for the current user and so not accessible.
     * If the record is locked by someone else, false will be returned, true otherwise.
     *
     * @return bool
     */
    public function isAccessibleForCurrentUser() {
        $strLockId = $this->getLockId();
        if(validateSystemid($strLockId)) {
{'fraction_non_alphanumeric': 0.19644919168591224, 'fraction_numerical': 0.0066397228637413395, 'mean_word_length': 2.05916114790287, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4320348', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1712, 'n_words': 432}