UpdateController.php 1.57 KB
Newer Older
Aan Choesni Herlingga committed
1 2 3 4 5 6 7
<?php

namespace App\Http\Controllers\Webprofile\Backend;

use App\Helpers\InseoHelper;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Artisan;
Aan Choesni Herlingga committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

class UpdateController extends Controller
{
    public function index()
    {
        return view('webprofile.backend.update.index');
    }

    public function update(Request $request)
    {
        $username = env('GIT_USERNAME', 'lorem');
        $password = InseoHelper::inseodecrypt(env('GIT_PASSWORD', 'lorem'), env('ENCRYPT_KEY', 'lorem'));
        $repository = env('GIT_REPOSITORY', 'lorem');

        $command = 'git pull http://'.$username.':'.$password.'@'.$repository.' master';
        $data = $request->tokenkey;
        $line = 'Token Tidak Valid';
        if ($data == env('TOKEN_KEY', 'lorem')) {
27
            $lines = null;
Aan Choesni Herlingga committed
28 29 30
            $result = array();
            exec($command, $result);
            foreach ($result as $line) {
31
                $lines = $lines.$line.'<br>';
Aan Choesni Herlingga committed
32 33 34 35 36
            }

            if ($line == null) {
                $line = 'Whoops something when wrong!! Check your username and password';
            }
37

38 39
            Artisan::call('migrate',
            array('--force' => true));
40

41 42 43 44 45 46
            // $command = 'cd .. && php artisan migrate';
            // exec($command, $resultMigrate);

            // foreach ($resultMigrate as $lineMigration) {
            //     $lines = $lines.$lineMigration.'<br>';
            // }
Aan Choesni Herlingga committed
47 48 49
        }

        $data = [
50
            'data' => $lines,
Aan Choesni Herlingga committed
51 52 53 54 55
        ];

        return view('webprofile.backend.update.result', $data);
    }
}