fix sql error

This commit is contained in:
wlx 2013-11-10 09:46:59 +00:00
parent a6fd1f9874
commit 29087d0e99
1 changed files with 33 additions and 33 deletions

View File

@ -33,7 +33,7 @@ class Admin_DataController extends Zend_Controller_Action
function syncAction()
{
set_time_limit(0);
$sql="select * from (select count(*) as westdccount from en.metadata) as t1,(select count(uuid) as gncount from geonetworken.metadata where schemaid='iso19115') as t2";
$sql="select * from (select count(*) as westdccount from en.metadata) as t1,(select count(uuid) as gncount from en.geonetworkmetadata where schemaid='iso19115') as t2";
$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$this->view->mdcount=$this->db->fetchRow($sql);
$source=$this->_request->getParam('source');
@ -46,10 +46,10 @@ class Admin_DataController extends Zend_Controller_Action
//从geonetwork向WESTDC同步
//对所有的新数据增加评审状态
$sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),?
from geonetworken.metadata gn where uuid not in (select uuid from mdstatus)";
from en.geonetworkmetadata gn where uuid not in (select uuid from mdstatus)";
$userid = Zend_Auth::getInstance()->getIdentity()->id;
$this->db->query($sql,array($userid));
$sql="select uuid,data,source from geonetworken.metadata where schemaid='iso19115'";
$sql="select uuid,data,source from en.geonetworkmetadata where schemaid='iso19115'";
$rs=$this->db->fetchAll($sql);
foreach($rs as $gmd) {
$this->import($gmd->data);
@ -88,7 +88,7 @@ class Admin_DataController extends Zend_Controller_Action
$userid = Zend_Auth::getInstance()->getIdentity()->id;
$this->db->query($sql,array($userid));*/
//同步专题元数据
$sql="select uuid,data,source from geonetworken.metadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')";
$sql="select uuid,data,source from en.geonetworkmetadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')";
$rs=$this->db->fetchAll($sql);
foreach($rs as $gmd) {
$this->import($gmd->data);
@ -98,27 +98,27 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->msg='成功同步专题元数据!';
} elseif ($source=="westdc" && empty($uuid) ) {
//从westdc向geonetwork同步
$sql="select m.uuid,m.source,x.data from en.metadata m left join xml x on m.id=x.id where m.uuid not in (select uuid from geonetworken.metadata)";
$sql="select m.uuid,m.source,x.data from en.metadata m left join xml x on m.id=x.id where m.uuid not in (select uuid from en.geonetworkmetadata)";
$rs=$this->db->fetchAll($sql);
foreach($rs as $gmd) {
$sql="insert into geonetworken.metadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")";
$sql="insert into en.geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")";
$this->db->exec($sql);
}
$sql="select m.uuid,m.source,x.data from en.metadata m left join xml x on m.id=x.id where m.uuid in (select uuid from geonetworken.metadata)";
$sql="select m.uuid,m.source,x.data from en.metadata m left join xml x on m.id=x.id where m.uuid in (select uuid from en.geonetworkmetadata)";
$rs=$this->db->fetchAll($sql);
foreach($rs as $gmd) {
$sql="update geonetworken.metadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'";
$sql="update en.geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'";
$this->db->exec($sql);
}
$this->view->msg='成功同步WESTDC元数据到GEONETWORK';
} elseif (!empty($uuid) && isset($_POST['gnsubmit'])) {
//同步单条元数据到geonetwork
$sql=$this->db->quoteInto("select m.uuid,m.source,x.data,g.id from en.metadata m left join xml x on m.id=x.id left join geonetworken.metadata g on g.uuid=m.uuid where m.uuid=?",$uuid);
$sql=$this->db->quoteInto("select m.uuid,m.source,x.data,g.id from en.metadata m left join xml x on m.id=x.id left join en.geonetworkmetadata g on g.uuid=m.uuid where m.uuid=?",$uuid);
if ($gmd=$this->db->fetchRow($sql)) {
if (!empty($gmd->id)) {
$sql="update geonetworken.metadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'";
$sql="update en.geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'";
} else {
$sql="insert into geonetworken.metadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")";
$sql="insert into en.geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")";
}
$this->db->exec($sql);
$this->view->msg='成功同步元数据:'.$uuid;
@ -132,32 +132,32 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->msg='成功同步元数据:'.$uuid;
} else $this->view->msg='不存在此元数据:'.$uuid;
} elseif ($list=='westdc') {
$sql="select uuid,title from en.metadata where uuid not in (select uuid from geonetworken.metadata where schemaid='iso19115')";
$sql="select uuid,title from en.metadata where uuid not in (select uuid from en.geonetworkmetadata where schemaid='iso19115')";
$this->view->metadata=$this->db->query($sql);
} elseif ($list=='geonetwork') {
$sql="select id,uuid,(regexp_matches(data,'<resTitle>(.*)</resTitle>'))[1] as title from geonetworken.metadata
$sql="select id,uuid,(regexp_matches(data,'<resTitle>(.*)</resTitle>'))[1] as title from en.geonetworkmetadata
where uuid not in (select uuid from en.metadata)";
$this->view->metadata=$this->db->query($sql);
} elseif ($delete=='westdc') {
$sql="delete from en.metadata where uuid not in (select uuid from geonetworken.metadata where schemaid='iso19115')";
$sql="delete from en.metadata where uuid not in (select uuid from en.geonetworkmetadata where schemaid='iso19115')";
$this->db->query($sql);
$this->view->msg='已删除WESTDC中多出的元数据';
} elseif ($delete=='geonetwork') {
//dblink view中删除多条有问题暂时用单条删除替代
//$sql="delete from geonetworken.metadata where uuid not in (select uuid from en.metadata)";
$sql="select uuid from geonetworken.metadata where uuid not in (select uuid from en.metadata)";
//$sql="delete from en.geonetworkmetadata where uuid not in (select uuid from en.metadata)";
$sql="select uuid from en.geonetworkmetadata where uuid not in (select uuid from en.metadata)";
$rows=$this->db->fetchAll($sql);
foreach($rows as $row)
{
$this->db->exec($this->db->quoteInto("delete from geonetworken.metadata where uuid=?",$row->uuid));
$this->db->exec($this->db->quoteInto("delete from en.geonetworkmetadata where uuid=?",$row->uuid));
}
$this->view->msg='已删除GEONETWORK中多出的元数据';
} elseif ($delete=='water') {
$sql="delete from en.metadata where uuid not in (select uuid from watergn where schemaid='iso19115') and uuid not in (select uuid from geonetworken.metadata where schemaid='iso19115')";
$sql="delete from en.metadata where uuid not in (select uuid from watergn where schemaid='iso19115') and uuid not in (select uuid from en.geonetworkmetadata where schemaid='iso19115')";
$this->db->query($sql);
$this->view->msg='已删除WESTDC中多出的元数据';
} elseif ($thumb=='geonetwork') {
$sql="select g.id as gid,m.uuid,t.* from thumbnail t left join en.metadata m on t.id=m.id left join geonetworken.metadata g on m.uuid=g.uuid where t.filetype is not null and t.filename is not null";
$sql="select g.id as gid,m.uuid,t.* from thumbnail t left join en.metadata m on t.id=m.id left join en.geonetworkmetadata g on m.uuid=g.uuid where t.filetype is not null and t.filename is not null";
$rows=$this->db->fetchAll($sql);
foreach($rows as $row) {
$data=file_get_contents($this->view->config->geonetwork->url.'srv/cn/resources.get?access=public&id='.$row->gid.'&fname='.urlencode($row->filename));
@ -191,13 +191,13 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->msg='已成功同步帐号!';
} elseif (!empty($uuid) && (isset($_POST['submit']) || (!isset($_POST['gnsubmit']) && !isset($_POST['watersubmit'])))) {
//同步单条元数据
$sql=$this->db->quoteInto("select data,source from geonetworken.metadata where uuid=?",$uuid);
$sql=$this->db->quoteInto("select data,source from en.geonetworkmetadata where uuid=?",$uuid);
if ($rs=$this->db->fetchRow($sql)) {
$this->import($rs->data);
$this->db->exec($this->db->quoteInto("update en.metadata set source=? where uuid='$uuid'",$rs->source));
$userid = Zend_Auth::getInstance()->getIdentity()->id;
$this->db->query("insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),?
from geonetworken.metadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid));
from en.geonetworkmetadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid));
$this->view->msg='成功同步元数据:'.$uuid;
//update search document
$search=new Search();
@ -411,7 +411,7 @@ class Admin_DataController extends Zend_Controller_Action
//查询需要创建的文件
$sql = "SELECT md.title,md.uuid,x.* from xml x
LEFT JOIN normalen.metadata md ON md.id=x.id";
LEFT JOIN en.normalmetadata md ON md.id=x.id";
$sth = $this->db->prepare($sql);
$sth->execute();
@ -471,7 +471,7 @@ class Admin_DataController extends Zend_Controller_Action
{
$sql = "select m.*,md.viewed,g.id as gid, ds.id as datasetid from en.metadata m
left join mdstat md on m.uuid=md.uuid
left join geonetworken.metadata g on g.uuid=m.uuid
left join en.geonetworkmetadata g on g.uuid=m.uuid
left join dataset ds on m.uuid=ds.uuid
where m.title like '%$keyword%'
order by m.id desc
@ -498,7 +498,7 @@ class Admin_DataController extends Zend_Controller_Action
$sql = "SELECT md.*,s.viewed,g.id as gid,st.status as mdstatus,ds.id as datasetid FROM en.metadata md
LEFT JOIN mdstat s ON md.uuid=s.uuid
LEFT JOIN geonetworkmetadata g ON g.uuid=md.uuid
LEFT JOIN en.geonetworkmetadata g ON g.uuid=md.uuid
LEFT JOIN mdstatus st ON md.uuid=st.uuid
LEFT JOIN dataset ds ON md.uuid=ds.uuid
ORDER BY md.id DESC";
@ -2325,7 +2325,7 @@ class Admin_DataController extends Zend_Controller_Action
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname,g.id as gid FROM mdversion v
LEFT JOIN en.metadata md ON md.uuid=v.uuid
left join users u on v.userid=u.id
left join geonetworken.metadata g on md.uuid=g.uuid
left join en.geonetworkmetadata g on md.uuid=g.uuid
WHERE md.title IS NOT NULL AND v.uuid=?
order by v.ts_created desc
";
@ -3201,7 +3201,7 @@ class Admin_DataController extends Zend_Controller_Action
//查看所有的未提交数据列表
else if((empty($ac) && empty($uuid))|| $ac=='list')
{
$sql = "SELECT (regexp_matches(gn.data,'<resTitle>(.*)</resTitle>'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM geonetworken.metadata gn left join users u on gn.owner=u.id
$sql = "SELECT (regexp_matches(gn.data,'<resTitle>(.*)</resTitle>'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM en.geonetworkmetadata gn left join users u on gn.owner=u.id
WHERE gn.uuid not in (select uuid from en.metadata)
order by gn.id desc
";
@ -3251,8 +3251,8 @@ class Admin_DataController extends Zend_Controller_Action
else if($ac=="add-by-data")
{
$keywords = $this->_request->getParam('q');
$sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalen.metadata md
left join geonetworken.metadata gn on md.uuid=gn.uuid
$sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM en.normalmetadata md
left join en.geonetworkmetadata gn on md.uuid=gn.uuid
WHERE gn.id is not null";
if(!empty($keywords))
{
@ -3282,7 +3282,7 @@ class Admin_DataController extends Zend_Controller_Action
$data = "";
$id = $this->_request->getParam('id');
$sql="select uuid,data from geonetworken.metadata where id=?";
$sql="select uuid,data from en.geonetworkmetadata where id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($id));
$row=$sth->fetch();
@ -3326,7 +3326,7 @@ class Admin_DataController extends Zend_Controller_Action
// 1. 权限认定当前用户必须和其owner相同
// 数据应当没有评审状态,没有作者信息
$sql="select uuid,data from geonetworken.metadata where id=?";
$sql="select uuid,data from en.geonetworkmetadata where id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($id));
$row=$sth->fetch();
@ -3340,7 +3340,7 @@ class Admin_DataController extends Zend_Controller_Action
// 保存数据作者信息
// 2. 保存变化记录 save changelog & userid for the latest version
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join geonetworken.metadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)";
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join en.geonetworkmetadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)";
$this->db->query($sql,array($changelog,$u_id,$id));
// 3. 保存数据评审状态
@ -3348,7 +3348,7 @@ class Admin_DataController extends Zend_Controller_Action
$iso=new ISO19115();
@$iso->saveDB($this->db,$row['data']);
//进入评审库
$sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworken.metadata where id=?";
$sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from en.geonetworkmetadata where id=?";
$this->db->query($sql,array($u_id,$id));
//email to admin
$mail=new WestdcMailer($this->view->config->smtp);
@ -3374,7 +3374,7 @@ class Admin_DataController extends Zend_Controller_Action
$this->jsonexit($data);
return true;
}catch(Exception $e) {
$sql="delete from mdstatus where uuid in (select uuid from geonetworken.metadata where id=?)";
$sql="delete from mdstatus where uuid in (select uuid from en.geonetworkmetadata where id=?)";
$this->db->query($sql,array($id));
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)