Blame view

app/Http/Controllers/Install/Updates.php 2.61 KB
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  <?php
  
  namespace App\Http\Controllers\Install;
  
  use App\Http\Controllers\Controller;
  use App\Events\UpdateFinished;
  use App\Utilities\Updater;
  use App\Utilities\Versions;
  use Artisan;
  use Module;
  
  class Updates extends Controller
  {
  
      /**
       * Show the form for creating a new resource.
       *
       * @return Response
       */
      public function index()
      {
          $updates = Updater::all();
  
          $core = null;
  
          $modules = array();
  
          if (isset($updates['core'])) {
              $core = $updates['core'];
          }
  
          $rows = Module::all();
  
          if ($rows) {
              foreach ($rows as $row) {
                  $alias = $row->get('alias');
  
                  if (!isset($updates[$alias])) {
                      continue;
                  }
  
                  $m = new \stdClass();
                  $m->name = $row->get('name');
                  $m->alias = $row->get('alias');
                  $m->category = $row->get('category');
                  $m->installed = $row->get('version');
                  $m->latest = $updates[$alias];
  
                  $modules[] = $m;
              }
          }
  
          return view('install.updates.index', compact('core', 'modules'));
      }
  
      public function changelog()
      {
          return Versions::changelog();
      }
  
      /**
       * Check for updates.
       *
       * @return Response
       */
      public function check()
      {
          // Clear cache in order to check for updates
          Updater::clear();
  
          return redirect()->back();
      }
  
      /**
       * Update the core or modules.
       *
       * @param  $alias
       * @param  $version
       * @return Response
       */
      public function update($alias, $version)
      {
          set_time_limit(600); // 10 minutes
  
          if (Updater::update($alias, $version)) {
              return redirect('install/updates/post/' . $alias . '/' . version('short') . '/' . $version);
          }
  
          flash(trans('updates.error'))->error()->important();
  
          return redirect()->back();
      }
  
      /**
       * Final actions post update.
       *
       * @param  $alias
       * @param  $old
       * @param  $new
       * @return Response
       */
      public function post($alias, $old, $new)
      {
          // Check if the file mirror was successful
          if (($alias == 'core') && (version('short') != $new)) {
              flash(trans('updates.error'))->error()->important();
  
              return redirect('install/updates');
          }
  
          // Clear cache after update
          Artisan::call('cache:clear');
  
          event(new UpdateFinished($alias, $old, $new));
  
          flash(trans('updates.success'))->success();
  
          return redirect('install/updates');
      }
  }