批量导入时,支持unicode字符匹配,添加事务
This commit is contained in:
parent
ee12175fba
commit
c452e6a486
@ -63,11 +63,15 @@ class ProgramConstructController extends BaseController
|
|||||||
"message" => "该BVID下已有{$count}个节目关联,请手动添加",
|
"message" => "该BVID下已有{$count}个节目关联,请手动添加",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$regex = "/^p(?P<part>\d{1,2})[-# _:,)]+(?P<time>(0?1[::])?(\d{1,3}[::])\d{1,2})?[ :]?(?P<content>.+)$/i";
|
$regex = "/^p(?P<part>\d{1,2})[-# _:,)]+(?P<time>(0?1[::])?\d{1,3}[::]\d{1,2}) ?(?P<content>.+)$/ui";
|
||||||
foreach (explode("\n", $content) as $line) {
|
DB::beginTransaction();
|
||||||
$match = [];
|
try {
|
||||||
$match_count = preg_match($regex, $line, $match);
|
foreach (explode("\n", $content) as $line) {
|
||||||
if ($match_count > 0) {
|
$match = [];
|
||||||
|
$match_count = preg_match($regex, $line, $match);
|
||||||
|
if ($match_count === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$time = $match["time"];
|
$time = $match["time"];
|
||||||
$time = str_replace(":", ":", $time);
|
$time = str_replace(":", ":", $time);
|
||||||
while (substr_count($time, ":") < 2) {
|
while (substr_count($time, ":") < 2) {
|
||||||
@ -83,6 +87,12 @@ class ProgramConstructController extends BaseController
|
|||||||
$program->save();
|
$program->save();
|
||||||
$program->video_pivots()->save($video_pivot);
|
$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"));
|
return redirect(route("program.construct.list"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user