1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands\Migrations; |
4
|
|
|
|
5
|
|
|
use App\Entities\CompileInfo; |
6
|
|
|
use App\Entities\RuntimeInfo; |
7
|
|
|
use App\Entities\Solution; |
8
|
|
|
use App\Entities\Source; |
9
|
|
|
use App\Services\UserService; |
10
|
|
|
|
11
|
|
|
class SolutionMigration extends Migration |
12
|
|
|
{ |
13
|
|
|
public function handle($command) |
14
|
|
|
{ |
15
|
|
|
$command->info('Migrating Solutions...'); |
16
|
|
|
$this->table('solution')->orderBy('solution_id', 'asc')->chunk(100, function ($objects) { |
17
|
|
|
foreach ($objects as $object) { |
18
|
|
|
$this->transformSolution($object); |
19
|
|
|
} |
20
|
|
|
}); |
21
|
|
|
$command->info('Migrating Runtime Info...'); |
22
|
|
|
$this->table('runtimeinfo')->orderBy('solution_id', 'asc')->chunk(100, function ($objects) { |
23
|
|
|
foreach ($objects as $object) { |
24
|
|
|
$this->transformRuntimeInfo($object); |
25
|
|
|
} |
26
|
|
|
}); |
27
|
|
|
$command->info('Migrating Compile Info...'); |
28
|
|
|
$this->table('compileinfo')->orderBy('solution_id', 'asc')->chunk(100, function ($objects) { |
29
|
|
|
foreach ($objects as $object) { |
30
|
|
|
$this->transformCompileInfo($object); |
31
|
|
|
} |
32
|
|
|
}); |
33
|
|
|
$command->info('Migrating Source Code...'); |
34
|
|
|
$this->table('source_code')->orderBy('solution_id', 'asc')->chunk(100, function ($objects) { |
35
|
|
|
foreach ($objects as $object) { |
36
|
|
|
$this->transformSource($object); |
37
|
|
|
} |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
$command->info('Migrating Solutions Done'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function transformSolution($oldSolution) |
44
|
|
|
{ |
45
|
|
|
$solution = new Solution(); |
46
|
|
|
$solution->fill(get_object_vars($oldSolution)); |
47
|
|
|
$solution->id = $oldSolution->solution_id; |
48
|
|
|
$solution->order = $oldSolution->num; |
49
|
|
|
$solution->time_cost = $oldSolution->time; |
50
|
|
|
$solution->memory_cost = $oldSolution->memory; |
51
|
|
|
$solution->language = $oldSolution->language; |
52
|
|
|
$user = app(UserService::class)->findByName($oldSolution->user_id); |
53
|
|
|
$solution->user_id = $user->id; |
54
|
|
|
$solution->created_at = $oldSolution->in_date; |
55
|
|
|
$solution->judged_at = $oldSolution->judgetime; |
56
|
|
|
$solution->save(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function transformRuntimeInfo($object) |
60
|
|
|
{ |
61
|
|
|
$info = new RuntimeInfo(); |
62
|
|
|
$info->solution_id = $object->solution_id; |
63
|
|
|
$info->content = $object->error; |
64
|
|
|
$info->save(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function transformCompileInfo($object) |
68
|
|
|
{ |
69
|
|
|
$info = new CompileInfo(); |
70
|
|
|
$info->solution_id = $object->solution_id; |
71
|
|
|
$info->content = $object->error; |
72
|
|
|
$info->save(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function transformSource($object) |
76
|
|
|
{ |
77
|
|
|
$info = new Source(); |
78
|
|
|
$info->solution_id = $object->solution_id; |
79
|
|
|
$info->code = $object->source; |
80
|
|
|
$info->save(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|