Files
tougao/test_plagiarism_e2e.php
2026-05-07 11:45:55 +08:00

103 lines
3.4 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
/**
* Turnitin TCA 端到端连通性测试。
*
* 用法(在项目根执行):
* php test_plagiarism_e2e.php features # 探活
* php test_plagiarism_e2e.php submit <article_id> # 用 article 主稿提交查重(手工触发)
* php test_plagiarism_e2e.php submit-file <pdf> # 用本地 PDF 提交(不绑定 article
* php test_plagiarism_e2e.php status <check_id> # 查询状态
* php test_plagiarism_e2e.php list <article_id> # 列出某 article 的查重记录
* php test_plagiarism_e2e.php viewer <check_id> # 取在线查看 URL
*
* 说明:
* submit-file 不会真正落库(仅用于联通验证),它会用 article_id=0 走完整套流程。
* submit 会写入 t_plagiarism_check并把 check_id 打回,再用 status 自己轮询。
*/
define('IS_CLI', true);
require __DIR__ . '/thinkphp/start.php';
use think\Db;
use app\common\PlagiarismService;
use app\common\TurnitinService;
if ($argc < 2) {
echo "Usage: php test_plagiarism_e2e.php <command> [args...]\n";
exit(1);
}
$cmd = $argv[1];
try {
switch ($cmd) {
case 'features': {
$tii = new TurnitinService();
print_r($tii->featuresEnabled());
break;
}
case 'submit': {
if ($argc < 3) {
echo "Usage: ... submit <article_id>\n";
exit(1);
}
$articleId = intval($argv[2]);
$svc = new PlagiarismService();
$local = $svc->locateArticleManuscript($articleId);
echo "manuscript local path: {$local}\n";
$checkId = $svc->submit($articleId, $local, 0, 'cli_test');
echo "submitted, check_id = {$checkId}\n";
echo "now run: php think queue:work --queue plagiarism --tries=1 -v\n";
break;
}
case 'submit-file': {
if ($argc < 3) {
echo "Usage: ... submit-file <pdf_path>\n";
exit(1);
}
$path = $argv[2];
if (!is_file($path)) {
echo "file not exists: {$path}\n";
exit(1);
}
$svc = new PlagiarismService();
$checkId = $svc->submit(0, $path, 0, 'cli_test_file');
echo "submitted, check_id = {$checkId}\n";
break;
}
case 'status': {
if ($argc < 3) {
echo "Usage: ... status <check_id>\n";
exit(1);
}
$row = Db::name('plagiarism_check')->where('check_id', intval($argv[2]))->find();
print_r($row);
break;
}
case 'list': {
if ($argc < 3) {
echo "Usage: ... list <article_id>\n";
exit(1);
}
$rows = Db::name('plagiarism_check')->where('article_id', intval($argv[2]))->order('check_id desc')->select();
print_r($rows);
break;
}
case 'viewer': {
if ($argc < 3) {
echo "Usage: ... viewer <check_id>\n";
exit(1);
}
$svc = new PlagiarismService();
print_r($svc->refreshViewerUrlFor(intval($argv[2])));
break;
}
default:
echo "unknown command: {$cmd}\n";
exit(1);
}
} catch (\Throwable $e) {
echo "ERROR: " . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
exit(1);
}