From c0ebcbfc8f2d99394f2aa8207cfcd079e22a9591 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 29 Jun 2015 16:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=83=E6=95=B0=E6=8D=AEsq?= =?UTF-8?q?l=E6=9F=A5=E8=AF=A2=E7=9A=84=E7=89=88=E6=9C=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=96=B9=E5=BC=8F=EF=BC=9B=E4=BF=AE=E5=A4=8D=E4=B8=93?= =?UTF-8?q?=E9=A2=98=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E4=B8=AD=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php | 2 ++ version.php | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/config.php b/config.php index 4a41cb8..1f46f8c 100644 --- a/config.php +++ b/config.php @@ -8,6 +8,8 @@ public $userid=3144; public $versionTable='en.mdversion'; public $statusTable='en.mdstatus'; + public $metadataTable="en.metadata"; + public $xmlTable="en.xml"; public $changelog='update the translation'; public $db=array('host'=>'localhost','user'=>'gis','password'=>'gispassword','dbname'=>'metadata'); } \ No newline at end of file diff --git a/version.php b/version.php index c0ecc44..5cf152d 100644 --- a/version.php +++ b/version.php @@ -13,6 +13,8 @@ //$this->db=$config->db; $this->versionTable=$config->versionTable; $this->statusTable=$config->statusTable; + $this->metadataTable=$config->metadataTable; + $this->xmlTable=$config->xmlTable; $this->changelog=$config->changelog; $this->db = pg_connect(http_build_query($config->db,'',' ')); $this->err=array(); @@ -84,13 +86,14 @@ $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) and uuid in (select distinct uuid from {$this->statusTable}) order by uuid,ts_created desc - )"; + ) and changelog is null"; 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 - )"; + 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 + ) and changelog is not null"; $result=pg_query($this->db,$sql); while ($row = pg_fetch_row($result)) { @@ -103,7 +106,42 @@ @$iso->saveDB($this->zend_db); } // 3. 移除中间版本 - $sql="delete from {$this->versionTable} where uuid in (select distinct uuid from datasource where sourceid=$sourceid) and changelog is null"; + $sql="delete from {$this->versionTable} where uuid in (select distinct uuid from datasource where sourceid=$sourceid) + and uuid in (select distinct uuid from {$this->statusTable}) and changelog is null"; + pg_query($this->db,$sql); + pg_free_result($result); + } + + // 更新符合SQL条件查询的所有数据的最新版本 + function update_by_sql($like,$changelog="") + { + if (!$changelog) $changelog=$this->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 distinct m.uuid from {$this->metadataTable} m left join {$this->xmlTable} x on m.id=x.id where x.xml like '%$like%') + and uuid in (select distinct uuid from {$this->statusTable}) order by uuid,ts_created desc + ) and changelog is null"; + 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 distinct m.uuid from {$this->metadataTable} m left join {$this->xmlTable} x on m.id=x.id where x.xml like '%$like%') + and uuid in (select distinct uuid from {$this->statusTable}) order by uuid,ts_created desc + ) and changelog is not null"; + $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." 导入过程中发现错误。\n".implode("\n",$iso->error); + } + @$iso->saveDB($this->zend_db); + } + // 3. 移除中间版本 + $sql="delete from {$this->versionTable} where uuid in (select distinct m.uuid from {$this->metadataTable} m left join {$this->xmlTable} x on m.id=x.id where x.xml like '%$like%') + and uuid in (select distinct uuid from {$this->statusTable}) and changelog is null"; pg_query($this->db,$sql); pg_free_result($result); }