专题更新时不更新未提交的数据
This commit is contained in:
parent
f6d73b8767
commit
4fa4a3ffee
|
@ -7,6 +7,7 @@
|
||||||
//当前运行用户的id号
|
//当前运行用户的id号
|
||||||
public $userid=3144;
|
public $userid=3144;
|
||||||
public $versionTable='en.mdversion';
|
public $versionTable='en.mdversion';
|
||||||
|
public $statusTable='en.mdstatus';
|
||||||
public $changelog='update the translation';
|
public $changelog='update the translation';
|
||||||
public $db=array('host'=>'localhost','user'=>'gis','password'=>'gispassword','dbname'=>'metadata');
|
public $db=array('host'=>'localhost','user'=>'gis','password'=>'gispassword','dbname'=>'metadata');
|
||||||
}
|
}
|
128
update.php
128
update.php
|
@ -1,128 +0,0 @@
|
||||||
<?php
|
|
||||||
class Version
|
|
||||||
{
|
|
||||||
private $db;
|
|
||||||
private $changelog;
|
|
||||||
private $err;
|
|
||||||
private $userid;
|
|
||||||
|
|
||||||
//初始化
|
|
||||||
function __construct($config)
|
|
||||||
{
|
|
||||||
//$this->db=$config->db;
|
|
||||||
$this->versionTable=$config->versionTable;
|
|
||||||
$this->changelog=$config->changelog;
|
|
||||||
$this->db = pg_connect("dbname=metadata user=gis password=gispassword host=210.77.68.241");
|
|
||||||
$this->err=array();
|
|
||||||
$this->userid=$config->userid;
|
|
||||||
}
|
|
||||||
|
|
||||||
function __destruct()
|
|
||||||
{
|
|
||||||
pg_close($link);
|
|
||||||
}
|
|
||||||
|
|
||||||
//版本更新:指定versionid
|
|
||||||
function update($uuid,$versionid,$changelog)
|
|
||||||
{
|
|
||||||
// 1. 保存变化记录 save changelog & userid
|
|
||||||
$sql = "UPDATE {$this->versionTable} SET changelog='$changelog',userid=$this->userid WHERE id=$versionid and uuid='$uuid'";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
|
|
||||||
// 2. 同步元数据
|
|
||||||
$sql = "select xml from {$this->versionTable} where id=$versionid and uuid='$uuid'";
|
|
||||||
$result=pg_query($this->db,$sql);
|
|
||||||
$row = pg_fetch_row($result);
|
|
||||||
$iso=new ISO19115();
|
|
||||||
@$iso->loadXML($row[0]);
|
|
||||||
if ($iso->validate())
|
|
||||||
{
|
|
||||||
$this->err[]="元数据: ".$uuid." 导入过程中发现错误。<br />".implode("<br />",$iso->error);
|
|
||||||
}
|
|
||||||
@$iso->saveDB($this->db);
|
|
||||||
|
|
||||||
// 3. 移除中间版本
|
|
||||||
$sql="delete from {$this->versionTable} where uuid='$uuid' and changelog is null";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
pg_free_result($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//版本更新:以最新的一个版本进行更新
|
|
||||||
function update($uuid,$changelog)
|
|
||||||
{
|
|
||||||
// 1. 保存变化记录 save changelog & userid
|
|
||||||
$sql = "UPDATE {$this->versionTable} SET changelog='$changelog',userid=$this->userid WHERE id in (select id from {$this->versionTable} where uuid='$uuid' order by ts_created desc limit 1)";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
|
|
||||||
// 2. 同步元数据
|
|
||||||
$sql = "select xml from {$this->versionTable} where uuid='$uuid' order by ts_created desc limit 1";
|
|
||||||
$result=pg_query($this->db,$sql);
|
|
||||||
$row = pg_fetch_row($result);
|
|
||||||
$iso=new ISO19115();
|
|
||||||
@$iso->loadXML($row[0]);
|
|
||||||
if ($iso->validate())
|
|
||||||
{
|
|
||||||
$this->err[]="元数据: ".$uuid." 导入过程中发现错误。<br />".implode("<br />",$iso->error);
|
|
||||||
}
|
|
||||||
@$iso->saveDB($this->db);
|
|
||||||
|
|
||||||
// 3. 移除中间版本
|
|
||||||
$sql="delete from {$this->versionTable} where uuid='$uuid' and changelog is null";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
pg_free_result($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//专题更新:将指定专题的数据,全部按照最新版本进行更新
|
|
||||||
function update_by_source($sourceid,$changelog)
|
|
||||||
{
|
|
||||||
// 1. 保存变化记录 save changelog & userid
|
|
||||||
$sql = "UPDATE {$this->versionTable} SET changelog='$changelog',userid=$this->userid WHERE id in (
|
|
||||||
select distinct on (uuid) id from {$this->versionTable} where uuid in (select uuid from datasource where sourceid=$sourceid) order by uuid,ts_created desc
|
|
||||||
)";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
|
|
||||||
// 2. 同步元数据
|
|
||||||
$sql = "select xml from {$this->versionTable} WHERE id in (
|
|
||||||
select distinct on (uuid) id from {$this->versionTable} where uuid in (select uuid from datasource where sourceid=$sourceid) order by uuid,ts_created desc
|
|
||||||
)";
|
|
||||||
$result=pg_query($this->db,$sql);
|
|
||||||
while ($row = pg_fetch_row($result))
|
|
||||||
{
|
|
||||||
$iso=new ISO19115();
|
|
||||||
@$iso->loadXML($row[0]);
|
|
||||||
if ($iso->validate())
|
|
||||||
{
|
|
||||||
$this->err[]="元数据: ".$uuid." 导入过程中发现错误。<br />".implode("<br />",$iso->error);
|
|
||||||
}
|
|
||||||
@$iso->saveDB($this->db);
|
|
||||||
}
|
|
||||||
// 3. 移除中间版本
|
|
||||||
$sql="delete from {$this->versionTable} where uuid in (select distinct uuid from datasource where sourceid=$sourceid) and changelog is null";
|
|
||||||
pg_query($this->db,$sql);
|
|
||||||
pg_free_result($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//版本删除
|
|
||||||
function delete($uuid,$versionid)
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM {$this->versionTable} WHERE uuid='$uuid' and id=$versionid";
|
|
||||||
return pg_query($this->db, $sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
//todo: 版本直接发布(仅发布之前为评审状态的数据)
|
|
||||||
function release($uuid,$versionid)
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
$sql = "SELECT s.*,v.xml,m.title FROM en.mdstatus s left join en.mdversion v on s.uuid=v.uuid
|
|
||||||
left join en.metadata m on s.uuid=m.uuid WHERE v.id=?";
|
|
||||||
return pg_query($this->db,$sql);
|
|
||||||
}
|
|
||||||
function release($uuid)
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
function release_by_source($sourceid)
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,6 +12,7 @@
|
||||||
{
|
{
|
||||||
//$this->db=$config->db;
|
//$this->db=$config->db;
|
||||||
$this->versionTable=$config->versionTable;
|
$this->versionTable=$config->versionTable;
|
||||||
|
$this->statusTable=$config->statusTable;
|
||||||
$this->changelog=$config->changelog;
|
$this->changelog=$config->changelog;
|
||||||
$this->db = pg_connect(http_build_query($config->db,'',' '));
|
$this->db = pg_connect(http_build_query($config->db,'',' '));
|
||||||
$this->err=array();
|
$this->err=array();
|
||||||
|
@ -81,7 +82,8 @@
|
||||||
if (!$changelog) $changelog=$this->changelog;
|
if (!$changelog) $changelog=$this->changelog;
|
||||||
// 1. 保存变化记录 save changelog & userid
|
// 1. 保存变化记录 save changelog & userid
|
||||||
$sql = "UPDATE {$this->versionTable} SET changelog='$changelog',userid=$this->userid WHERE id in (
|
$sql = "UPDATE {$this->versionTable} SET changelog='$changelog',userid=$this->userid WHERE id in (
|
||||||
select distinct on (uuid) id from {$this->versionTable} where uuid in (select uuid from datasource where sourceid=$sourceid) order by uuid,ts_created desc
|
select distinct on (uuid) id from {$this->versionTable} where uuid in (select uuid from datasource where sourceid=$sourceid)
|
||||||
|
and uuid in (select distinct uuid from {$this->statusTable}) order by uuid,ts_created desc
|
||||||
)";
|
)";
|
||||||
pg_query($this->db,$sql);
|
pg_query($this->db,$sql);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue