dereuromark 15 年 前
コミット
8e348a620a
4 ファイル変更184 行追加0 行削除
  1. 12 0
      config/sql/code_key.sql
  2. 7 0
      config/sql/session.sql
  3. 12 0
      config/usage/session.txt
  4. 153 0
      vendors/shells/tools.php

+ 12 - 0
config/sql/code_key.sql

@@ -0,0 +1,12 @@
+-- code_keys
+CREATE TABLE IF NOT EXISTS `{prefix}code_keys` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `user_id` char(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+  `type` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'e.g.:activate,reactivate',
+  `key` varchar(60) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+  `content` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'can transport some information',
+  `used` tinyint(1) unsigned NOT NULL DEFAULT '0',
+  `created` datetime NOT NULL,
+  `modified` datetime NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

+ 7 - 0
config/sql/session.sql

@@ -0,0 +1,7 @@
+-- cake_sessions
+CREATE TABLE IF NOT EXISTS `{prefix}cake_sessions` (
+  `id` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+  `data` text COLLATE utf8_unicode_ci,
+  `expires` int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

+ 12 - 0
config/usage/session.txt

@@ -0,0 +1,12 @@
+to enable session handling via database:
+
+*** /config/core.php
+
+Configure::write('Session.save', 'database');
+
+Configure::write('Session.model', 'Tools.Session');
+
+
+*** console:
+
+run "cake tools install Session"

+ 153 - 0
vendors/shells/tools.php

@@ -0,0 +1,153 @@
+<?php
+
+/**
+ * Install Tools
+ * 2010-06-05 ms
+ */
+class ToolsShell extends Shell {
+	var $uses = array();
+	var $tasks = array('DbConfig');
+
+	private $files = array();
+	private $folder = null;
+
+	private $models = array('Configuration', 'User', 'Role');
+	private $Db;
+
+	function startup() {
+		Configure::write('debug', 2);
+
+		foreach ($this->models as $m) {
+			$imported = App::import('Model', $m);
+			if ($imported === true) {
+				$modelname = $m;
+				break;
+			}
+		}
+		if (empty($modelname)) {
+			$this->error('At least one of the following DB-Tables are required:', implode(', ', $this->models));
+		}
+		$this->Db = ClassRegistry::init($modelname); //old: new Model();
+	}
+
+
+	function main() {
+    $this->out('Install/Manage Tools');
+		$this->out('');
+		$this->out('Usage:');
+		$this->out('- cake install Tool {params}');
+		$this->out('- cake uninstall Tool {params}');
+
+		$this->out('');
+		$this->out('Tools:');
+    $this->_getFiles();
+    foreach ($this->files as $file) {
+			$this->out('- '.Inflector::camelize(extractPathInfo('file', $file)));
+		}
+		$this->out('');
+		$this->out('Params:');
+		$this->out('-f => Force Reinstall (Drop + Create)');
+		$this->out('-s => Status (TODO!)');
+	}
+
+
+	function install() {
+		if (empty($this->args)) {
+			return $this->main();
+		}
+		$args = $this->args;
+
+		if (!empty($args[0]) && $args[0] == 'all') {
+   		$this->_getFiles();
+			$args = $this->files;
+		}
+		if (!empty($this->params['f'])) {
+			$this->args = $args;
+			$this->uninstall();
+		}
+
+		foreach ($args as $arg) {
+
+			if ($sql = $this->_getFile($arg)) {
+				$sql = String::insert($sql, array('prefix'=>$this->Db->tablePrefix), array('before'=>'{', 'after'=>'}', 'clean'=>true));
+				$this->Db->query($sql);
+				$this->out('OK: '.$arg.' created');
+			} else {
+				$this->out($arg.' not found');
+			}
+		}
+
+		$this->out('... done');
+	}
+
+	function uninstall() {
+		if (empty($this->args)) {
+			return $this->main();
+		}
+
+		$args = $this->args;
+
+		if (!empty($args[0]) && $args[0] == 'all') {
+			$this->_getFiles();
+			$args = $this->files;
+		}
+
+		foreach ($args as $arg) {
+			if ($sql = $this->_getFile($arg)) {
+				$sqlParts = explode(NL, $sql, 2);
+				if (mb_strpos($sqlParts[0], '-- ') !== 0) {
+					$this->out('Error: '.$arg);
+					continue;
+				}
+				$sql = trim(mb_substr($sqlParts[0], 3));
+				if (!empty($sql)) {
+					//$this->Db->execute('DROP TABLE IF EXISTS `'.$this->Db->tablePrefix.$sql.'`;');
+					//$this->_ensureDatabaseConnection();
+					$this->Db->query('DROP TABLE IF EXISTS `'.$this->Db->tablePrefix.$sql.'`;');
+					$this->out('OK: '.$arg.' dropped');
+					//die('drop: '.$sql);
+				} else {
+					$this->out('Error: '.$sql);
+				}
+
+			} else {
+				$this->out($arg.' not found');
+			}
+		}
+
+		$this->out('... done');
+	}
+
+	/*
+	function _ensureDatabaseConnection() {
+		if (empty($this->connection)) {
+			$this->connection = $this->DbConfig->getConfig();
+		}
+		$this->Db =& ConnectionManager::getDataSource($this->connection);
+	}
+	*/
+
+
+	function _getFiles() {
+		App::import('Core', 'Folder');
+		//TODO: make it more generic (could be somewhere else too...)
+		$this->folder = APP.'plugins'.DS.'tools'.DS.'config'.DS.'sql'.DS;
+
+		$handle = new Folder($this->folder);
+		$content = $handle->read(true, true);
+		$this->files = $content[1];
+	}
+
+	function _getFile($file) {
+		if (empty($this->files)) {
+			$this->_getFiles();
+		}
+		$file = Inflector::underscore($file).'.sql';
+		if (file_exists($this->folder.$file)) {
+			return file_get_contents($this->folder.$file);
+		}
+		return false;
+	}
+
+}
+?>