121 lines
2.6 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\Controllers\Install;
use App\Http\Controllers\Controller;
2017-10-02 16:26:45 +03:00
use App\Events\UpdateFinished;
2017-09-14 22:21:00 +03:00
use App\Utilities\Updater;
use App\Utilities\Versions;
2017-10-02 16:26:45 +03:00
use Artisan;
2017-09-14 22:21:00 +03:00
use Module;
class Updates extends Controller
{
2017-09-21 17:01:51 +03:00
2017-09-14 22:21:00 +03:00
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function index()
{
$updates = Updater::all();
$core = null;
2017-09-14 22:21:00 +03:00
$modules = array();
if (isset($updates['core'])) {
$core = $updates['core'];
}
2017-09-14 22:21:00 +03:00
$rows = Module::all();
if ($rows) {
foreach ($rows as $row) {
$alias = $row->get('alias');
2017-09-14 22:21:00 +03:00
if (!isset($updates[$alias])) {
continue;
}
2017-09-14 22:21:00 +03:00
$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;
}
2017-09-14 22:21:00 +03:00
}
return view('install.updates.index', compact('core', 'modules'));
}
public function changelog()
{
return Versions::changelog();
}
2017-09-21 17:01:51 +03:00
/**
* 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.
*
2017-10-02 16:26:45 +03:00
* @param $alias
* @param $version
2017-09-21 17:01:51 +03:00
* @return Response
*/
2017-09-14 22:21:00 +03:00
public function update($alias, $version)
{
set_time_limit(600); // 10 minutes
2017-10-02 16:26:45 +03:00
if (Updater::update($alias, $version)) {
return redirect('install/updates/post/' . $alias . '/' . version('short') . '/' . $version);
}
2017-09-14 22:21:00 +03:00
2017-10-02 16:26:45 +03:00
flash(trans('updates.error'))->error();
2017-09-14 22:21:00 +03:00
return redirect()->back();
}
2017-10-02 16:26:45 +03:00
/**
* 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();
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');
}
2017-09-14 22:21:00 +03:00
}