add check version and refactpr auto update

This commit is contained in:
jayvirsinh_gohil
2019-11-14 21:00:17 +05:30
parent 0d9ca2a0fd
commit 917b618ac7
7 changed files with 37 additions and 19 deletions

View File

@ -14,8 +14,6 @@ class UpdateFinished
{
use Dispatchable;
public $alias;
public $new;
public $old;
@ -25,9 +23,8 @@ class UpdateFinished
*
* @return void
*/
public function __construct($alias, $old, $new)
public function __construct($old, $new)
{
$this->alias = $alias;
$this->old = $old;
$this->new = $new;
}

View File

@ -4,6 +4,7 @@ namespace Laraspace\Http\Controllers;
use Illuminate\Http\Request;
use Laraspace\Space\Updater;
use Laraspace\Space\SiteApi;
class UpdateController extends Controller
{
@ -11,7 +12,16 @@ class UpdateController extends Controller
{
set_time_limit(600); // 10 minutes
$json = Updater::update($request->alias, $request->installed, $request->version);
$json = Updater::update($request->installed, $request->version);
return response()->json($json);
}
public function checkLatestVersion(Request $request)
{
set_time_limit(600); // 10 minutes
$json = Updater::checkForUpdate();
return response()->json($json);
}

View File

@ -4,8 +4,6 @@ namespace Laraspace\Listeners\Updates;
class Listener
{
const ALIAS = '';
const VERSION = '';
/**
@ -16,11 +14,6 @@ class Listener
*/
protected function check($event)
{
// Apply only to the specified alias
// if ($event->alias != static::ALIAS) {
// return false;
// }
// Do not apply to the same or newer versions
// if (version_compare($event->old, static::VERSION, '>=')) {
// return false;

View File

@ -11,8 +11,6 @@ use Laraspace\Setting;
class Version101 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.0.1';
/**

View File

@ -11,7 +11,7 @@ trait SiteApi
protected static function getRemote($url, $data = array())
{
$base = 'http://download-test.test/';
$base = 'http://crater-main.test/';
$client = new Client(['verify' => false, 'base_uri' => $base]);

View File

@ -7,17 +7,18 @@ use Artisan;
use GuzzleHttp\Exception\RequestException;
use Laraspace\Space\SiteApi;
use Laraspace\Events\UpdateFinished;
use Laraspace\Setting;
class Updater
{
use SiteApi;
public static function update($alias, $installed, $version)
public static function update($installed, $version)
{
$data = null;
$path = null;
$url = '/api/download';
$url = '/download/'.$version;
$response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]);
@ -68,7 +69,7 @@ class Updater
// Delete zip file
File::delete($file);
if (!File::copyDirectory($temp_path2, base_path())) {
if (!File::copyDirectory($temp_path2.'/crater', base_path())) {
return false;
}
@ -77,7 +78,7 @@ class Updater
File::deleteDirectory($temp_path2);
try {
event(new UpdateFinished($alias, $installed, $version));
event(new UpdateFinished($installed, $version));
return [
'success' => true,
@ -92,4 +93,18 @@ class Updater
];
}
}
public static function checkForUpdate()
{
$data = null;
$url = '/check/latest/download/'.Setting::getSetting('version');
$response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]);
if ($response && ($response->getStatusCode() == 200)) {
$data = $response->getBody()->getContents();
}
return json_decode($data);
}
}

View File

@ -129,6 +129,11 @@ Route::group(['middleware' => 'api'], function () {
'uses' => 'UpdateController@update'
]);
Route::get('/check/update', [
'as' => 'check.update',
'uses' => 'UpdateController@checkLatestVersion'
]);
Route::get('/bootstrap', [
'as' => 'bootstrap',
'uses' => 'UsersController@getBootstrap'