Ver código fonte

add basic Route system; test version of FixProjectPath

Piotr Labudda 11 anos atrás
pai
commit
2e4c68b8fe
4 arquivos alterados com 141 adições e 1 exclusões
  1. 5 1
      SE/index.php
  2. 85 0
      SE/se-lib/Route/FixProjectPath.php
  3. 24 0
      SE/se-lib/RouteBase.php
  4. 27 0
      SE/se-lib/Router.php

+ 5 - 1
SE/index.php

@@ -38,16 +38,20 @@ Lib::loadClass('SE_Layout');
 Lib::loadClass('S');
 Lib::loadClass('Http');
 Lib::loadClass('HttpException');
+Lib::loadClass('Router');
 
 S::init();// init session variables if not exists
 User::auth();// die if not logged in
 
 S::timeoutUpdate(true);// User is authorized - update logout time
 
+$route = V::get('_route', '', $_REQUEST);
+Router::route($route);
+
 //STD INCLUDE 2010-01-14
 require APP_PATH_ROOT . "/superedit-logistyka.php";
 
-// register globals
+// register globals - legacy
 $MENU_INIT = isset($_REQUEST['MENU_INIT'])? $_REQUEST['MENU_INIT'] : null;
 $ARG1 = isset($_REQUEST['ARG1'])? $_REQUEST['ARG1'] : null;
 $ARG1_VAL = isset($_REQUEST['ARG1_VAL'])? $_REQUEST['ARG1_VAL'] : null;

+ 85 - 0
SE/se-lib/Route/FixProjectPath.php

@@ -0,0 +1,85 @@
+<?php
+
+Lib::loadClass('RouteBase');
+
+class Route_FixProjectPath extends RouteBase {
+
+	public function defaultAction() {
+		echo 'TODO: F.' . __FUNCTION__;
+		//$sqlList['Check'] = "SHOW PROCEDURE STATUS where `Name`='update_project_path_idx_rec'";
+	}
+
+	public function runAction() {
+		$sql = "call `update_project_path_idx_rec`();";
+		// TODO: update fields:
+		//   `IN7_MK_BAZA_DYSTRYBUCJI`.`path`
+		//   `IN7_DZIENNIK_KORESP`.`path`
+		//   `PROBLEMS`.`ID_PROJECT_path`
+		$db = DB::getDB();
+		if ($db->has_errors()) {
+			throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+		}
+		$res = $db->query($sql);
+		if ($db->has_errors()) {
+			throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+		}
+		die('OK');
+	}
+
+	public function reinstallAction() {
+		// TODO: reinstall triggers for after insert/update `IN7_MK_BAZA_DYSTRYBUCJI`?
+		// TODO: reinstall triggers for after insert/update `IN7_DZIENNIK_KORESP` and `PROBLEMS`?
+		$sqlList = array();
+		$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `_project_path_idx`";
+		$sqlList['InstallTable'] = "
+			CREATE TABLE IF NOT EXISTS `_project_path_idx` (
+				`ID` int(11) NOT NULL
+				, `P_ID` int(11) NOT NULL DEFAULT '0'
+				, `idx_PATH` varchar(255) NOT NULL DEFAULT ''
+				, KEY `ID` (`ID`)
+				, KEY `P_ID` (`P_ID`)
+			) ENGINE=MyISAM DEFAULT CHARSET=latin2
+		";
+		$sqlList['Remove'] = "DROP PROCEDURE if exists `update_project_path_idx_rec`";
+		$sqlList['Create'] = "
+			CREATE PROCEDURE `update_project_path_idx_rec`()
+			BEGIN
+				SET @conf_last_exec_key = 'tbl_indexer_project_last_exec';
+				replace into `CRM_CONFIG` (`conf_key`, `conf_val`) values (@conf_last_exec_key, NOW());
+
+				truncate table `_project_path_idx`;
+				-- delete from `_project_path_idx`;
+
+				insert into `_project_path_idx` (`ID`,`P_ID`)
+					select p.`ID`, p.`P_ID`
+					from `IN7_MK_BAZA_DYSTRYBUCJI` p
+					where 1=1
+				;
+
+				update `_project_path_idx` as p set p.`idx_PATH`=concat('0-', p.`ID`) where p.`P_ID` is null or p.`P_ID`=0;
+				SET @i = 0;
+				SET @loopLomit = 100;
+				SET @pinitCnt = 1;
+				WHILE @i < @loopLomit and @pinitCnt > 0 DO
+					update `_project_path_idx` p join `_project_path_idx` pp on(pp.`ID`=p.`P_ID`)
+						set p.`idx_PATH`=concat(pp.`idx_PATH`, '-', p.`ID`)
+						where p.`idx_PATH`='' and pp.`idx_PATH`!='';
+					SET @pinitCnt = ROW_COUNT();
+					SET @i = @i + 1;
+				END WHILE;
+			END ;
+		";
+		$db = DB::getDB();
+		if ($db->has_errors()) {
+			throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+		}
+		foreach ($sqlList as $sql) {
+			$res = $db->query($sql);
+			if ($db->has_errors()) {
+				throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+			}
+		}
+		die('OK');
+	}
+
+}

+ 24 - 0
SE/se-lib/RouteBase.php

@@ -0,0 +1,24 @@
+<?php
+
+class RouteBase {
+
+	public function route() {
+		$task = V::get('_task', '', $_REQUEST);
+		if (empty($task)) {
+			$this->defaultAction();
+			return;
+		}
+
+		$methodName = "{$task}Action";
+		if (method_exists($this, $methodName)) {
+			$this->{$methodName}();
+		} else {
+			die("Task '{$task}' not exists");
+		}
+	}
+
+	public function defaultAction() {
+		die("default task not implemented");
+	}
+
+}

+ 27 - 0
SE/se-lib/Router.php

@@ -0,0 +1,27 @@
+<?php
+
+Lib::loadClass('HttpException');
+
+class Router {
+
+	public static function route($route) {
+		if (empty($route)) return;
+
+		$routeClassName = "Route_{$route}";
+		if (Lib::tryLoadClass($routeClassName)) {
+			$route = new $routeClassName();
+			try {
+				$route->route();
+			} catch (HttpException $e) {
+				Http::sendHeaderByCode($e->getCode());
+				die($e->getMessage());
+			} catch (Exception $e) {
+				die($e->getMessage());
+			}
+			exit;
+		} else {
+			die("Route '{$route}' not exists");
+		}
+	}
+
+}