Просмотр исходного кода

DB_PROCEDURES_CREATE add Route Config

Piotr Labudda 10 лет назад
Родитель
Сommit
c21556b068
2 измененных файлов с 70 добавлено и 0 удалено
  1. 67 0
      SE/se-lib/Route/Config.php
  2. 3 0
      SE/superedit-DB_PROCEDURES_CREATE.php

+ 67 - 0
SE/se-lib/Route/Config.php

@@ -0,0 +1,67 @@
+<?php
+
+Lib::loadClass('RouteBase');
+
+class Route_Config extends RouteBase {
+
+	public function handleAuth() {
+		if (!User::logged()) {
+			throw new HttpException('Unauthorized', 401);
+		}
+	}
+
+	public function defaultAction() {
+		SE_Layout::gora();
+		?>
+<div class="container">
+	<h1>Config</h1>
+	...
+</div>
+		<?php
+		SE_Layout::dol();
+	}
+
+	public function reinstallAction() {
+		$this->reinstall();
+		die('OK');
+	}
+
+	public function runAction() {
+		$msgId = V::get('_msgId', 0, $_REQUEST, 'int');
+		if ($msgId > 0) {
+			$this->runByMessageId($msgId);
+		}
+		$jsonData = new stdClass();
+		$jsonData->type = 'success';
+		$jsonData->msg = 'Gotowe';
+		echo json_encode($jsonData);
+		exit;
+	}
+
+	public function reinstall() {
+		$sqlList = array();
+		//$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";
+		$sqlList['InstallTable'] = <<<SQL
+
+CREATE TABLE IF NOT EXISTS `CRM_CONFIG` (
+	`ID` int(11) NOT NULL AUTO_INCREMENT,
+	`CONF_KEY` varchar(64) NOT NULL,
+	`CONF_VAL` text NOT NULL,
+	PRIMARY KEY (`ID`),
+	UNIQUE KEY `CONF_KEY` (`CONF_KEY`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
+
+SQL;
+		$db = DB::getDB();
+		if ($db->has_errors()) {
+			throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+		}
+		foreach ($sqlList as $sqlName => $sql) {
+			$res = $db->query($sql);
+			if ($db->has_errors()) {
+				throw new Exception("DB Errors at sql '{$sqlName}': " . implode("\n<br>", $db->get_errors()));
+			}
+		}
+	}
+
+}

+ 3 - 0
SE/superedit-DB_PROCEDURES_CREATE.php

@@ -1013,6 +1013,9 @@ foreach($sql as $ind=>$sql_) {
 
 	Lib::loadClass('Router');
 
+	$routeConfig = Router::getRoute('Config');
+	$routeConfig->reinstall();
+
 	$routeMsgs = Router::getRoute('Msgs');
 	$routeMsgs->reinstall();