From 7758c9eda5f3b39bfcf494f71ad958581f957939 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 17 Sep 2012 09:58:08 +0000
Subject: [PATCH] 1. Uwzględnienie w pliku UPGRADE skryptu test.php 2. Zmiana wersji bota na 2.5 w związku z poprzednimi poprawkami.

---
 class/BotSession.php |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/class/BotSession.php b/class/BotSession.php
index 20088e3..494f377 100644
--- a/class/BotSession.php
+++ b/class/BotSession.php
@@ -7,12 +7,12 @@
 	
 	/**
 	 * Nazwa modułu, którego zmienne klasa przetwarza
-	 * @var string max. 40 znak�w
+	 * @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,10 +21,14 @@
 		$this->user = sha1($user);
 		$this->user_struct = parse_url($user);
 		
-		$this->class = '';
+		$this->class_empty = FALSE;
 	}
 	
 	private function init() {
+		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".');
+		}
+		
 		if($this->PDO) {
 			return NULL;
 		}
@@ -33,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\'');
+			if($st->rowCount > 0) {
+				$row = $st->fetch(PDO::FETCH_ASSOC);
+				$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;
 		}
 		
@@ -54,9 +82,14 @@
 			);
 			
 			$files = glob(BOT_TOPDIR.'/db/*/'.$this->user_struct['user'].'.ggdb');
+			if(!$files) {
+				return;
+			}
 			
 			$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));
@@ -142,6 +175,10 @@
 		return $return;
 	}
 	
+	function setClass($class) {
+		$this->class = $class;
+	}
+	
 	function truncate() {
 		$this->init();
 		
@@ -149,4 +186,4 @@
 		$st->execute(array($this->class));
 	}
 }
-?>
+?>
\ No newline at end of file

--
Gitblit v1.9.1