Location: PHPKode > projects > Content*Builder > contentbuilder/lib/CB_update.class.php
<?php

/**
 * Klasse zum Updaten von Modultabellen
 * 
 * @package CB Update Management
 * @access public 
 * @author Jörg Stöber <hide@address.com> 
 * @version 0.1 ($Id: CB_update.class.php,v 1.1 2004/03/29 22:45:31 cb_fog Exp $)
 */

class CB_update {
	var $table   = array();
	var $updates = array();

	function CB_update($pluginLocation) {
		$this->updateDir = $pluginLocation."/updates";
		$this->pluginDir = "plugins";
		$this->setupLocation = $pluginLocation;
	}

	function checkModule($pluginLocation) {
		if(is_dir($this->pluginDir."/".$pluginLocation)) {
			unset($update);
			unset($updateKey);
			include($this->pluginDir."/".$pluginLocation."/plugin.config");
			$this->updateKey   = $updateKey;
			$this->moduleName  = $config['menuEntry'];
			$this->moduleGroup = $config['menuGroup'];
			
			if(is_array($update)) {
				foreach($update as $k => $v) {
					$tableInfo = mysql_fetch_object(mysql_query("SHOW TABLE STATUS LIKE '$v'"));
					$this->table[$v] = $tableInfo->Comment;
				}
			}
		}
	}
	
	function addUpdate($params) {
		if(is_array($params)) {
			$this->updates[$params[table]][$params[fromVer]][$params[toVer]] = $params[query];
			$this->prepend[$params[table]][$params[fromVer]][$params[toVer]] = $params[prepend];
			$status = 1;
		} else { 
			$status = 0; 
		}
		return $status;
	}
	
	function performUpdate($table, $from, $to) {
		$updateQuery = $this->updates[$table][$from][$to];
		$prependToDo = $this->prepend[$table][$from][$to];
		if($prependToDo == true) {
			$updateQuery = $this->performPrepend($table, $from, $to);
		}
		if(!is_array($updateQuery)) {
			if(!empty($updateQuery)) {
				$query = mysql_query($updateQuery);
				if($query) {
					$result[] = 1;
				} else {
					$result[] = 0;
				}
			}
		} else {
			foreach($updateQuery as $k => $v) {
				if(!empty($v)) {
					$query = mysql_query($v);
					if($query) {
						$result[] = 1;
					} else {
						$result[] = 0;
					}
				}
			}
		}
		return $result;
	}
	
	function performPrepend($table, $from, $to) {
		$cbPrepend = new CB_prepend($this->setupLocation, $this->updateKey);
		$cbPrepend->setValues($table, $from, $to);
		if(!empty($this->updateKey) && file_exists($this->updateDir."/".$this->updateKey."_prepend.php")) {
			include_once($this->updateDir."/".$this->updateKey."_prepend.php");
		}
		$query = $cbPrepend->getQuery();
		return $query;
	}
	
	function refreshTableVersion($table) {
		$tableInfo = mysql_fetch_object(mysql_query("SHOW TABLE STATUS LIKE '$table'"));
		$this->table[$table] = $tableInfo->Comment;
	}
	
	function listUpdates() {
		return $this->updates;
	}
	
	function getUpdateKey() {
		return $this->updateKey;
	}
	
	function getTableVersion($table) {
		return $this->table[$table];
	}
	
	function getModuleName() {
		return $this->moduleName;
	}
	
	function getModuleGroup() {
		return $this->moduleGroup;
	}
}

class CB_prepend {
	
	function CB_prepend($pluginLocation, $updateKey) {
		$this->updateKey = $updateKey;
		$this->updateDir = $pluginLocation."/updates";
		$this->pluginDir = "plugins";
	}
	
	function setValues($table, $from, $to) {
		$this->table = $table;
		$this->from  = $from;
		$this->to    = $to;
	}
	
	function checkValues($params) {
		if(is_array($params)) {
			if(($params[0] == $this->table) && ($params[1] == $this->from) && ($params[2] == $this->to)) {
				$result = 1;
			} else {
				$result = 0;
			}
		} else {
			$result = 0;
		}
		return $result;
	}
	
	function setQuery($query) {
		$this->query = $query;
	}
	
	function getQuery() { return $this->query; }
	function getTable() { return $this->table; }
	function getFrom()  { return $this->from; }
	function getTo()    { return $this->to; }
}
?>
Return current item: Content*Builder