Files
journal/application/master/service/push/EbscoPusher.php

63 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\master\service\push;
use app\master\service\XmlBuilder;
/**
* EBSCO 推送器
* 为每篇文章生成 XML连同 PDF 通过 FTP 上传到 EBSCO。
* 逻辑迁移自 Datebase::pushXmlToEp / pushFtpForEp。
*/
class EbscoPusher extends AbstractPusher
{
public function code()
{
return 'ebsco';
}
public function label()
{
return 'EBSCO';
}
public function pushStage($stage_id, array $options = [])
{
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $stage_id)->find();
$list = $this->article_obj->where("journal_stage_id", $stage_id)->select();
$journal_info = $this->journal_obj->where("journal_id", $stage_info['journal_id'])->find();
$count = 0;
foreach ($list as $v) {
$local_file = XmlBuilder::forArticle($v['article_id']);
$file = substr($v['doi'], strpos($v['doi'], "/") + 1) . ".xml";
$remote_file = "/" . $journal_info['title'] . "/" . $stage_info['stage_year'] . "v" . $stage_info['stage_vol'] . "n" . $stage_info['stage_no'] . "-" . $file;
$this->pushFtp($remote_file, $local_file);
$localPdf = ROOT_PATH . "public/articlePDF/" . $v['file_pdf'];
$remotePdf = "/" . $journal_info['title'] . "/" . $stage_info['stage_year'] . "v" . $stage_info['stage_vol'] . "n" . $stage_info['stage_no'] . "-" . substr($v['doi'], strpos($v['doi'], "/") + 1) . ".pdf";
$this->pushFtp($remotePdf, $localPdf);
$count++;
}
return PushResult::success("EBSCO 已上传 {$count} 篇文章的 XML/PDF");
}
private function pushFtp($remote_file, $local_file)
{
$cred = $this->cred('ebsco');
$con = ftp_connect($cred['host'], $cred['port']);
if (!$con) {
throw new \Exception('EBSCO FTP 连接失败');
}
$res = ftp_login($con, $cred['user'], $cred['pass']);
if (!$res) {
ftp_close($con);
throw new \Exception('EBSCO FTP 登录失败');
}
ftp_pasv($con, true);
$data = ftp_put($con, $remote_file, $local_file, FTP_BINARY);
ftp_close($con);
if (!$data) {
throw new \Exception('EBSCO FTP 上传失败: ' . $remote_file);
}
}
}