修改了三江源元数据同步时的问题

This commit is contained in:
Li Jianxuan 2014-03-12 07:01:09 +00:00
parent e63849890b
commit 9af8314d14
3 changed files with 172 additions and 156 deletions

View File

@ -1,92 +1,92 @@
<div class="pagebody">
<div class="col-lg-10 col-md-8 col-sm-12">
<h3>数据同步</h3>
<hr />
<a href="javascript:void(0);" class="btn-sync btn btn-default btn-lg" rel="qinghaihu"><span class="glyphicon glyphicon-import"></span>从“青海湖”数据库同步</a>
<a href="javascript:void(0);" class="btn-sync btn btn-default btn-lg" rel="sanjiangyuan"><span class="glyphicon glyphicon-import"></span>从“三江源总平台”数据库同步</a>
<hr />
<div class="progress progress-striped active" id="submit-loading" style="height:40px;display:none">
<div class="progress-bar" style="width:100%"></div>
</div>
<div class="" id="alert-info"></div>
</div><!-- col-lg-8 -->
<div class="col-lg-2 col-md-4 col-sm-12">
<?= $this->partial("layout/admin/metadata/sync/nav") ?>
</div><!-- col-lg-4 -->
</div>
<script>
var _this = {};
_this.source = '<?= isset($this->data['id']) ? "edit":'add' ?>';
$(document).ready(function(e) {
$('.btn-sync').click(function(e) {//submit
$("#alert-info").hide();
$.ajax({
'type':"POST",
'url':"<?= $_SERVER['REQUEST_URI'] ?>",
'data':'source=' + $(this).attr('rel'),
'success':submited,
'timeout': 30000,
'error': function(){
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html("出现错误,请稍后重试");
$('#submit-loading').hide();
return false;
},
'beforeSend': function(){
$(".btn-sync").addClass('disabled');
$(".btn-sync").attr('disabled','disabled');
$('#submit-loading').show();
},
'complete': function(){
$(".btn-sync").removeClass('disabled');
$(".btn-sync").removeAttr('disabled');
$('#submit-loading').hide();
}
});
});
});
function submited(data){
$("#alert-info").show();
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html(data.error);
return false;
}
if(typeof(data.success)!='undefined')
{
$("#btn-submit").attr('disabled','disabled');
$("#alert-info").attr('class','alert alert-success');
if(typeof(data.time)!='undefined')
{
html = "数据同步成功!耗时:" + data.time + "秒";
}else{
html = "数据同步成功!";
}
$("#alert-info").html(html);//setTimeout("window.history.go(-1)",3000);
return false;
}
}
else{
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html('服务器掉链子了,<a href="/service/reporterror/?content=">通知管理员</a>');
return false;
}
}
<div class="pagebody">
<div class="col-lg-10 col-md-8 col-sm-12">
<h3>数据同步</h3>
<hr />
<a href="javascript:void(0);" class="btn-sync btn btn-default btn-lg" rel="qinghaihu"><span class="glyphicon glyphicon-import"></span>从“青海湖”数据库同步</a>
<a href="javascript:void(0);" class="btn-sync btn btn-default btn-lg" rel="sanjiangyuan"><span class="glyphicon glyphicon-import"></span>从“三江源总平台”数据库同步</a>
<hr />
<div class="progress progress-striped active" id="submit-loading" style="height:40px;display:none">
<div class="progress-bar" style="width:100%"></div>
</div>
<div class="" id="alert-info"></div>
</div><!-- col-lg-8 -->
<div class="col-lg-2 col-md-4 col-sm-12">
<?= $this->partial("layout/admin/metadata/sync/nav") ?>
</div><!-- col-lg-4 -->
</div>
<script>
var _this = {};
_this.source = '<?= isset($this->data['id']) ? "edit":'add' ?>';
$(document).ready(function(e) {
$('.btn-sync').click(function(e) {//submit
$("#alert-info").hide();
$.ajax({
'type':"POST",
'url':"<?= $_SERVER['REQUEST_URI'] ?>",
'data':'source=' + $(this).attr('rel'),
'success':submited,
'timeout': 600000,
'error': function(){
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html("出现错误,请稍后重试");
$('#submit-loading').hide();
return false;
},
'beforeSend': function(){
$(".btn-sync").addClass('disabled');
$(".btn-sync").attr('disabled','disabled');
$('#submit-loading').show();
},
'complete': function(){
$(".btn-sync").removeClass('disabled');
$(".btn-sync").removeAttr('disabled');
$('#submit-loading').hide();
}
});
});
});
function submited(data){
$("#alert-info").show();
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html(data.error);
return false;
}
if(typeof(data.success)!='undefined')
{
$("#btn-submit").attr('disabled','disabled');
$("#alert-info").attr('class','alert alert-success');
if(typeof(data.time)!='undefined')
{
html = "数据同步成功!耗时:" + data.time + "秒";
}else{
html = "数据同步成功!";
}
$("#alert-info").html(html);//setTimeout("window.history.go(-1)",3000);
return false;
}
}
else{
$("#alert-info").attr('class','alert alert-danger');
$("#alert-info").html('服务器掉链子了,<a href="/service/reporterror/?content=">通知管理员</a>');
return false;
}
}
</script>

View File

@ -4,6 +4,7 @@ namespace Westdc\MetadataSync\Plugin;
use Sookon\Helpers\View as view;
use Sookon\Helpers\Dbh as dbh;
use Sookon\Helpers\PDO;
use Sookon\Helpers\Db;
use Sookon\Helpers\Config;
use Sookon\Helpers\Table;
use Zend\Http\PhpEnvironment\Request;
@ -24,6 +25,8 @@ class Sanjiangyuan implements SyncPluginInterface
function __construct($db)
{
$this->db = $db;
new Db($this->target);
ini_set("max_execution_time",600);
}
public function check()

View File

@ -216,18 +216,21 @@ class ISO19115
$id = $temp['id'];
//$id=$db->lastInsertId('metadata','id');
//处理在线资源
if ($this->onlineresource) foreach($this->onlineresource as $resource)
{
$name = isset($resource['name']) ? $resource['name']:"";
$sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)";
$db->query($sql,array(
$this->uuid,
$resource['linkage'],
isset($resource['protocol']) ? $resource['protocol']:"",
$name,
$resource['description']
)
);
if (isset($this->onlineresource))
{
foreach($this->onlineresource as $resource)
{
$name = isset($resource['name']) ? $resource['name']:"";
$sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)";
$db->query($sql,array(
$this->uuid,
$resource['linkage'],
isset($resource['protocol']) ? $resource['protocol']:"",
$name,
$resource['description']
)
);
}
}
//处理缩略图
if (!empty($this->thumbnail)) {
@ -252,15 +255,18 @@ class ISO19115
}*/
//处理关键词
//1:N relation
foreach($this->keyword as $keytype=>$keys)
if(isset($this->keyword))
{
foreach($keys as $key)
foreach($this->keyword as $keytype=>$keys)
{
$sql="insert into keyword (id,keyword,keytype) values(?,?,?)";
try {
$db->query($sql,array($id,$key,$keytype));
} catch(\Exception $e) {
//忽略关键词错误
foreach($keys as $key)
{
$sql="insert into keyword (id,keyword,keytype) values(?,?,?)";
try {
$db->query($sql,array($id,$key,$keytype));
} catch(\Exception $e) {
//忽略关键词错误
}
}
}
}
@ -351,25 +357,28 @@ class ISO19115
}
}
//处理数据限制信息
foreach($this->limits as $uselimit)
if(isset($this->limits))
{
$sql="select id from uselimit where uselimit=?";
$sth=$db->query($sql,array($uselimit));
$row = $sth->current();
if (!$row)
foreach($this->limits as $uselimit)
{
$sql="insert into uselimit (uselimit) values (?)";
$db->query($sql,array($uselimit));
}
$sql="select id from uselimit where uselimit=?";
$sth = $db->query($sql,array($uselimit));
$row = $sth->current();
if ($row)
{
try{
$sql="insert into mdlimit (uuid,lid) values(?,?)";
$db->query($sql,array($this->uuid,$row->id));
}catch(\Exception $e){
$sql="select id from uselimit where uselimit=?";
$sth=$db->query($sql,array($uselimit));
$row = $sth->current();
if (!$row)
{
$sql="insert into uselimit (uselimit) values (?)";
$db->query($sql,array($uselimit));
}
$sql="select id from uselimit where uselimit=?";
$sth = $db->query($sql,array($uselimit));
$row = $sth->current();
if ($row)
{
try{
$sql="insert into mdlimit (uuid,lid) values(?,?)";
$db->query($sql,array($this->uuid,$row->id));
}catch(\Exception $e){
}
}
}
}
@ -472,7 +481,7 @@ class ISO19115
$this->author[$k]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
@$this->author[$k]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
$cnt=$k+1;
@$cnt=$k+1;
$authors=$this->dom->getElementsByTagName('mdContact');
foreach($authors as $j=>$author)
{
@ -494,15 +503,15 @@ class ISO19115
$authors=$this->dom->getElementsByTagName('distorCont');
foreach($authors as $m=>$author)
{
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
@$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
if(isset($author->getElementsByTagName('rpOrgName')->item(0)->nodeValue))
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
if(isset($author->getElementsByTagName('rpPosName')->item(0)->nodeValue))
$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
if(isset($author->getElementsByTagName('delPoint')->item(0)->nodeValue))
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
@$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
@$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
if(isset($author->getElementsByTagName('postCode')->item(0)->nodeValue))
$this->author[$cnt+$m]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
if(isset($author->getElementsByTagName('city')->item(0)->nodeValue))
@ -514,20 +523,20 @@ class ISO19115
if(isset($author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue))
$this->author[$cnt+$m]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
$cnt+=$m+1;
@$cnt+=$m+1;
$authors=$this->dom->getElementsByTagName('idPoC');
foreach($authors as $m=>$author)
{
$this->author[$cnt+$m]['individual']=$author->getElementsByTagName('rpIndName')->item(0)->nodeValue;
$this->author[$cnt+$m]['organisation']=$author->getElementsByTagName('rpOrgName')->item(0)->nodeValue;
@$this->author[$cnt+$m]['position']=$author->getElementsByTagName('rpPosName')->item(0)->nodeValue;
$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
$this->author[$cnt+$m]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
$this->author[$cnt+$m]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
$this->author[$cnt+$m]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
$this->author[$cnt+$m]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
@$this->author[$cnt+$m]['delivery']=$author->getElementsByTagName('delPoint')->item(0)->nodeValue;
@$this->author[$cnt+$m]['phone']=$author->getElementsByTagName('voiceNum')->item(0)->nodeValue;
@$this->author[$cnt+$m]['email']=$author->getElementsByTagName('eMailAdd')->item(0)->nodeValue;
@$this->author[$cnt+$m]['postal']=$author->getElementsByTagName('postCode')->item(0)->nodeValue;
@$this->author[$cnt+$m]['city']=$author->getElementsByTagName('city')->item(0)->nodeValue;
@$this->author[$cnt+$m]['administrative']=$author->getElementsByTagName('adminArea')->item(0)->nodeValue;
@$this->author[$cnt+$m]['country']=$author->getElementsByTagName('country')->item(0)->nodeValue;
$this->author[$cnt+$m]['role']=$author->getElementsByTagName('RoleCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
}
/*
@ -592,7 +601,7 @@ class ISO19115
$this->onlineresource[$k]['linkage']=$src->getElementsByTagName('linkage')->item(0)->nodeValue;
if ($src->getElementsByTagName('protocol')->item(0)) $this->onlineresource[$k]['protocol']=$src->getElementsByTagName('protocol')->item(0)->nodeValue;
if ($src->getElementsByTagName('orName')->item(0)) $this->onlineresource[$k]['name']=$src->getElementsByTagName('orName')->item(0)->nodeValue;
$this->onlineresource[$k]['description']=$src->getElementsByTagName('orDesc')->item(0)->nodeValue;
@$this->onlineresource[$k]['description']=$src->getElementsByTagName('orDesc')->item(0)->nodeValue;
}
}
$cats=$this->dom->getElementsByTagName('tpCat');
@ -608,22 +617,26 @@ class ISO19115
if ($keys->getElementsByTagName('KeyTypCd')->item(0) && $keys->getElementsByTagName('KeyTypCd')->item(0)->hasAttributes())
$k=$keys->getElementsByTagName('KeyTypCd')->item(0)->attributes->getNamedItem('value')->nodeValue;
if (is_numeric($k))
$kt=$this->keytypecode[(int)$k];
if(isset($this->keytypecode[(int)$k]))
$kt=$this->keytypecode[(int)$k];
else
$kt=$k;
//如果没有找到类别,则默认为主题关键词
if (!$kt) $kt=$this->keytypecode[5];
$ks=$keys->getElementsByTagName('keyword');
foreach($ks as $key)
if(isset($kt))
{
//处理特殊情况:多关键词输入在一起,用一些符号来分割,如分号等。
$pos=strpos($key->nodeValue,';');
if ($pos===false)
$this->keyword[$kt][]=$key->nodeValue;
else {
$str=explode(';',$key->nodeValue);
foreach($str as $s){
$this->keyword[$kt][]=$s;
if (!$kt) $kt=$this->keytypecode[5];
$ks=$keys->getElementsByTagName('keyword');
foreach($ks as $key)
{
//处理特殊情况:多关键词输入在一起,用一些符号来分割,如分号等。
$pos=strpos($key->nodeValue,';');
if ($pos===false)
$this->keyword[$kt][]=$key->nodeValue;
else {
$str=explode(';',$key->nodeValue);
foreach($str as $s){
$this->keyword[$kt][]=$s;
}
}
}
}
@ -643,7 +656,7 @@ class ISO19115
$ds = $this->dom->getElementsByTagName('datasetSeries');
foreach($ds as $k=>$dataset)
{
$this->datasetSeries[$k]['seriesName']=$dataset->getElementsByTagName('seriesName')->item(0)->nodeValue;
@$this->datasetSeries[$k]['seriesName']=$dataset->getElementsByTagName('seriesName')->item(0)->nodeValue;
if(isset($dataset->getElementsByTagName('issId')->item(0)->nodeValue))
$this->datasetSeries[$k]['issId']=$dataset->getElementsByTagName('issId')->item(0)->nodeValue;
if(isset($dataset->getElementsByTagName('artPage')->item(0)->nodeValue))
@ -694,7 +707,7 @@ class ISO19115
}
}
//提取时间信息
$tm_period=$this->dom->getElementsByTagName('TM_Period');
@$tm_period=$this->dom->getElementsByTagName('TM_Period');
foreach($tm_period as $period)
{
$this->timebegin=$period->getElementsByTagName('begin')->item(0)->nodeValue;
@ -722,9 +735,9 @@ class ISO19115
foreach ($graphs as $g)
{
if ($g->getElementsByTagName('bgFileDesc')->item(0)->nodeValue=='thumbnail') {
$this->graph['filename']=$g->getElementsByTagName('bgFileName')->item(0)->nodeValue;
@$this->graph['filename']=$g->getElementsByTagName('bgFileName')->item(0)->nodeValue;
$this->graph['filedesc']='thumbnail';
$this->graph['filetype']=$g->getElementsByTagName('bgFileType')->item(0)->nodeValue;
@$this->graph['filetype']=$g->getElementsByTagName('bgFileType')->item(0)->nodeValue;
}
}
}