From 6e7958d91fcb949ac27e3fc6d1b67833e013f725 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 29 Jun 2013 16:21:31 +0000
Subject: [PATCH] Poprawka pobierania wyników Multi Multi z 21:40

---
 class/BotSession.php |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/class/BotSession.php b/class/BotSession.php
index e8b8930..36cd174 100644
--- a/class/BotSession.php
+++ b/class/BotSession.php
@@ -9,10 +9,10 @@
 	 * Nazwa modułu, którego zmienne klasa przetwarza
 	 * @var string max. 40 znaków
 	 */
-	var $class;
+	protected $class = '';
+	protected $class_empty = TRUE;
 	
 	private $user;
-	
 	
 	/**
 	 * Inicjuje klasę w zależności od użytkownika
@@ -21,11 +21,11 @@
 		$this->user = sha1($user);
 		$this->user_struct = parse_url($user);
 		
-		$this->class = '';
+		$this->class_empty = FALSE;
 	}
 	
 	private function init() {
-		if(strlen($this->class) == 0) {
+		if(strlen($this->class) == 0 && !$this->class_empty) {
 			throw new Exception('Przed użyciem $msg->session należy ustawić nazwę modułu za pomocą metody setClass - patrz "Poradnik tworzenia modułów", dział "Klasa BotMessage", rozdział "Pole $session".');
 		}
 		
@@ -37,6 +37,30 @@
 			$this->PDO = new PDO('sqlite:'.BOT_TOPDIR.'/database/'.sha1($this->user).'.sqlite');
 			$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 			$this->PDO->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
+			
+			$st = $this->PDO->query('SELECT value FROM data WHERE class=\'\' AND name=\'_version\'');
+			$row = $st->fetch(PDO::FETCH_ASSOC);
+			if(is_array($row)) {
+				$version = (int)$row['value'];
+			}
+			else
+			{
+				$version = 0;
+			}
+			$st->closeCursor();
+			
+			if($version < 1) {
+				$this->PDO->query('UPDATE data SET class=\'kino\' WHERE class=\'\' AND name=\'kino\'');
+				$this->PDO->query('INSERT OR REPLACE INTO data (class, name, value) VALUES (\'\', \'_version\', 1)');
+				$version = 1;
+			}
+			
+			if($version < 3) {
+				$this->PDO->query('DELETE FROM data WHERE class IS NULL AND name=\'user_struct\'');
+				$this->PDO->query('INSERT OR REPLACE INTO data (class, name, value) VALUES (\'\', \'_version\', 3)');
+				$version = 3;
+			}
+			
 			return;
 		}
 		
@@ -65,6 +89,8 @@
 			$this->PDO->beginTransaction();
 			$st = $this->PDO->prepare('INSERT OR REPLACE INTO data (class, name, value) VALUES (?, ?, ?)');
 			
+			$st->execute(array('', '_version', 2));
+			
 			foreach($files as $file) {
 				$data = unserialize(file_get_contents($file));
 				foreach($data as $name => $value) {

--
Gitblit v1.9.1