From 66aeb02dc7f4d3fbc3abccddd51230de265c3651 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Mon, 22 Dec 2014 14:42:19 +0800 Subject: [PATCH] fixed a variable missing in AbstractEventManager,profection the Westdc\Metadata\Dataset --- Westdc/EventModel/AbstractEventManager.php | 2 + Westdc/Metadata/Dataset.php | 120 +++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/Westdc/EventModel/AbstractEventManager.php b/Westdc/EventModel/AbstractEventManager.php index 74357e5..7e1b051 100644 --- a/Westdc/EventModel/AbstractEventManager.php +++ b/Westdc/EventModel/AbstractEventManager.php @@ -14,6 +14,8 @@ use Zend\EventManager\EventManagerAwareInterface; abstract class AbstractEventManager { + protected $events; + public function setEventManager (EventManagerInterface $events) { $events->setIdentifiers(array( __CLASS__, diff --git a/Westdc/Metadata/Dataset.php b/Westdc/Metadata/Dataset.php index d0271bb..91c8728 100644 --- a/Westdc/Metadata/Dataset.php +++ b/Westdc/Metadata/Dataset.php @@ -34,6 +34,7 @@ class Dataset extends AbstractEventManager implements ServiceManagerAwareInterfa } /** + * 查询某个元数据的数据集信息(数据存储位置) * @param $uuid * @return mixed */ @@ -45,7 +46,126 @@ class Dataset extends AbstractEventManager implements ServiceManagerAwareInterfa return $sth->fetch(); } + /** + * + * @param $uuid + * @param $host + * @param $path + * @return bool|string + */ + public function record($uuid,$host,$path) + { + $tools = $this->serviceManager->get('Tools'); + + if( false == $tools->isUUID($uuid) ) + return "Invalid UUID"; + + $data = $this->fetch($uuid); + + if(isset($data['id']) && $data['id'] > 0) + return $this->update($uuid,$host,$path); + else + return $this->insert($uuid,$host,$path); + + } + + /** + * @param $uuid + * @param $host + * @param $path + * @return bool + */ + public function update($uuid,$host,$path) + { + $sql = "UPDATE dataset SET host='$host',path='$path' WHERE uuid='$uuid'"; + if($this->db->exec($sql) > 0) + { + $this->proftpUpload($uuid,$host); + $this->getEventManager()->trigger('dataset.update.success', $this, compact('uuid','host','path')); + return true; + }else{ + return false; + } + } + + /** + * @param $uuid + * @param $host + * @param $path + * @return bool + */ + public function insert($uuid,$host,$path) + { + $dbService = $this->serviceManager->get('Db'); + $dbh = $dbService->getDbh(); + + $id = $dbh->insert('dataset',[ + 'uuid' => $uuid, + 'host' => $host, + 'path' => $path, + ],true); + + if(is_numeric($id) && $id>0) + { + $this->proftpUpload($uuid,$host); + $this->getEventManager()->trigger('dataset.insert.success', $this, compact('id','uuid','host','path')); + return true; + }else{ + return false; + } + + } + + /** + * @param $uuid + * @return bool + */ + public function delete($uuid) + { + $sql = "DELETE FROM dataset WHERE uuid='$uuid'"; + if($this->db->exec($sql) > 0) + { + $this->getEventManager()->trigger('dataset.delete.success', $this, compact('uuid')); + return true; + }else{ + return false; + } + } + public function reload($uuid) + { + $data = $this->fetch($uuid); + + if(!isset($data['id']) || empty($data['id'])) + { + return "未找到对应的记录,无法完成更新"; + } + + try { + $this->proftpUpload($uuid, $data['host']); + }catch(\Exception $e){ + return $e->getMessage(); + } + return true; + + } + + + /** + * @param $uuid + * @param $host + */ + public function proftpUpload($uuid,$host) + { + if ($host=='ftp1.westgis.ac.cn') + { + //var_dump("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + } else if ($host=='ftp2.westgis.ac.cn') { + //var_dump("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + file_get_contents("http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + } + } } \ No newline at end of file