fixed a variable missing in AbstractEventManager,profection the Westdc\Metadata\Dataset

This commit is contained in:
Jianxuan Li 2014-12-22 14:42:19 +08:00
parent c705293d85
commit 66aeb02dc7
2 changed files with 122 additions and 0 deletions

View File

@ -14,6 +14,8 @@ use Zend\EventManager\EventManagerAwareInterface;
abstract class AbstractEventManager { abstract class AbstractEventManager {
protected $events;
public function setEventManager (EventManagerInterface $events) { public function setEventManager (EventManagerInterface $events) {
$events->setIdentifiers(array( $events->setIdentifiers(array(
__CLASS__, __CLASS__,

View File

@ -34,6 +34,7 @@ class Dataset extends AbstractEventManager implements ServiceManagerAwareInterfa
} }
/** /**
* 查询某个元数据的数据集信息(数据存储位置)
* @param $uuid * @param $uuid
* @return mixed * @return mixed
*/ */
@ -45,7 +46,126 @@ class Dataset extends AbstractEventManager implements ServiceManagerAwareInterfa
return $sth->fetch(); 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");
}
}
} }