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

@ -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);
}
}