<commit_before><?php
/**
 * MINZ - Copyright 2011 <NAME>
 * Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/

/**
 * La classe Model_sql représente le modèle interragissant avec les bases de données
 * Seul la connexion MySQL est prise en charge pour le moment
 */
class Minz_ModelPdo {

	/**
	 * Partage la connexion à la base de données entre toutes les instances.
	 */
	public static $useSharedBd = true;
	private static $sharedBd = null;
	private static $sharedPrefix;
	private static $has_transaction = false;
	protected static $sharedDbType;

	/**
	 * $bd variable représentant la base de données
	 */
	protected $bd;

	protected $prefix;

	public function dbType() {
		return self::$sharedDbType;
	}

	/**
	 * Créé la connexion à la base de données à l'aide des variables
	 * HOST, BASE, USER et PASS définies dans le fichier de configuration
	 */
	public function __construct($currentUser = null) {
		if (self::$useSharedBd && self::$sharedBd != null && $currentUser === null) {
			$this->bd = self::$sharedBd;
			$this->prefix = self::$sharedPrefix;
			return;
		}

		$db = Minz_Configuration::dataBase();

		if ($currentUser === null) {
			$currentUser = Minz_Session::param('currentUser', '_');
		}

		try {
			$type = $db['type'];
			if ($type === 'mysql') {
				$string = 'mysql:host=' . $db['host']
				        . ';dbname=' . $db['base']
				        . ';charset=utf8';
				$driver_options = array(
					PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
				);
				$this->prefix = $db['prefix'] . $currentUser . '_';
			} elseif ($type === 'sqlite') {
				$string = 'sqlite:' . DATA_PATH . '/' . $currentUser . '.sqlite';
				$driver_options = array(
					//PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				);
				$this->prefix = '';
			} else {
				throw new Minz_PDOConnectionException(
					'Invalid database type!',
					$db['user'], Minz_Exception::ERROR
				);
			}
			self::$sharedDbType = $type;
			self::$sharedPrefix = $this->prefix;

			$this->bd = new MinzPDO(
				$string,
				$db['user'],
				$db['password'],
				$driver_options
			);
			if ($type === 'sqlite') {
				$this->bd->exec('PRAGMA foreign_keys = ON;');
			}
			self::$sharedBd = $this->bd;
		} catch (Exception $e) {
			throw new Minz_PDOConnectionException(
				$string,
				$db['user'], Minz_Exception::ERROR
			);
		}
	}

	public function beginTransaction() {
		$this->bd->beginTransaction();
		$this->has_transaction = true;
	}
	public function hasTransaction() {
		return $this->has_transaction;
	}
	public function commit() {
		$this->bd->commit();
		$this->has_transaction = false;
	}
	public function rollBack() {
		$this->bd->rollBack();
		$this->has_transaction = false;
	}

	public static function clean() {
		self::$sharedBd = null;
		self::$sharedPrefix = '';
	}
}

class MinzPDO extends PDO {
	private static function check($statement) {
		if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) {
			invalidateHttpCache();
		}
	}
<commit_msg>Fix  a bug (has_transaction)<commit_after><?php
/**
 * MINZ - Copyright 2011 <NAME>
 * Sous licence AGPL3 <http://www.gnu.org/licenses/>
*/

/**
 * La classe Model_sql représente le modèle interragissant avec les bases de données
 * Seul la connexion MySQL est prise en charge pour le moment
 */
class Minz_ModelPdo {

	/**
	 * Partage la connexion à la base de données entre toutes les instances.
	 */
	public static $useSharedBd = true;
	private static $sharedBd = null;
	private static $sharedPrefix;
	private static $has_transaction = false;
	protected static $sharedDbType;

	/**
	 * $bd variable représentant la base de données
	 */
	protected $bd;

	protected $prefix;

	public function dbType() {
		return self::$sharedDbType;
	}

	/**
	 * Créé la connexion à la base de données à l'aide des variables
	 * HOST, BASE, USER et PASS définies dans le fichier de configuration
	 */
	public function __construct($currentUser = null) {
		if (self::$useSharedBd && self::$sharedBd != null && $currentUser === null) {
			$this->bd = self::$sharedBd;
			$this->prefix = self::$sharedPrefix;
			return;
		}

		$db = Minz_Configuration::dataBase();

		if ($currentUser === null) {
			$currentUser = Minz_Session::param('currentUser', '_');
		}

		try {
			$type = $db['type'];
			if ($type === 'mysql') {
				$string = 'mysql:host=' . $db['host']
				        . ';dbname=' . $db['base']
				        . ';charset=utf8';
				$driver_options = array(
					PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
				);
				$this->prefix = $db['prefix'] . $currentUser . '_';
			} elseif ($type === 'sqlite') {
				$string = 'sqlite:' . DATA_PATH . '/' . $currentUser . '.sqlite';
				$driver_options = array(
					//PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
				);
				$this->prefix = '';
			} else {
				throw new Minz_PDOConnectionException(
					'Invalid database type!',
					$db['user'], Minz_Exception::ERROR
				);
			}
			self::$sharedDbType = $type;
			self::$sharedPrefix = $this->prefix;

			$this->bd = new MinzPDO(
				$string,
				$db['user'],
				$db['password'],
				$driver_options
			);
			if ($type === 'sqlite') {
				$this->bd->exec('PRAGMA foreign_keys = ON;');
			}
			self::$sharedBd = $this->bd;
		} catch (Exception $e) {
			throw new Minz_PDOConnectionException(
				$string,
				$db['user'], Minz_Exception::ERROR
			);
		}
	}

	public function beginTransaction() {
		$this->bd->beginTransaction();
		self::$has_transaction = true;
	}
	public function hasTransaction() {
		return self::$has_transaction;
	}
	public function commit() {
		$this->bd->commit();
		self::$has_transaction = false;
	}
	public function rollBack() {
		$this->bd->rollBack();
		self::$has_transaction = false;
	}

	public static function clean() {
		self::$sharedBd = null;
		self::$sharedPrefix = '';
	}
}

class MinzPDO extends PDO {
	private static function check($statement) {
		if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) {
			invalidateHttpCache();
		}
	}

{'fraction_non_alphanumeric': 0.1624176937362823, 'fraction_numerical': 0.002363667060611177, 'mean_word_length': 3.42419716206124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6472424', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2017, 'n_words': 479}