Parcourir la source

added install link in table in ProjektyKosztyWstepnychRobot

Piotr Labudda il y a 10 ans
Parent
commit
6166ddec44
1 fichiers modifiés avec 103 ajouts et 1 suppressions
  1. 103 1
      SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

+ 103 - 1
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -135,7 +135,7 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 						values {$sqlValues}
 						values {$sqlValues}
 					");
 					");
 					DBG::_(true, true, "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
 					DBG::_(true, true, "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
-					$sth->execute();
+					//$sth->execute();
 					$dbFunction = $this->fetchZasobInfo();
 					$dbFunction = $this->fetchZasobInfo();
 				}
 				}
 				if (empty($dbFunction['url_params'])) {
 				if (empty($dbFunction['url_params'])) {
@@ -143,6 +143,68 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 				}
 				}
 			}
 			}
 		}
 		}
+		{// check links in tables
+			// $info['links']['IN7_MK_BAZA_DYSTRYBUCJI'] = $linkInfo;
+			if (empty($dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'])) throw new Exception("Brak poprawne wprowadzonej tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' w drzewie zasobów!");
+			$projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
+			/*
+				[link_action_id] =>
+				[db_id] => 36
+				[tbl_id] => 636
+				[cell_id] => 763
+				[param1_id] =>
+			*/
+			if (!$projInfo['link_action_id']) {
+				$sth = $pdo->prepare("
+					insert into CRM_LISTA_ZASOBOW (
+						TYPE,
+						PARENT_ID,
+						ALIAS_ID,
+						`DESC`,
+						A_RECORD_CREATE_AUTHOR,
+						A_RECORD_CREATE_DATE
+					)
+					values (
+						'URL_ACTION',
+						{$projInfo['tbl_id']},
+						{$dbFunction['action_id']},
+						'{$urlActionName}',
+						'system-by-{$usrLogin}',
+						NOW()
+					)
+				");
+				//DBG::_(true, true, "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
+				$sth->execute();
+				$dbFunction = $this->fetchZasobInfo();
+				$projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
+				if (!$projInfo['link_action_id']) throw new Exception("Brak zainstalowanej akcji dla tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' - nie udało się zainstalować");
+			}
+			if (!$projInfo['param1_id']) {// TODO: get from params
+				$sth = $pdo->prepare("
+					insert into CRM_LISTA_ZASOBOW (
+						TYPE,
+						PARENT_ID,
+						ALIAS_ID,
+						`DESC`,
+						A_RECORD_CREATE_AUTHOR,
+						A_RECORD_CREATE_DATE
+					)
+					values (
+						'PARAM_IN',
+						{$projInfo['link_action_id']},
+						{$projInfo['cell_id']},
+						'ID_PROJECT',
+						'system-by-{$usrLogin}',
+						NOW()
+					)
+				");
+				$sth->execute();
+				$dbFunction = $this->fetchZasobInfo();
+				$projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
+				if (!$projInfo['param1_id']) throw new Exception("Brak zainstalowanego parametru 1 w akcji dla tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' - nie udało się zainstalować");
+			}
+
+		}
 	}
 	}
 
 
 	public function fetchZasobInfo() {
 	public function fetchZasobInfo() {
@@ -169,6 +231,8 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 		$info = $sth->fetch();
 		$info = $sth->fetch();
 		if (!$info) return $info;
 		if (!$info) return $info;
 		$info['url_params'] = array();
 		$info['url_params'] = array();
+		$info['links'] = array();// where action is installed - expected `IN7_MK_BAZA_DYSTRYBUCJI`
+
 		if ($info['action_id'] > 0) {
 		if ($info['action_id'] > 0) {
 			$sthParams = $pdo->prepare("
 			$sthParams = $pdo->prepare("
 				select z.ID as param_id
 				select z.ID as param_id
@@ -187,6 +251,44 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 			}
 			}
 			$info['url_params'] = $urlParams;
 			$info['url_params'] = $urlParams;
 		}
 		}
+		{
+			$main_db_id = $pdo->getZasobId();
+			$sth_dbInfo = $pdo->prepare("
+				select za.id as link_action_id
+					, zd.id as db_id
+					, zt.id as tbl_id
+					, zi.id as cell_id
+					, zp1.id as param1_id -- for every param
+				from CRM_LISTA_ZASOBOW zt
+					join CRM_LISTA_ZASOBOW zd on(zd.ID = zt.PARENT_ID
+						and zd.TYPE in('DATABASE_MYSQL', 'BAZA_DANYCH', 'DATABASE_POSTGRESQL')
+						and zd.ID = {$main_db_id}
+					)
+					join CRM_LISTA_ZASOBOW zi on(zi.PARENT_ID = zt.ID
+						and zi.TYPE = 'KOMORKA'
+						and zi.DESC = 'ID'
+					)
+					left join CRM_LISTA_ZASOBOW za on(za.PARENT_ID = zt.ID
+						and za.TYPE = 'URL_ACTION'
+						and za.ALIAS_ID = {$info['action_id']}
+					)
+					-- TODO: for every param:
+					left join CRM_LISTA_ZASOBOW zp1 on(zp1.PARENT_ID = za.ID
+						and zp1.TYPE = 'PARAM_IN'
+						and zp1.ALIAS_ID = zi.id
+						and zp1.DESC = 'ID_PROJECT'
+					)
+				where zt.TYPE = 'TABELA'
+					and zt.A_STATUS not in('DELETED')
+					and zt.DESC = 'IN7_MK_BAZA_DYSTRYBUCJI'
+			");
+			DBG::_(true, true, "dbInfo query", $pdo->getRawSql($sth_dbInfo), __CLASS__, __FUNCTION__, __LINE__);
+			$sth_dbInfo->execute();
+			$linkInfo = $sth_dbInfo->fetch();
+			if ($linkInfo) {
+				$info['links']['IN7_MK_BAZA_DYSTRYBUCJI'] = $linkInfo;
+			}
+		}
 		return $info;
 		return $info;
 	}
 	}