<commit_before><?php

/**
 * This file contains the model for storing php session information
 * in the database
 *
 * PHP Version 5.3
 *
 * @category   Models
 * @package    Core
 * @subpackage Models
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

/**
 * Core Session Model
 *
 * @category   Models
 * @package    Core
 * @subpackage Models
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
class SessionModel extends Model
{

    /**
     * Constructor
     */
    public function __construct()
    {
        global $db;
        parent::__construct($db);
        $this->get_write_access();
    }

    /**
     * Destructor
     */
    public function __destruct()
    {
        parent::__destruct();
    }

    /**
     * Read session data from the database
     *
     * @param String $id Session ID
     *
     * @return mixed The Session Data on success, False on failure
     */
    public function read_session_data($id)
    {
        $this->db->select("sessionData");
        $this->db->where("sessionID", $id);
        $this->db->where("expires", time(), ">");
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            if ($query->num_rows() > 0)
            {
                return base64_decode($query->field("sessionData"));
            }
            else
            {
                return "";
            }
        }
        else
        {
            return FALSE;
        }
    }

    /**
     * Save session data into the database
     *
     * @param String  $id           Session ID
     * @param String  $session_data Session data
     * @param Integer $time         expiration timestamp
     *
     * @return void
     */
    public function write_session_data($id, $session_data, $time)
    {
        $this->db->begin_transaction();
        $this->db->select_for_update("*", FALSE);
        $this->db->where("sessionID", $id);
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            $data = array(
                        "sessionID" => $id,
                        "sessionData" => base64_encode($session_data),
                        "expires" => $time
                    );
            $this->db->replace("user_sessions", $data);
            $this->db->commit();
        }
        else
        {
            $this->db->rollback();
        }
        $this->db->end_transaction();
    }

    /**
     * Remove a no-longer active session
     *
     * @param String $id Session ID
     *
     * @return void
     */
    public function delete_session($id)
    {
        $this->db->begin_transaction();
        $this->db->select_for_update("*", FALSE);
        $this->db->where("sessionID", $id);
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            if ($query->num_rows() > 0)
            {
                $this->db->where("sessionID", $id);
                $this->db->delete("user_sessions");
                $this->db->commit();
            }
            else
            {
                $this->db->rollback();
            }
        }
        else
        {
            $this->db->rollback();
        }
        $this->db->end_transaction();
    }

    /**
     * Remove expired sessions
     *
     * @return void
     */
    public function session_gc()
    {
        $this->db->where("expires", time(), "<");
        $this->db->delete("user_sessions");
    }

}

?>
<commit_msg>system: Fix style for session model<commit_after><?php

/**
 * This file contains the model for storing php session information
 * in the database
 *
 * PHP Version 5.3
 *
 * @category   Models
 * @package    Core
 * @subpackage Models
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

/**
 * Core Session Model
 *
 * @category   Models
 * @package    Core
 * @subpackage Models
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
class SessionModel extends Model
{

    /**
     * Constructor.
     */
    public function __construct()
    {
        global $db;
        parent::__construct($db);
        $this->get_write_access();
    }

    /**
     * Destructor.
     */
    public function __destruct()
    {
        parent::__destruct();
    }

    /**
     * Read session data from the database.
     *
     * @param String $id Session ID
     *
     * @return mixed The Session Data on success, False on failure
     */
    public function read_session_data($id)
    {
        $this->db->select("sessionData");
        $this->db->where("sessionID", $id);
        $this->db->where("expires", time(), ">");
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            if ($query->num_rows() > 0)
            {
                return base64_decode($query->field("sessionData"));
            }
            else
            {
                return "";
            }
        }
        else
        {
            return FALSE;
        }
    }

    /**
     * Save session data into the database.
     *
     * @param String  $id           Session ID
     * @param String  $session_data Session data
     * @param Integer $time         expiration timestamp
     *
     * @return void
     */
    public function write_session_data($id, $session_data, $time)
    {
        $this->db->begin_transaction();
        $this->db->select_for_update("*", FALSE);
        $this->db->where("sessionID", $id);
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            $data = array(
                        "sessionID" => $id,
                        "sessionData" => base64_encode($session_data),
                        "expires" => $time
                    );
            $this->db->replace("user_sessions", $data);
            $this->db->commit();
        }
        else
        {
            $this->db->rollback();
        }
        $this->db->end_transaction();
    }

    /**
     * Remove a no-longer active session.
     *
     * @param String $id Session ID
     *
     * @return void
     */
    public function delete_session($id)
    {
        $this->db->begin_transaction();
        $this->db->select_for_update("*", FALSE);
        $this->db->where("sessionID", $id);
        $query = $this->db->get("user_sessions");
        if ($query)
        {
            if ($query->num_rows() > 0)
            {
                $this->db->where("sessionID", $id);
                $this->db->delete("user_sessions");
                $this->db->commit();
            }
            else
            {
                $this->db->rollback();
            }
        }
        else
        {
            $this->db->rollback();
        }
        $this->db->end_transaction();
    }

    /**
     * Remove expired sessions.
     *
     * @return void
     */
    public function session_gc()
    {
        $this->db->where("expires", time(), "<");
        $this->db->delete("user_sessions");
    }

}

?>

{'fraction_non_alphanumeric': 0.15179856115107915, 'fraction_numerical': 0.0028776978417266188, 'mean_word_length': 1.4825, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991619', 'n_tokens_mistral': 2065, 'n_tokens_neox': 2004, 'n_words': 409}