批量导入时,支持unicode字符匹配,添加事务
This commit is contained in:
parent
ee12175fba
commit
c452e6a486
@ -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"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user