Completed
Push — dev5 ( f3ddc1...c580cf )
by Ron
10:16
created

RelocateSystemFilesToTechTips::up()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 2
nop 0
dl 0
loc 29
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
use App\TechTips;
4
use App\SystemFiles;
5
use App\TechTipFiles;
6
use App\TechTipSystems;
7
use Illuminate\Support\Facades\Schema;
8
use Illuminate\Database\Schema\Blueprint;
9
use Illuminate\Database\Migrations\Migration;
10
11
class RelocateSystemFilesToTechTips extends Migration
12
{
13
    /**
14
     * Run the migrations.
15
     *
16
     * @return void
17
     */
18
    //  Relocate any system files into the Tech Tips knowledge base
19
    public function up()
20
    {
21
//        Schema::table('tech_tips', function (Blueprint $table) {
22
//            //
23
//        });
24
        
25
        
26
        $sysFiles = SystemFiles::all();
27
        
28
        foreach($sysFiles as $sysFile)
29
        {
30
            $newTip = TechTips::create([
31
                'user_id'       => $sysFile->user_id,
0 ignored issues
show
Bug introduced by
The property user_id does not exist on App\SystemFiles. Did you mean user?
Loading history...
32
                'public'        => 0,
33
                'documentation' => 1,
34
                'subject'       => $sysFile->name,
35
                'description'   => empty($sysFile->description) ? $sysFile->name : $sysFile->description,
36
                'created_at'    => $sysFile->created_at,
37
                'updated_at'    => $sysFile->updated_at
38
            ]);
39
            
40
            $tipId = $newTip->tip_id;
41
            TechTipFiles::create([
42
                'tip_id'  => $tipId,
43
                'file_id' => $sysFile->file_id
44
            ]);
45
            TechTipSystems::create([
46
                'tip_id' => $tipId,
47
                'sys_id' => $sysFile->sys_id
48
            ]);
49
        }
50
        
51
        
52
    }
53
54
    /**
55
     * Reverse the migrations.
56
     *
57
     * @return void
58
     */
59
    public function down()
60
    {
61
//        Schema::table('tech_tips', function (Blueprint $table) {
62
//            //
63
//        });
64
    }
65
}
66