增加同步时间判断
This commit is contained in:
parent
827673bb3f
commit
2e568a7cab
|
@ -1,170 +1,177 @@
|
|||
<?php
|
||||
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;
|
||||
use Westdc\MetadataSync\SyncPluginInterface;
|
||||
|
||||
class Qinghaihu implements SyncPluginInterface
|
||||
{
|
||||
private $db; //传入PDO对象
|
||||
private $target; //目标数据库
|
||||
private $table;
|
||||
|
||||
public $url = "http://deep.qherc.org"; //outlink表中得链接
|
||||
public $last_sync;
|
||||
public $source_type;
|
||||
public $data;
|
||||
|
||||
protected $events = NULL;
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
new Db($this->target);
|
||||
//$this->target = new PDO;
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try{
|
||||
$ol = new \Westdc\Metadata\Outlink;
|
||||
$ol->opt->limit = 1;
|
||||
$ol->opt->order = "ol.ts_created";
|
||||
$ol->opt->sort = "DESC";
|
||||
$ol->opt->where = array("ol.host='{$this->url}'");
|
||||
$row = $ol->fetchAllOutlink();
|
||||
|
||||
if(isset($row['ts_created']))
|
||||
{
|
||||
$this->last_sync = $row['ts_created'];
|
||||
}else{
|
||||
$this->last_sync = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sync()
|
||||
{
|
||||
$this->getMetadataFromSource();
|
||||
|
||||
return $this->processData();
|
||||
|
||||
if(isset($this->last_sync))
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function processData()
|
||||
{
|
||||
if($this->source_type == "dataTable")
|
||||
{
|
||||
return $this->processDataFromDataTable();
|
||||
}
|
||||
|
||||
if($this->source_type == "xml")
|
||||
{
|
||||
return $this->processDataFromXmlDocument();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMetadataFromSource()
|
||||
{
|
||||
$sql = "SELECT * FROM xml";
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
$this->data = $rs->fetchAll();
|
||||
|
||||
$this->source_type = "xml";
|
||||
}
|
||||
|
||||
public function processDataFromXmlDocument()
|
||||
{
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$isoxml = new \Westdc\MetadataXml\ISO19115;
|
||||
$isoxml->saveDB($this->target,$v['data']);
|
||||
|
||||
$this->insertToMdoutlink($isoxml->uuid);
|
||||
$this->insertToThumbnail($v['id']);
|
||||
|
||||
unset($isoxml);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function processDataFromDataTable()
|
||||
{
|
||||
|
||||
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$data = array(
|
||||
'uuid' => $v['uuid'],
|
||||
'title' => $v['title'],
|
||||
'description' => $v['description'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//写入 mdoutlink表
|
||||
public function insertToMdoutlink($uuid)
|
||||
{
|
||||
$sql = "DELETE FROM mdoutlink WHERE uuid=?";
|
||||
$rs = $this->target->query($sql,array($uuid));
|
||||
|
||||
$data = array(
|
||||
'uuid' => $uuid,
|
||||
'url' => $this->url."/data/".$uuid,
|
||||
'status' => 1,
|
||||
'host' => $this->url
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("mdoutlink",$data);
|
||||
}
|
||||
|
||||
//读取缩略图并写入 thumbnail
|
||||
public function insertToThumbnail($id)
|
||||
{
|
||||
$sql = "SELECT * FROM thumbnail WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if($row)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $row['id'],
|
||||
'data' => $row['data'],
|
||||
'filetype' => $row['filetype'],
|
||||
'filename' => $row['filename'],
|
||||
'filedesc' => $row['filedesc']
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("thumbnail",$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
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;
|
||||
use Westdc\MetadataSync\SyncPluginInterface;
|
||||
|
||||
class Qinghaihu implements SyncPluginInterface
|
||||
{
|
||||
private $db; //传入PDO对象
|
||||
private $target; //目标数据库
|
||||
private $table;
|
||||
|
||||
public $url = "http://deep.qherc.org"; //outlink表中得链接
|
||||
public $last_sync;
|
||||
public $source_type;
|
||||
public $data;
|
||||
|
||||
protected $events = NULL;
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
new Db($this->target);
|
||||
//$this->target = new PDO;
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try{
|
||||
$ol = new \Westdc\Metadata\Outlink;
|
||||
$ol->opt->limit = 1;
|
||||
$ol->opt->order = "ol.ts_created";
|
||||
$ol->opt->sort = "DESC";
|
||||
$ol->opt->where = array("ol.host='{$this->url}'");
|
||||
$row = $ol->fetchAllOutlink();
|
||||
|
||||
if(isset($row['ts_created']))
|
||||
{
|
||||
$this->last_sync = $row['ts_created'];
|
||||
}else{
|
||||
$this->last_sync = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sync()
|
||||
{
|
||||
$this->getMetadataFromSource();
|
||||
|
||||
return $this->processData();
|
||||
|
||||
if(isset($this->last_sync))
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function processData()
|
||||
{
|
||||
if($this->source_type == "dataTable")
|
||||
{
|
||||
return $this->processDataFromDataTable();
|
||||
}
|
||||
|
||||
if($this->source_type == "xml")
|
||||
{
|
||||
return $this->processDataFromXmlDocument();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMetadataFromSource()
|
||||
{
|
||||
if(!empty($this->last_sync))
|
||||
{
|
||||
$sql = "SELECT x.* FROM xml x";
|
||||
}else{
|
||||
$sql = "SELECT x.* FROM xml x
|
||||
LEFT JOIN metadata m ON x.id=m.id
|
||||
WHERE m.ts_created > '{$this->last_sync}'";
|
||||
}
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
$this->data = $rs->fetchAll();
|
||||
|
||||
$this->source_type = "xml";
|
||||
}
|
||||
|
||||
public function processDataFromXmlDocument()
|
||||
{
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$isoxml = new \Westdc\MetadataXml\ISO19115;
|
||||
$isoxml->saveDB($this->target,$v['data']);
|
||||
|
||||
$this->insertToMdoutlink($isoxml->uuid);
|
||||
$this->insertToThumbnail($v['id']);
|
||||
|
||||
unset($isoxml);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function processDataFromDataTable()
|
||||
{
|
||||
|
||||
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$data = array(
|
||||
'uuid' => $v['uuid'],
|
||||
'title' => $v['title'],
|
||||
'description' => $v['description'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//写入 mdoutlink表
|
||||
public function insertToMdoutlink($uuid)
|
||||
{
|
||||
$sql = "DELETE FROM mdoutlink WHERE uuid=?";
|
||||
$rs = $this->target->query($sql,array($uuid));
|
||||
|
||||
$data = array(
|
||||
'uuid' => $uuid,
|
||||
'url' => $this->url."/data/".$uuid,
|
||||
'status' => 1,
|
||||
'host' => $this->url
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("mdoutlink",$data);
|
||||
}
|
||||
|
||||
//读取缩略图并写入 thumbnail
|
||||
public function insertToThumbnail($id)
|
||||
{
|
||||
$sql = "SELECT * FROM thumbnail WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if($row)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $row['id'],
|
||||
'data' => $row['data'],
|
||||
'filetype' => $row['filetype'],
|
||||
'filename' => $row['filename'],
|
||||
'filedesc' => $row['filedesc']
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("thumbnail",$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,150 +1,158 @@
|
|||
<?php
|
||||
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;
|
||||
use Westdc\MetadataSync\SyncPluginInterface;
|
||||
|
||||
class Sanjiangyuan implements SyncPluginInterface
|
||||
{
|
||||
private $db; //传入PDO对象
|
||||
private $table;
|
||||
|
||||
public $url = "http://www.sanjiangyuan.org.cn"; //outlink表中得链接
|
||||
public $last_sync;
|
||||
public $source_type;
|
||||
public $data;
|
||||
|
||||
protected $events = NULL;
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
new Db($this->target);
|
||||
ini_set("max_execution_time",600);
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try{
|
||||
$ol = new \Westdc\Metadata\Outlink;
|
||||
$ol->opt->limit = 1;
|
||||
$ol->opt->order = "ol.ts_created";
|
||||
$ol->opt->sort = "DESC";
|
||||
$ol->opt->where = array("ol.host='{$this->url}'");
|
||||
$row = $ol->fetchAllOutlink();
|
||||
|
||||
if(isset($row['ts_created']))
|
||||
{
|
||||
$this->last_sync = $row['ts_created'];
|
||||
}else{
|
||||
$this->last_sync = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sync()
|
||||
{
|
||||
$this->getMetadataFromSource();
|
||||
|
||||
return $this->processData();
|
||||
|
||||
if(isset($this->last_sync))
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function processData()
|
||||
{
|
||||
if($this->source_type == "dataTable")
|
||||
{
|
||||
return $this->processDataFromDataTable();
|
||||
}
|
||||
|
||||
if($this->source_type == "xml")
|
||||
{
|
||||
return $this->processDataFromXmlDocument();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMetadataFromSource()
|
||||
{
|
||||
$sql = "SELECT * FROM xml where id in (select id from normalmetadata)";
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
$this->data = $rs->fetchAll();
|
||||
|
||||
$this->source_type = "xml";
|
||||
}
|
||||
|
||||
public function processDataFromXmlDocument()
|
||||
{
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$isoxml = new \Westdc\MetadataXml\ISO19115;
|
||||
$isoxml->saveDB($this->target,$v['data']);
|
||||
|
||||
$this->insertToMdoutlink($isoxml->uuid);
|
||||
$this->insertToThumbnail($v['id'],$isoxml->id);
|
||||
|
||||
unset($isoxml);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//写入 mdoutlink表
|
||||
public function insertToMdoutlink($uuid)
|
||||
{
|
||||
$sql = "DELETE FROM mdoutlink WHERE uuid=?";
|
||||
$rs = $this->target->query($sql,array($uuid));
|
||||
|
||||
$data = array(
|
||||
'uuid' => $uuid,
|
||||
'url' => $this->url."/data/".$uuid,
|
||||
'status' => 1,
|
||||
'host' => $this->url
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("mdoutlink",$data);
|
||||
}
|
||||
|
||||
//读取缩略图并写入 thumbnail
|
||||
public function insertToThumbnail($id,$mid)
|
||||
{
|
||||
$sql = "SELECT * FROM thumbnail WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if($row)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $mid,
|
||||
'data' => $row['data'],
|
||||
'filetype' => $row['filetype'],
|
||||
'filename' => $row['filename'],
|
||||
'filedesc' => $row['filedesc']
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("thumbnail",$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
<?php
|
||||
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;
|
||||
use Westdc\MetadataSync\SyncPluginInterface;
|
||||
|
||||
class Sanjiangyuan implements SyncPluginInterface
|
||||
{
|
||||
private $db; //传入PDO对象
|
||||
private $table;
|
||||
|
||||
public $url = "http://www.sanjiangyuan.org.cn"; //outlink表中得链接
|
||||
public $last_sync;
|
||||
public $source_type;
|
||||
public $data;
|
||||
|
||||
protected $events = NULL;
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
new Db($this->target);
|
||||
ini_set("max_execution_time",600);
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try{
|
||||
$ol = new \Westdc\Metadata\Outlink;
|
||||
$ol->opt->limit = 1;
|
||||
$ol->opt->order = "ol.ts_created";
|
||||
$ol->opt->sort = "DESC";
|
||||
$ol->opt->where = array("ol.host='{$this->url}'");
|
||||
$row = $ol->fetchAllOutlink();
|
||||
|
||||
if(isset($row['ts_created']))
|
||||
{
|
||||
$this->last_sync = $row['ts_created'];
|
||||
}else{
|
||||
$this->last_sync = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sync()
|
||||
{
|
||||
$this->getMetadataFromSource();
|
||||
|
||||
return $this->processData();
|
||||
|
||||
if(isset($this->last_sync))
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function processData()
|
||||
{
|
||||
if($this->source_type == "dataTable")
|
||||
{
|
||||
return $this->processDataFromDataTable();
|
||||
}
|
||||
|
||||
if($this->source_type == "xml")
|
||||
{
|
||||
return $this->processDataFromXmlDocument();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMetadataFromSource()
|
||||
{
|
||||
if(!empty($this->last_sync))
|
||||
{
|
||||
$sql = "SELECT * FROM xml where id in (select id from normalmetadata)";
|
||||
}else{
|
||||
$sql = "SELECT x.* FROM xml x
|
||||
LEFT JOIN metadata m ON x.id=m.id
|
||||
WHERE m.ts_created > '{$this->last_sync}' AND m.id in (select id from normalmetadata)";
|
||||
}
|
||||
$sql = "SELECT * FROM xml where id in (select id from normalmetadata)";
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
$this->data = $rs->fetchAll();
|
||||
|
||||
$this->source_type = "xml";
|
||||
}
|
||||
|
||||
public function processDataFromXmlDocument()
|
||||
{
|
||||
foreach($this->data as $k=>$v)
|
||||
{
|
||||
$isoxml = new \Westdc\MetadataXml\ISO19115;
|
||||
$isoxml->saveDB($this->target,$v['data']);
|
||||
|
||||
$this->insertToMdoutlink($isoxml->uuid);
|
||||
$this->insertToThumbnail($v['id'],$isoxml->id);
|
||||
|
||||
unset($isoxml);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//写入 mdoutlink表
|
||||
public function insertToMdoutlink($uuid)
|
||||
{
|
||||
$sql = "DELETE FROM mdoutlink WHERE uuid=?";
|
||||
$rs = $this->target->query($sql,array($uuid));
|
||||
|
||||
$data = array(
|
||||
'uuid' => $uuid,
|
||||
'url' => $this->url."/data/".$uuid,
|
||||
'status' => 1,
|
||||
'host' => $this->url
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("mdoutlink",$data);
|
||||
}
|
||||
|
||||
//读取缩略图并写入 thumbnail
|
||||
public function insertToThumbnail($id,$mid)
|
||||
{
|
||||
$sql = "SELECT * FROM thumbnail WHERE id=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if($row)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $mid,
|
||||
'data' => $row['data'],
|
||||
'filetype' => $row['filetype'],
|
||||
'filename' => $row['filename'],
|
||||
'filedesc' => $row['filedesc']
|
||||
);
|
||||
$dbh = new dbh();
|
||||
$dbh->insert("thumbnail",$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue