#318 数据版本管理功能

This commit is contained in:
Li Jianxuan 2012-03-27 10:17:51 +00:00
parent 564bd16bd6
commit e1f261d61f
2 changed files with 300 additions and 58 deletions

View File

@ -439,7 +439,7 @@ class AuthorController extends Zend_Controller_Action
if($ex)
{
include_once("EmailText.php");
include_once("EmailText.php");
$this->author_first($row['uuid'],$row['userid']);
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
@ -746,7 +746,7 @@ class AuthorController extends Zend_Controller_Action
$this ->getResponse()
->setHeader('Content-Type', 'application/json')
->appendBody(Zend_Json::encode($data));
exit();
return true;
}
@ -876,7 +876,7 @@ class AuthorController extends Zend_Controller_Action
$ex = $sth->execute(array($uuid,$u_id,'','now()',1));
if($ex)
{
$data = array("error"=>"您的身份符合申请条件,已经自动成为该元数据作者");
$data = array("error"=>"您的身份符合申请条件,已经自动成为该元数据作者");
$this->author_first($uuid,$u_id);
include_once("EmailText.php");
$mail=new WestdcMailer($this->view->config->smtp);
@ -1477,7 +1477,7 @@ class AuthorController extends Zend_Controller_Action
function versionAction()
{
$ac = $this->_request->getParam('ac');
$ac = $this->_request->getParam('ac');
$uuid = $this->_request->getParam('uuid');
$auth = Zend_Auth::getInstance();
@ -1486,20 +1486,21 @@ class AuthorController extends Zend_Controller_Action
$user = $auth->getIdentity();
$u_id = $user->id;
}
if (!empty($uuid) && empty($ac))
{
//view the versions of the data
//查看单条数据的所有版本
if (!empty($uuid) && empty($ac))
{
//view the versions of the data
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join users u on v.userid=u.id
WHERE md.title IS NOT NULL AND a.userid=? and v.uuid=?
order by v.ts_created desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id,$uuid));
$rows = $sth->fetchAll();
$rows = $sth->fetchAll();
@$this->view->mdtitle=$rows[0]['title'];
$paginator = Zend_Paginator::factory($rows);
@ -1507,13 +1508,15 @@ class AuthorController extends Zend_Controller_Action
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->view->paginator=$paginator;
}
//查看所有版本列表
else if((empty($ac) && empty($uuid))|| $ac=='list')
{
$sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
left join users u on v.userid=u.id
WHERE md.title IS NOT NULL AND a.userid=?
order by v.ts_created desc
@ -1530,23 +1533,25 @@ class AuthorController extends Zend_Controller_Action
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
//按数据浏览
else if($ac=="bydata")
{
{
$keywords = $this->_request->getParam('q');
if(!empty($keywords))
$this->view->q = $keywords;
$sql = "SELECT md.title,md.uuid,count(v.id) as c FROM mdversion v
LEFT JOIN metadata md ON md.uuid=v.uuid
LEFT JOIN mdauthor a ON md.uuid=a.uuid
WHERE md.title IS NOT NULL AND a.userid=?";
WHERE md.title IS NOT NULL AND a.userid=?";
if(!empty($keywords))
{
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" group by md.uuid,md.title";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
@ -1560,27 +1565,233 @@ class AuthorController extends Zend_Controller_Action
$this->_helper->viewRenderer('version-bydata');
}
}// versionAction() 数据版本管理
//成为作者后的后继处理工作
private function author_first($uuid,$author)
{
$sql="insert into mdversion (xml,ts_created,uuid,changelog,userid)
select x.data,m.ts_created,?,?,? from metadata m left join xml x on m.id=x.id
left join mdversion v on m.uuid=v.uuid
where m.uuid=? and v.changelog is null";
$sth=$this->db->prepare($sql);
try
{
$sth->execute(array($uuid,'初始版本 version 1.0',$author,$uuid));
} catch(Exception $e){
// do nothing here.
// 说明之前已经有对应数据
}
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$sql="update metadata set owner=? where uuid=?";
$sth=$this->wdb->prepare($sql);
$sth->execute(array($author,$uuid));
//删除某个版本
else if($ac=="delete")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
$sql = "DELETE FROM mdversion v
USING mdauthor a
WHERE v.id=? AND a.userid=?";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($id,$u_id));
if($ex)
{
$data = array("deleted"=>$id,"error"=>$this->alertbox('ok','删除成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}else{
$data = array("error"=>$this->alertbox('error','删除失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}catch(Exception $e) {
$msg = "删除失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}
//恢复到geonetwork
else if($ac == "restore")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
$db = Zend_Db::factory('Pdo_Pgsql', array(
'host' => 'localhost',
'username' => 'postgres',
'password' => '************************************',
'dbname' => 'geonetwork',
'persistent' => true
));
$sql = "SELECT v.xml,v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
WHERE v.id=? AND a.userid=?";
$sth = $this->db->prepare($sql);
$sth ->execute(array($id,$u_id));
$row = $sth->fetch();
$sql = "SELECT data FROM metadata WHERE uuid=?";
$sth = $db->prepare($sql);
$sth ->execute(array($row['uuid']));
$row_geo = $sth->fetch();
if($row['xml']==$row_geo['data'])
{
$data = array("error"=>$this->alertbox('warning','恢复失败,目前两个版本中的内容相同'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
$sql = "UPDATE metadata SET data=? WHERE uuid=?";
$sth = $db->prepare($sql);
$ex = $sth ->execute(array($row['xml'],$row['uuid']));
if($ex)
{
$data = array("error"=>$this->alertbox('ok','恢复成功'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}else{
$data = array("error"=>$this->alertbox('error','恢复失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}catch(Exception $e) {
$msg = "恢复失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}
//发布到评审
else if($ac == "commit")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
$sql = "SELECT * FROM mdstatus s
LEFT JOIN mdversion v ON v.uuid=s.uuid
LEFT JOIN mdauthor a ON a.uuid=v.uuid
WHERE v.id=? AND a.userid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($id,$u_id));
$row = $sth->fetch();
if(!empty($row['id']))
{
$data = array("error"=>$this->alertbox('warning','该数据已经在评审中,请勿重复提交'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
$sql = "SELECT v.uuid FROM mdversion v
LEFT JOIN mdauthor a ON a.uuid=v.uuid
WHERE v.id=? AND a.userid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($id,$u_id));
$row = $sth->fetch();
$sql = "INSERT INTO mdstatus (uuid,status,userid) VALUES (?,?,?)";
$sth = $this->db->prepare($sql);
$ex = $sth->execute(array($row['uuid'],1,$u_id));
if($ex)
{
$data = array("error"=>$this->alertbox('ok','提交成功!'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}else{
$data = array("error"=>$this->alertbox('error','提交失败,请确认权限后重试'));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}catch(Exception $e) {
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data));
return true;
}
}
}// versionAction() 数据版本管理
//成为作者后的后继处理工作
private function author_first($uuid,$author)
{
$sql="insert into mdversion (xml,ts_created,uuid,changelog,userid)
select x.data,m.ts_created,?,?,? from metadata m left join xml x on m.id=x.id
left join mdversion v on m.uuid=v.uuid
where m.uuid=? and v.changelog is null";
$sth=$this->db->prepare($sql);
try
{
$sth->execute(array($uuid,'初始版本 version 1.0',$author,$uuid));
} catch(Exception $e){
// do nothing here.
// 说明之前已经有对应数据
}
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$sql="update metadata set owner=? where uuid=?";
$sth=$this->wdb->prepare($sql);
$sth->execute(array($author,$uuid));
}
public function alertbox($type='',$body){
if($type == "error")
{
$img = '<img src="/images/alert_big_error.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if($type == "ok")
{
$img = '<img src="/images/alert_big_ok.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if($type == "warning")
{
$img = '<img src="/images/alert_big_warning.png" />';
$text = '<h4>'.$body.'</h4>';
return $img.$text;
}
if(empty($type))
{
$text = '<h4>'.$body.'</h4>';
return $text;
}
}
}

View File

@ -3,7 +3,9 @@ $this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据版本管理');
@ -21,34 +23,34 @@ $this->breadcrumb()->setSeparator(' > ');
<div id="wapper">
<div id="tabs-controller">
<ul>
<li class="box-shadow active"><a class="text-shadow" href="/author/version">所有版本概况</a></li>
<li class="box-shadow <?php if(!$this->mdtitle) echo "active";?>"><a class="text-shadow" href="/author/version">所有版本概况</a></li>
<li class="box-shadow"><a class="text-shadow" href="/author/version/ac/bydata">逐数据浏览</a></li>
</ul>
</div>
<div id="datalist">
<?php
if (count($this->paginator)):
if (count($this->paginator)):
if ($this->mdtitle) echo "<h2>元数据:".$this->mdtitle."</h2>";
echo "<ul>";
$autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<li>
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a>
<li id="list_<?php echo $item['id'];?>">
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a>
<a href="/author/version/uuid/<?php echo $item['uuid']; ?>">查看此数据所有版本</a></p>
<p>版本创建时间: <?php echo date("Y-m-d H:i",strtotime($item['ts_created']));?>
<?php if ($item['userid']) :
echo "发布人: ".(empty($item['realname'])?$item['username']:$item['realname'])." 【";
else :
?>
<a href="/author/version/ac/delete/id/<?php echo $item['id'];?>" class="more">删除</a>
<?php endif; ?>
<a href="/author/version/ac/restore/id/<?php echo $item['id'];?>" class="more">恢复到geonetwork</a>
<a href="/author/version/ac/diff/id/<?php echo $item['id'];?>" class="more">与前一版对比</a>
<a href="/author/version/ac/commit/id/<?php echo $item['id'];?>" class="more">提交评审发布</a>
</p>
<?php if ($item['changelog']) : ?>
<p><?php echo $item['changelog']; ?></p>
<p>版本创建时间: <?php echo date("Y-m-d H:i",strtotime($item['ts_created']));?>
<?php if ($item['userid']) :
echo "发布人: ".(empty($item['realname'])?$item['username']:$item['realname'])." 【";
else :
?>
<a onclick="return confirm('是否确定删除该版本?');" href="javascript:action('delete','<?php echo $item['id'];?>');" class="more">删除</a>
<?php endif; ?>
<a onclick="return confirm('是否确定将这个版本恢复到geonetwork');" href="javascript:action('restore','<?php echo $item['id'];?>');" class="more">恢复到geonetwork</a>
<a href="/author/version/ac/diff/id/<?php echo $item['id'];?>" class="more">与前一版对比</a>
<a onclick="return confirm('是否确定将该版本提交至评审发布?');" href="javascript:action('commit','<?php echo $item['id'];?>');" class="more">提交评审发布</a>
</p>
<?php if ($item['changelog']) : ?>
<p><?php echo $item['changelog']; ?></p>
<?php endif; ?>
</li>
<?php endforeach;
@ -60,4 +62,33 @@ $this->breadcrumb()->setSeparator(' > ');
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
</script>
function action(ac,id){
$.ajax({
'type':"POST",
'url':'/author/version/',
'data':'ac='+ ac +'&id='+id,
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{$.colorbox({'innerWidth':'50%','html':data.error});}
if(typeof(data.deleted)!='undefined')
{$('#list_'+data.deleted).fadeOut("slow",function(){$(this).remove();});}
}
else{
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_warning.png" /><h4>出现错误,请稍候再试</h4>'});
}
//$('#data_'+uuid).html('');
},
'timeout': 30000,
'error': function(){
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_error.png" /><h4>处理中出现错误,请刷新页面后重试</h4>'});
}
});
}
</script>
<div class="colorbox" style="display:none;">
<div class="error"><img src="/images/alert_big_error.png" /><span></span></div>
<div class="ok"><img src="/images/alert_big_ok.png" /><span></span></div>
<div class="warning"><img src="/images/alert_big_warning.png" /><span></span></div>
</div>