批量导入时,支持unicode字符匹配,添加事务

This commit is contained in:
Jerry Yan 2022-08-20 11:48:34 +08:00
parent ee12175fba
commit c452e6a486
Signed by: q792602257
GPG Key ID: D070F653AF6C0004

View File

@ -63,11 +63,15 @@ class ProgramConstructController extends BaseController
"message" => "该BVID下已有{$count}个节目关联,请手动添加",
]);
}
$regex = "/^p(?P<part>\d{1,2})[-# _:,)]+(?P<time>(0?1[:])?(\d{1,3}[:])\d{1,2})?[ :]?(?P<content>.+)$/i";
foreach (explode("\n", $content) as $line) {
$match = [];
$match_count = preg_match($regex, $line, $match);
if ($match_count > 0) {
$regex = "/^p(?P<part>\d{1,2})[-# _:,)]+(?P<time>(0?1[:])?\d{1,3}[:]\d{1,2}) ?(?P<content>.+)$/ui";
DB::beginTransaction();
try {
foreach (explode("\n", $content) as $line) {
$match = [];
$match_count = preg_match($regex, $line, $match);
if ($match_count === 0) {
continue;
}
$time = $match["time"];
$time = str_replace("", ":", $time);
while (substr_count($time, ":") < 2) {
@ -83,6 +87,12 @@ class ProgramConstructController extends BaseController
$program->save();
$program->video_pivots()->save($video_pivot);
}
DB::commit();
} catch (QueryException $e) {
DB::rollBack();
return back()->withInput()->withErrors([
"content" => $e->getMessage()
]);
}
return redirect(route("program.construct.list"));
}