ID=$id; $uploader = new FileUploader('WMS_LAYERS_COLUMN', $record); $errMsg=""; if (!$uploader->setConfig($folderConf, $errMsg)) throw new HttpException("Błąd danych konfiguracyjnych" . '
' . "\n" . $errMsg, 404); $uploader->findFolder(); return $uploader->getDestLocalPath(true); } public function defaultAction() { SE_Layout::gora(); SE_Layout::menu(); $ID_WMS_LAYERS=V::get('ID_WMS_LAYERS',0,$_GET,'int'); if ($ID_WMS_LAYERS<=0) die ('ID ERROR'); try { $destFolderPath = $this->getDirectory($ID_WMS_LAYERS); $files=array(); foreach (glob($destFolderPath."/*.tif",GLOB_BRACE) as $node) { if (is_file($node)) $files[]=basename($node); } if (count($files)==0) throw new Exception('Nie znaleziono żadnego pliku tif!'); if (count($files)>1) throw new Exception('Znaleziono zbyt dużo plików tif!'); $validateGeoTifJson=shell_exec("/opt/local/bin/gdalinfo -json ".$destFolderPath."/*".$files[0]." 2>/dev/null"); $validateGeoTif=json_decode($validateGeoTifJson); if (!$validateGeoTif) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem tif!'); if (!$validateGeoTif->coordinateSystem->wkt) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem GeoTif!'); $sqlObj = new stdClass(); $sqlObj->ID = $ID_WMS_LAYERS; $sqlObj->FILE_STATUS='TO_GENERATE'; $sqlObj->FILE_STATUS_INFO='Plik oczekuje na przetworzenie'; $sqlObj->FILE_NAME=$files[0]; $affected = DB::getDB()->UPDATE_OBJ('WMS_LAYERS', $sqlObj); if ($affected) SE_Layout::alert('success','Oznaczono plik '.$files[0].' do przetworzenia.'); else SE_Layout::alert('warning','Plik '.$files[0].' został już wcześniej oznaczony do przetworzenia.'); } catch (Exception $e) { SE_Layout::alert('danger',$e->getMessage()); } ?>
Powrót
fetchall("select count(*) as cnt from CRM_CONFIG where CONF_KEY='module_WMS' and CONF_VAL='on'"); if (!$moduleActive[0]['cnt']) throw new Exception("Module WMS disabled/not installed."); $layers=DB::getPDO()->fetchall("select ID,FILE_NAME from WMS_LAYERS where FILE_STATUS='IN_PROGRESS'"); foreach ($layers as $layer) { if (!file_exists('/tmp/generate_wms-'.$layer['ID'].'.lock')) { unlink('/tmp/generate_wms-'.$layer['ID'].'.sh'); $destFolderPath = $this->getDirectory($layer['ID']); if (file_exists($destFolderPath.'/.wms/.completed')) { DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'GENERATED','FILE_STATUS_INFO'=>'Plik przetworzony poprawnie')); unlink($destFolderPath.'/.wms/.completed'); } else { DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'TO_GENERATE','FILE_STATUS_INFO'=>'Wystąpił błąd prztwarzania, ale nastąpi kolejna próba jego przetworzenia')); } } if (count($layers)) $this->mapGenerate(); } $bashSchema=' rm -rf __PATH__/.wms mkdir __PATH__/.wms lock="/tmp/generate_wms-__ID__.lock" touch ${lock} /opt/local/bin/gdal_translate -of GTiff -co "TILED=YES" -co "COMPRESS=DEFLATE" -co "ZLEVEL=9" -co "BIGTIFF=YES" __PATH__/__FILE__ __PATH__/.wms/__FILE__ && /opt/local/bin/gdaladdo -r average __PATH__/.wms/__FILE__ 2 4 8 16 32 64 128 rm -f ${lock} touch __PATH__/.wms/.completed echo "Successfully completed." '; $search=array('__ID__','__PATH__','__FILE__'); $layers=DB::getPDO()->fetchall("select ID,FILE_NAME from WMS_LAYERS where FILE_STATUS='TO_GENERATE'"); foreach ($layers as $layer) { $destFolderPath = $this->getDirectory($layer['ID']); if(!is_file($destFolderPath.'/'.$layer['FILE_NAME'])) { DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'ERROR','FILE_STATUS_INFO'=>'Wystąpił błąd pliku tif')); throw new Exception("Błąd pliku: ".$layer['FILE_NAME']); } DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'IN_PROGRESS','FILE_STATUS_INFO'=>'Plik w trakcie przetwarzania')); $replace = array($layer['ID'],$destFolderPath,$layer['FILE_NAME']); $bash = str_replace($search,$replace,$bashSchema); file_put_contents('/tmp/generate_wms-'.$layer['ID'].'.sh',$bash); shell_exec('nohup /bin/sh /tmp/generate_wms-'.$layer['ID'].'.sh > /tmp/generate_wms-'.$layer['ID'].'.log 2>&1 & echo $!'); } } catch (Exception $e) { echo $e->getMessage()."\n"; } } public function doGenerateAction() { $this->doGenerate(); // echo "OK\n"; } public function reinstallAction() { $this->reinstall(); die('OK'); } /* public function reinstall() { $sqlList = array(); //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_CONFIG`"; $sqlList['InstallTable'] = <<has_errors()) { throw new Exception("DB Errors: " . implode("\n
", $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
", $db->get_errors())); } } } */ }