Przeglądaj źródła

Merge branch 'master' of ssh://biuro.biall-net.pl:2222/plabudda/se

* 'master' of ssh://biuro.biall-net.pl:2222/plabudda/se:
  updated Ant exec
  updated DBG::log
  updated RouteBase::getLink
a.binder 9 lat temu
rodzic
commit
a9f0ab31ec

+ 9 - 9
SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml

@@ -1,35 +1,35 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<project basedir="." name="example wfs GetFeature" default="http_fist_input">
+<project basedir="." name="example wfs GetFeature" default="http_first_input">
+
+    <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->
 
 
-    <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->    
-    
     <!-- sample URL which call this exact variables in this ANT build -->
     <!-- sample URL which call this exact variables in this ANT build -->
     <!-- przykladowy URL ktory przekazuje parametry do tego ANT -->
     <!-- przykladowy URL ktory przekazuje parametry do tego ANT -->
     <!--https://biuro.biall-net.pl/SE/version-git/index.php?_route=UrlAction_Ant&_task=ant&
     <!--https://biuro.biall-net.pl/SE/version-git/index.php?_route=UrlAction_Ant&_task=ant&
-        path=${default_db.in7_dziennik_koresp/test-get-wfs-xml} -  this is the place to keep ant build (directory name with build.xml)  
+        path=${default_db.in7_dziennik_koresp/test-get-wfs-xml} -  this is the place to keep ant build (directory name with build.xml)
         &namespace=p5_default_db:Rozdzielcza_test_bzyk_PE&featureID=123 - this is setting the <property name="url" value="${url}"/> - to point what is record/table to download
         &namespace=p5_default_db:Rozdzielcza_test_bzyk_PE&featureID=123 - this is setting the <property name="url" value="${url}"/> - to point what is record/table to download
         <property name="uuid" value="${uuid}"/> it is automatically also set to enable uinque transaction and to allow to save data with user
         <property name="uuid" value="${uuid}"/> it is automatically also set to enable uinque transaction and to allow to save data with user
         <property name="passwordBase64Basic" value="${passwordBase64Basic}"/> - this is also set - to enable communicate with API -
         <property name="passwordBase64Basic" value="${passwordBase64Basic}"/> - this is also set - to enable communicate with API -
-        <property name="DwebRootUrl" value="${$webRootUrl}"/> - this is the place where script is localized to easyli to target user GUI by href to generated output      
+        <property name="DwebRootUrl" value="${$webRootUrl}"/> - this is the place where script is localized to easyli to target user GUI by href to generated output
     />
     />
     -->
     -->
 
 
     <property name="uuid" value="${uuid}"/>
     <property name="uuid" value="${uuid}"/>
     <property name="passwordBase64Basic" value="${passwordBase64Basic}"/>
     <property name="passwordBase64Basic" value="${passwordBase64Basic}"/>
     <property name="url" value="${url}"/>
     <property name="url" value="${url}"/>
-    <property name="webRootUrl" value="${webRootUrl}"/> 
+    <property name="webRootUrl" value="${webRootUrl}"/>
 
 
-    <target name="http_fist_input">
+    <target name="http_first_input">
         <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
         <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
             <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}"/>
             <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}"/>
         </exec>
         </exec>
         <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
         <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
         <echo message="OUTPUT__START"/>
         <echo message="OUTPUT__START"/>
         <echo message="${wfs_output}"/>
         <echo message="${wfs_output}"/>
-        
+
         <echo message="webRootUrl"></echo>
         <echo message="webRootUrl"></echo>
         <echo message="${webRootUrl}"></echo>
         <echo message="${webRootUrl}"></echo>
-        
+
         <echo message="OUTPUT__END"/>
         <echo message="OUTPUT__END"/>
 
 
         <echo message="RESULT__START"/>
         <echo message="RESULT__START"/>

+ 28 - 0
SE/se-lib/Core/AclHelper.php

@@ -176,6 +176,31 @@ class Core_AclHelper {// Helper class for Acl
 				$rowFunList[] = $rowFunction;
 				$rowFunList[] = $rowFunction;
 			}
 			}
 		}
 		}
+
+    if (1) {// Druki
+      $parsedNs = self::parseNamespaceUrl($acl->getNamespace());
+      // array (
+      //   'name' => 'TEST_PERMS',
+      //   'prefix' => 'default_db',
+      //   'url' => 'https://biuro.biall-net.pl/wfs/default_db',
+      //   'sourceName' => 'default_db',
+      // ),
+      $typeName = "{$parsedNs['prefix']}:{$parsedNs['name']}";
+      DBG::log([
+        'msg' => "getMoreFunctionsCell Druki",
+        'namespace' => $acl->getNamespace(),
+        'typeName' => $typeName,
+        'primaryKey' => $id,
+        'parseNamespace' => $parsedNs,
+      ]);
+      $rowFunList[] = [
+        'href' => Request::getPathUri() . "index.php?_route=UrlAction_Ant&typeName={$typeName}&primaryKey={$id}",
+        'ico' => 'glyphicon glyphicon-file',
+        'label' => "Druki",
+        'title' => "Druki"
+      ];
+    }
+    DBG::log(['msg'=>"\$rowFunList", '$rowFunList'=>$rowFunList]);
 		return $rowFunList;
 		return $rowFunList;
 	}
 	}
 
 
@@ -220,6 +245,9 @@ class Core_AclHelper {// Helper class for Acl
     return $aclList;
     return $aclList;
   }
   }
 
 
+  public static function parseTypeName($typeName) {
+    return self::parseNamespaceUrl(str_replace(':', '/', $typeName));
+  }
   /**
   /**
    * Parse namespace url into parts.
    * Parse namespace url into parts.
    *
    *

+ 6 - 4
SE/se-lib/DBG.php

@@ -142,7 +142,7 @@ class DBG {
 		}
 		}
 		self::_log($mixedArg, $type, $msg);
 		self::_log($mixedArg, $type, $msg);
 	}
 	}
-	public static function _log($mixedArg, $type = 'unknown', $msg = '') {
+	public static function _log($mixedArg, $type = '', $msg = '') {
 		// * TODO: debug to file based on session_id (/tmp/se-debug-{$date("Y-m-d")}-{$login}_{$ip}_{$session_id}.log)
 		// * TODO: debug to file based on session_id (/tmp/se-debug-{$date("Y-m-d")}-{$login}_{$ip}_{$session_id}.log)
 		$logInfo = [
 		$logInfo = [
 			'date' => date("Y-m-d H:i:s"),
 			'date' => date("Y-m-d H:i:s"),
@@ -163,7 +163,7 @@ class DBG {
 			$logInfo['trace'] = $mixedArg->getTraceAsString();// getTrace
 			$logInfo['trace'] = $mixedArg->getTraceAsString();// getTrace
 		} else if (is_string($mixedArg)) {
 		} else if (is_string($mixedArg)) {
 			if ('sql' == $type) {
 			if ('sql' == $type) {
-				if ('unknown' == $logInfo['type']) $logInfo['type'] = 'sql';
+				if (!$logInfo['type']) $logInfo['type'] = 'sql';
 				if (empty($logInfo['msg'])) $logInfo['msg'] = "sql";
 				if (empty($logInfo['msg'])) $logInfo['msg'] = "sql";
 				$logInfo['log'] = $mixedArg;
 				$logInfo['log'] = $mixedArg;
 			} else {
 			} else {
@@ -174,8 +174,9 @@ class DBG {
 			ob_start();
 			ob_start();
 			debug_print_backtrace();
 			debug_print_backtrace();
 			$logInfo['trace'] = ob_get_clean();
 			$logInfo['trace'] = ob_get_clean();
-		} else if (is_array($mixedArg)) {
-			if ('unknown' == $logInfo['type']) $logInfo['type'] = 'array';
+		} else if ('array' == $type || is_array($mixedArg)) {
+			$mixedArg = (array)$mixedArg;
+			if (!$logInfo['type']) $logInfo['type'] = 'array';
 			if (!empty($logInfo['msg']) && !empty($mixedArg['msg'])) $logInfo['msg'] .= ". {$mixedArg['msg']}";
 			if (!empty($logInfo['msg']) && !empty($mixedArg['msg'])) $logInfo['msg'] .= ". {$mixedArg['msg']}";
 			else if (empty($logInfo['msg']) && !empty($mixedArg['msg'])) $logInfo['msg'] = $mixedArg['msg'];
 			else if (empty($logInfo['msg']) && !empty($mixedArg['msg'])) $logInfo['msg'] = $mixedArg['msg'];
 			if (!empty($mixedArg['msg'])) unset($mixedArg['msg']);
 			if (!empty($mixedArg['msg'])) unset($mixedArg['msg']);
@@ -186,6 +187,7 @@ class DBG {
 		}
 		}
 		$logInfo['trace'] = str_replace(APP_PATH_ROOT, 'SE', $logInfo['trace']);
 		$logInfo['trace'] = str_replace(APP_PATH_ROOT, 'SE', $logInfo['trace']);
 		$logInfo['trace'] .= (("\n" == substr($logInfo['trace'], -1)) ? '' :  "\n") . "URI: " . V::get('REQUEST_URI', '', $_SERVER);
 		$logInfo['trace'] .= (("\n" == substr($logInfo['trace'], -1)) ? '' :  "\n") . "URI: " . V::get('REQUEST_URI', '', $_SERVER);
+		if (!$logInfo['type']) $logInfo['type'] = 'unknown';
 		error_log(
 		error_log(
 			json_encode($logInfo) . "\n"
 			json_encode($logInfo) . "\n"
 			, 3
 			, 3

+ 80 - 28
SE/se-lib/Route/UrlAction/Ant.php

@@ -11,20 +11,33 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
 
 
   public function defaultAction() {
   public function defaultAction() {
     UI::gora();
     UI::gora();
+    UI::menu();
+    UI::startContainer();
     UI::tag('h1', [], 'Ant');
     UI::tag('h1', [], 'Ant');
     try {
     try {
       $taskList = $this->getAntUrlActionList();
       $taskList = $this->getAntUrlActionList();
-      DBG::nicePrint($taskList, 'ant-url_action');
 
 
-      $featureID = V::get('featureID', '', $_GET);
-      $typeName = V::get('typeName', '', $_GET);
-      // TODO: validate missing ...
+      // $featureID = V::get('featureID', '', $_GET);
+      $primaryKey = V::get('primaryKey', '', $_GET, 'word');
+      $typeName = V::get('typeName', '', $_GET, 'word');
+      if (empty($typeName)) throw new Exception("Missing typeName");
+      if (empty($primaryKey)) throw new Exception("Missing primaryKey");
+      $parsedInfo = Core_AclHelper::parseTypeName($typeName);
+      DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})");
+      $acl = ACL::getAclByNamespace("{$parsedInfo['url']}/{$parsedInfo['name']}");
+      $pkField = $acl->getPrimaryKeyField();
 
 
       UI::startTag('ul');
       UI::startTag('ul');
       foreach ($taskList as $path => $label) {
       foreach ($taskList as $path => $label) {
-        $link = "index.php?_route=UrlAction_Ant&_task=ant&path={$path}&typeName={$typeName}&featureID={$featureID}";
         echo UI::h('li', [], [
         echo UI::h('li', [], [
-          UI::h('a', ['href'=>$link], "Uruchom '{$label}'")
+          UI::h('a', [
+            'href' => $this->getLink('ant', [
+              'path' => $path,
+              'typeName' => $typeName,
+              'primaryKey' => $primaryKey,
+              'primaryKeyField' => $pkField
+            ])
+          ], "Uruchom '{$label}'")
         ]);
         ]);
       }
       }
       UI::endTag('ul');
       UI::endTag('ul');
@@ -32,6 +45,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       UI::alert('danger', $e->getMessage());
       UI::alert('danger', $e->getMessage());
       DBG::log($e);
       DBG::log($e);
     }
     }
+    UI::endContainer();
     UI::dol();
     UI::dol();
   }
   }
 
 
@@ -47,45 +61,82 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
 
 
   public function antAction() {
   public function antAction() {
     UI::gora();
     UI::gora();
+    UI::startContainer();
     try {
     try {
-      echo UI::h('h1', [], "Ant action");
       $path = V::get('path', '', $_GET);
       $path = V::get('path', '', $_GET);
       if (!$path) throw new Exception("Missing Ant path!");
       if (!$path) throw new Exception("Missing Ant path!");
-      $primaryKey = V::get('primaryKey', '', $_GET);
-      $xpath = V::get('xpath', '', $_GET);
-
       $typeName = V::get('typeName', '', $_GET);
       $typeName = V::get('typeName', '', $_GET);
-      list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName
+      if (!$typeName) throw new Exception("Missing typeName");
+      $primaryKey = V::get('primaryKey', '', $_GET);
+      if (!$primaryKey) throw new Exception("Missing primaryKey");
+      $pkField = V::get('primaryKeyField', '', $_GET);
+      if (!$pkField) throw new Exception("Missing primaryKeyField");
+      // list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName
+      $parsedInfo = Core_AclHelper::parseTypeName($typeName);
+      DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})");
+      $nsPrefix = $parsedInfo['prefix'];
+      $objectName = $parsedInfo['name'];
 
 
       // TODO: validate missing ...
       // TODO: validate missing ...
+      DBG::log($_GET, 'array', '$_GET');
       DBG::log([ 'msg'=>'$path', '$path'=>$path]);
       DBG::log([ 'msg'=>'$path', '$path'=>$path]);
       DBG::log([ 'msg'=>'$primaryKey', '$primaryKey'=>$primaryKey]);
       DBG::log([ 'msg'=>'$primaryKey', '$primaryKey'=>$primaryKey]);
       DBG::log([ 'msg'=>'$typeName', '$typeName'=>$typeName]);
       DBG::log([ 'msg'=>'$typeName', '$typeName'=>$typeName]);
 
 
       $taskList = $this->getAntUrlActionList();
       $taskList = $this->getAntUrlActionList();
       if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
       if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
+      echo UI::h('h3', [], [
+        "Druk",
+        '<br>',
+        UI::h('small', [], $taskList[$path])
+      ]);
 
 
       echo UI::h('hr');
       echo UI::h('hr');
 
 
       $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test
       $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test
-      $outputFunctionUrl = Request::getPathUri() . "index.php?_route=UrlAction_Ant&_task=output&path={$path}&file=";
+      $outputFunctionUrl = $this->getLink('output') . "&path={$path}&file=";
       DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]);
       DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]);
       DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]);
       DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]);
-      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=".$typeName."&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
+      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME={$typeName}&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
       $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
       $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
-//      $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin}  -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\"  2>&1";
-      $cmd = "{$this->pathUrlActions}{$path}/do_build.sh -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\" ";
+      $uniqID = session_id();// TODO: uniq id for every request
+      // $cmd = "{$this->pathUrlActions}{$path}/do_build.sh";
+      $cmd = "cd {$this->pathUrlActions}{$path} && ant -S";
+      $cmd .= " -DoutputFunctionUrl='{$outputFunctionUrl}'";
+      $cmd .= " -DwebRootUrl='{$webRootUrl}'";
+      $cmd .= " -Durl='{$testUrl}'";
+      $cmd .= " -DpasswordBase64Basic=\"{$cryptedPass}\"";
+      $cmd .= " -Duuid=\"{$uniqID}\"";
+      $cmd .= " -Dxpath={$pkField}";
+      $cmd .= " -Dxpath_value={$primaryKey}";
+      $cmd .= " -DtypeName=\"{$typeName}\"";
+      $cmd .= " 2>&1";
+
+      $pathCmd = [];
+      $pathCmd[] = '/opt/local/bin/ant';
+      $pathCmd[] = '/bin';
+      $pathCmd[] = '/usr/bin';
+      $pathCmd[] = '/usr/local/bin';
+      $pathCmd[] = '/opt/local/bin';
+      $pathCmd[] = '/sbin';
+      $pathCmd[] = '/usr/sbin';
+      $pathCmd[] = '/opt/local/sbin/skrypty';
+      $pathCmd[] = '/opt/local/var/macports/software';
+      $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/bin';
+      $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/sbin';
+      $cmd = 'export PATH=' . implode(':', $pathCmd) . "\n" .
+        'JAVA_HOME="/usr/bin/java"' . "\n" .
+        'MAVEN_OPTS="-Xms256m -Xmx512m"' . "\n" .
+        $cmd;
+      $useShellExec = true;
+      if ($useShellExec) $out = shell_exec($cmd);
+      else V::exec($cmd, $out, $ret);
+      DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out, 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]);
+      if (empty($out)) throw new Exception("Empty output");
+      if ($useShellExec) $out = explode("\n", $out);
 
 
-      DBG::log([ 'msg'=>"cmd", 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]);
-      //V::exec($cmd, $out, $ret); to nie dziala prawidlowo
-      putenv('PATH=/opt/local/bin/ant');
-      $out=shell_exec($cmd);
-      DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out ]);
       $html = []; $startRead = false;
       $html = []; $startRead = false;
-      
-      
-      echo "<hr>".$out."<hr>"; //do poprawy, chce ruszyc, bo lokalnie mi dziala
-     /* foreach ($out as $line) {
+      foreach ($out as $line) {
         if (!$startRead) {
         if (!$startRead) {
           if ('OUTPUT__START' == $line) {
           if ('OUTPUT__START' == $line) {
             $startRead = true;
             $startRead = true;
@@ -99,15 +150,16 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
           $html[]= $line;
           $html[]= $line;
         }
         }
       }
       }
-      echo UI::h('h3', [], "output:");
       if (empty($html)) UI::alert('danger', "Empty output!");
       if (empty($html)) UI::alert('danger', "Empty output!");
-      // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
-      echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
-      */
+      else {
+        // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
+        echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+      }
     } catch (Exception $e) {
     } catch (Exception $e) {
       UI::alert('danger', $e->getMessage());
       UI::alert('danger', $e->getMessage());
       DBG::log($e);
       DBG::log($e);
     }
     }
+    UI::endContainer();
     UI::dol();
     UI::dol();
   }
   }
 
 

+ 14 - 2
SE/se-lib/RouteBase.php

@@ -21,11 +21,23 @@ class RouteBase {
 		die("default task not implemented");
 		die("default task not implemented");
 	}
 	}
 
 
-	public function getLink($task = '') {
+	public function getLink($task = '', $args = null) {
 		$clsName = get_class($this);
 		$clsName = get_class($this);
 		if ('Route_' != substr($clsName, 0, strlen('Route_'))) throw new Exception("Wrong route class name '{$clsName}'");
 		if ('Route_' != substr($clsName, 0, strlen('Route_'))) throw new Exception("Wrong route class name '{$clsName}'");
 		$routeName = substr($clsName, strlen('Route_'));
 		$routeName = substr($clsName, strlen('Route_'));
-		return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($task) ? "&_task={$task}" : "");
+		if (empty($args)) return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($task) ? "&_task={$task}" : "");
+		if (is_string($args)) {
+			return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($task) ? "&_task={$task}" : "") . ltrim($args, '&');
+		}
+		if (is_array($args)) {
+			$urlArgs = [];
+			$uniqArgs = [];
+			if (!empty($task)) $uniqArgs['_task'] = $task;
+			foreach ($args as $name => $val) $uniqArgs[$name] = $val;
+			foreach ($uniqArgs as $name => $val) $urlArgs[] = "{$name}={$val}";
+			return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($urlArgs) ? '&' . implode('&', $urlArgs) : '');
+		}
+		throw new Exception("Not Implemented args type", 501);
 	}
 	}
 
 
 	public function runTask($task) {
 	public function runTask($task) {