#284 后台下载全部元数据xml文件
This commit is contained in:
parent
bc29229463
commit
9421ae190d
|
@ -332,42 +332,77 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
|
|
||||||
}//编辑附件
|
}//编辑附件
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 输出打包下载的xml文件
|
||||||
|
*
|
||||||
|
* 文件量大时可能出现超时,需要修改超时时间为无限
|
||||||
|
*/
|
||||||
elseif ($down) {
|
elseif ($down) {
|
||||||
$zip = new ZipArchive();
|
|
||||||
$url="/tmp/xml.zip";
|
$this->_helper->layout->disableLayout();
|
||||||
$opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
if( $opened !== true ){
|
|
||||||
die("cannot open {$url} for writing.");
|
//临时zip文件名
|
||||||
}
|
$tmpname="dataxml";
|
||||||
|
|
||||||
|
//xml文件存放的缓存目录
|
||||||
$dirName = '../data/import/';
|
$dirName = '../data/import/';
|
||||||
$zip->addEmptyDir("xml/");
|
|
||||||
|
//查询需要创建的文件
|
||||||
$filesToAdd = array();
|
$sql = "SELECT md.title,md.uuid,x.* from xml x
|
||||||
$dir = dir($dirName);
|
LEFT JOIN metadata md ON md.id=x.id";
|
||||||
while (false !== ($node = $dir->read())) {
|
|
||||||
if (($node == '..') || ($node == '.')) {
|
$sth = $this->db->prepare($sql);
|
||||||
continue;
|
$sth->execute();
|
||||||
}
|
$rows = $sth->fetchAll(); //将结果储存,但不使用
|
||||||
if (is_file($dirName.$node)) {
|
|
||||||
$zip->addFile($dirName.$node,"xml/".$node);
|
//创建zip文件,创建成功后再使用查询结果
|
||||||
}
|
$zip = new ZipArchive();
|
||||||
}
|
$url = tempnam($this->config->temp->path,$tmpname);//创建临时文件
|
||||||
$zip->close();
|
|
||||||
$content=file_get_contents($url);
|
if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true )
|
||||||
$this->_helper->layout->disableLayout();
|
{
|
||||||
$this->_helper->viewRenderer->setNoRender();
|
throw new Exception("cannot open {$url} for writing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($rows as $k=>$v)
|
||||||
|
{
|
||||||
|
|
||||||
|
$filename = $dirName.$v['uuid'].'.xml';
|
||||||
|
|
||||||
|
//创建xml文件
|
||||||
|
$handle = fopen($filename,"w");
|
||||||
|
fwrite($handle,$v['data']);
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
//添加到zip文件
|
||||||
|
//zip localname 直接使用UUID作为文件名
|
||||||
|
$zip->addFile($filename,$v['uuid'].".xml");
|
||||||
|
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
//zip文件创建完成后删除服务器上的缓存文件,防止发生冗余
|
||||||
|
foreach($rows as $k=>$v)
|
||||||
|
{
|
||||||
|
$filename = $dirName.$v['uuid'].'.xml';
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出下载
|
||||||
|
$content=file_get_contents($url);
|
||||||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||||||
->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"')
|
->setHeader('Content-Disposition','attachment; filename="dataxml.zip"')
|
||||||
->setHeader('Content-Length', strlen($content))
|
->setHeader('Content-Length', strlen($content))
|
||||||
->setHeader('Content-Type','application/force-download')
|
->setHeader('Content-Type','application/force-download')
|
||||||
->setHeader('Content-Type','application/download')
|
->setHeader('Content-Type','application/download')
|
||||||
->setHeader('Content-Type','application/zip')
|
->setHeader('Content-Type','application/zip')
|
||||||
->setHeader('Content-Description','File Transfer')
|
->setHeader('Content-Description','File Transfer')
|
||||||
->setHeader('Content-Transfer-Encoding','binary')
|
->setHeader('Content-Transfer-Encoding','binary')
|
||||||
->setHeader('Expires',0)
|
->setHeader('Expires',0)
|
||||||
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
||||||
->setHeader('Pragma','public')
|
->setHeader('Pragma','public')
|
||||||
->setBody($content);
|
->setBody($content);
|
||||||
}//down
|
}//down
|
||||||
else if($search){
|
else if($search){
|
||||||
|
|
||||||
|
@ -684,11 +719,11 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
$lines=explode("\n",$ref);
|
$lines=explode("\n",$ref);
|
||||||
foreach($lines as $line)
|
foreach($lines as $line)
|
||||||
{
|
{
|
||||||
$data=explode(";",$line);
|
$data=explode(";",$line);
|
||||||
if (count($data)==2)
|
if (count($data)==2)
|
||||||
$link='';
|
$link='';
|
||||||
else
|
else
|
||||||
$link=$data[2];
|
$link=$data[2];
|
||||||
$link=$this->db->quote($link);
|
$link=$this->db->quote($link);
|
||||||
$sql="insert into reference (reference,link) values(?,".$link.")";
|
$sql="insert into reference (reference,link) values(?,".$link.")";
|
||||||
try {
|
try {
|
||||||
|
@ -1122,7 +1157,7 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
|
|
||||||
|
|
||||||
}// 清除元数据来源记录
|
}// 清除元数据来源记录
|
||||||
elseif ($do=='sync') { //同步数据来源到metadata表
|
elseif ($do=='sync') { //同步数据来源到metadata表
|
||||||
$redirect = "/admin/data/source/";
|
$redirect = "/admin/data/source/";
|
||||||
$sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid";
|
$sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid";
|
||||||
if($this->db->exec($sql))
|
if($this->db->exec($sql))
|
||||||
|
|
Loading…
Reference in New Issue