Bläddra i källkod

added debug flat config in Url Action

Piotr Labudda 10 år sedan
förälder
incheckning
2bf51a684d
1 ändrade filer med 95 tillägg och 18 borttagningar
  1. 95 18
      SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

+ 95 - 18
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -43,6 +43,23 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 	}
 
 	public function reinstall() {// TODO: mv to UrlActionBase
+		/* required Zasoby tree structure - XML (parent rel in PARENT_ID field):
+<zasob:tree>
+	<zasob:TYPESPECIALS>
+		<zasob:URL_ACTION zasob:key=":action_id" zasob:desc=":url_action_name">
+			<zasob:PARAM_IN zasob:key=":action_param_1_id" zasob:desc=":url_action_param_1_name"/>
+		</zasob:URL_ACTION>
+	</zasob:TYPESPECIALS>
+	<zasob:BAZA_DANYCH zasob:key=":main_db_id" altername_types="DATABASE_MYSQL,DATABASE_POSTGRESQL">
+		<zasob:TABELA zasob:key=":tbl_id" zasob:desc="IN7_MK_BAZA_DYSTRYBUCJI">
+			<zasob:KOMORKA zasob:key=":cell_id" zasob:desc="ID"/>
+			<zasob:URL_ACTION zasob:key=":link_action_id" zasob:desc=":url_action_name" zasob:alias_id=":action_id">
+				<zasob:PARAM_IN zasob:key=":cell_id" zasob:desc="ID_PROJECT" zasob:alias_id=":cell_id"/>
+			</zasob:URL_ACTION>
+		</zasob:TABELA>
+	</zasob:BAZA_DANYCH>
+</zasob:tree>
+		*/
 		/* required Zasoby tree structure:
 - required base structure
 [:ts_main_id] TYPESPECIALS
@@ -97,7 +114,7 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 				'out' => array(':action_param_1_id' => 'ID')
 			);
 		}
-		DBG::_(true, true, "flatConfig_main", $flatConfig_main, __CLASS__, __FUNCTION__, __LINE__);
+		//DBG::_(true, true, "flatConfig_main", $flatConfig_main, __CLASS__, __FUNCTION__, __LINE__);
 		$flatConfig_link_in_projekt = array();
 		{
 			$flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db)
@@ -168,23 +185,13 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 				'out' => array(':link_action_id' => 'ID')
 			);
 		}
-		DBG::_(true, true, "flatConfig_link_in_projekt", $flatConfig_link_in_projekt, __CLASS__, __FUNCTION__, __LINE__);
-		/* flat config - table Projekty (default_db:IN7_MK_BAZA_DYSTRYBUCJI):
-[
-	{ // Zasob::assert(default_db/IN7_MK_BAZA_DYSTRYBUCJI/:url_action_name/ID)
-		query: "select z.ID from CRM_LISTA_ZASOBOW z
-			where z.PARENT_ID = :link_action_id
-				and z.ALIAS_ID = ':cell_id'
-				and z.TYPE = 'PARAM_IN'
-				and z.DESC = 'ID'
-				and z.A_STATUS not in('DELETED')
-		",
-		create: {CRM_LISTA_ZASOBOW: [TYPE: 'KOMORKA', PARENT_ID: ':tbl_id', DESC: 'ID']},
-		in: [':tbl_id', ':cell_id', ':link_action_id'],
-		out: { ID: ':link_param_id' }
-	}
-]
-		*/
+		//DBG::_(true, true, "flatConfig_link_in_projekt", $flatConfig_link_in_projekt, __CLASS__, __FUNCTION__, __LINE__);
+		$flatConf = array_merge($flatConfig_main, $flatConfig_link_in_projekt);
+		$knownArgs = array();
+		$knownArgs[':url_action_name'] = 'Test';
+		$knownArgs[':url_action_param_1_name'] = 'ID_PROJECT';
+		$knownArgs[':main_db_id'] = '36';// from DB::getDB()->getZasobId(); or DB::getPDO()->getZasobId();
+		$this->_debugFlatConfig($flatConf, $knownArgs);
 		$pdo = DB::getPDO();
 
 		$args = $this->getArgsList();
@@ -337,6 +344,76 @@ class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: U
 		}
 	}
 
+	public function _debugFlatConfig($flatConfig, $args = array()) {
+		//DBG::_(true, true, "flatConfig", $flatConfig, __CLASS__, __FUNCTION__, __LINE__);
+		echo '<pre style="border:1px solid green">';
+		foreach ($flatConfig as $conf) {
+			/*
+				[query] => string
+				[createTable] => srting - eg. CRM_LISTA_ZASOBOW
+				[createArgs] => array - eg. [ TYPE: 'TYPESPECIALS', DESC: 'Typespecials' ]
+				[in] => array - eg. [ ':ts_main_id', ':url_action_name' ]
+				[out] => array - eg. [ ':ts_main_id': 'ID' ]
+			*/
+			echo "Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
+		}
+		echo '</pre>';
+
+		echo '<pre style="border:1px solid green">';
+		echo "DBG: Simulate iter loop:\n";
+		$simulateGeneratedId = 1000;
+		$i = 0; $limit = 10; $todoIdx = array(); $knownArgsMap = array();
+		foreach ($flatConfig as $idx => $conf) $todoIdx[] = $idx;
+		foreach ($args as $arg => $val) $knownArgsMap[$arg] = $val;
+		for ($i = 0; $i < $limit; $i++) {
+			echo ">> DBG loop({$i}):\n";
+			$isExecuted = false;
+			foreach ($todoIdx as $idx) {
+				$conf = $flatConfig[$idx];
+				/*
+					[query] => string
+					[createTable] => srting - eg. CRM_LISTA_ZASOBOW
+					[createArgs] => array - eg. [ TYPE: 'TYPESPECIALS', DESC: 'Typespecials' ]
+					[in] => array - eg. [ ':ts_main_id', ':url_action_name' ]
+					[out] => array - eg. [ ':ts_main_id': 'ID' ]
+				*/
+				echo ">>>> Loop({$i}): idx({$idx}) Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
+				$canExecute = true;
+				foreach ($conf->in as $argName) {
+					if (!array_key_exists($argName, $knownArgsMap)) {
+						$canExecute = false;
+					}
+				}
+				if ($canExecute) {
+					// TODO: execute - $r = $this->_assertZasobConf($conf, $knownArgsMap);
+					// fetch params out to $knownArgsMap
+					foreach ($conf->out as $argName => $outFieldName) {
+						$knownArgsMap[$argName] = $simulateGeneratedId++;// TODO: fetch from returned object ($r->{$outFieldName})
+					}
+					$todoIdx = array_diff($todoIdx, array($idx));// remove $idx from $todoIdx
+					echo ">>>> Loop({$i}): knownArgsMap: " . json_encode($knownArgsMap) . " \n";
+					$isExecuted = true;
+				} else {
+					echo ">>>> Loop({$i}): cannot execute conf [{$idx}] missing args: " . json_encode($conf->in) . " \n";
+				}
+			}
+			if (!$isExecuted) {
+				echo "DBG: Stop";
+				if (empty($todoIdx)) {
+					echo " - OK";
+				} else {
+					echo " - Error - TODO:\n";
+					foreach ($todoIdx as $idx) {
+						$conf = $flatConfig[$idx];
+						echo "Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
+					}
+				}
+				break;
+			}
+		}
+		echo '</pre>';
+	}
+
 	public function fetchZasobInfo() {
 		$pdo = DB::getPDO();
 		$args = $this->getArgsList();