feat: Trigger app update when new version is deployed
This commit is contained in:
parent
b50bf716dc
commit
157b972ff5
5 changed files with 86 additions and 41 deletions
|
@ -3,14 +3,23 @@
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class Application extends Model
|
class Application extends Model
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $primaryKey = 'appid';
|
protected $primaryKey = 'appid';
|
||||||
|
|
||||||
//
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function icon()
|
public function icon()
|
||||||
{
|
{
|
||||||
if (! file_exists(storage_path('app/public/'.$this->icon))) {
|
if (! file_exists(storage_path('app/public/'.$this->icon))) {
|
||||||
|
@ -23,12 +32,18 @@ class Application extends Model
|
||||||
return $this->icon;
|
return $this->icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function iconView()
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function iconView(): string
|
||||||
{
|
{
|
||||||
return asset('storage/'.$this->icon);
|
return asset('storage/'.$this->icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function defaultColour()
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function defaultColour(): string
|
||||||
{
|
{
|
||||||
// check if light or dark
|
// check if light or dark
|
||||||
if ($this->tile_background == 'light') {
|
if ($this->tile_background == 'light') {
|
||||||
|
@ -38,7 +53,10 @@ class Application extends Model
|
||||||
return '#161b1f';
|
return '#161b1f';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function class()
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function class(): string
|
||||||
{
|
{
|
||||||
$name = $this->name;
|
$name = $this->name;
|
||||||
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
||||||
|
@ -48,6 +66,10 @@ class Application extends Model
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public static function classFromName($name)
|
public static function classFromName($name)
|
||||||
{
|
{
|
||||||
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
||||||
|
@ -57,16 +79,21 @@ class Application extends Model
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function apps()
|
/**
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public static function apps(): \Illuminate\Support\Collection
|
||||||
{
|
{
|
||||||
$json = json_decode(file_get_contents(storage_path('app/supportedapps.json'))) ?? [];
|
$json = json_decode(file_get_contents(storage_path('app/supportedapps.json'))) ?? [];
|
||||||
$apps = collect($json->apps);
|
$apps = collect($json->apps);
|
||||||
$sorted = $apps->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE);
|
|
||||||
|
|
||||||
return $sorted;
|
return $apps->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function autocomplete()
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function autocomplete(): array
|
||||||
{
|
{
|
||||||
$apps = self::apps();
|
$apps = self::apps();
|
||||||
$list = [];
|
$list = [];
|
||||||
|
@ -80,8 +107,14 @@ class Application extends Model
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $appid
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
public static function getApp($appid)
|
public static function getApp($appid)
|
||||||
{
|
{
|
||||||
|
Log::debug("Get app triggered for: $appid");
|
||||||
|
|
||||||
$localapp = self::where('appid', $appid)->first();
|
$localapp = self::where('appid', $appid)->first();
|
||||||
$app = self::single($appid);
|
$app = self::single($appid);
|
||||||
|
|
||||||
|
@ -106,6 +139,10 @@ class Application extends Model
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $appid
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
public static function single($appid)
|
public static function single($appid)
|
||||||
{
|
{
|
||||||
$apps = self::apps();
|
$apps = self::apps();
|
||||||
|
@ -128,7 +165,10 @@ class Application extends Model
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function applist()
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function applist(): array
|
||||||
{
|
{
|
||||||
$list = [];
|
$list = [];
|
||||||
$list['null'] = 'None';
|
$list['null'] = 'None';
|
||||||
|
|
|
@ -369,26 +369,6 @@ class ItemController extends Controller
|
||||||
if ($appid === 'null') {
|
if ($appid === 'null') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/*$appname = $request->input('app');
|
|
||||||
//die($appname);
|
|
||||||
|
|
||||||
$app_details = Application::where('name', $appname)->firstOrFail();
|
|
||||||
$appclass = $app_details->class();
|
|
||||||
$app = new $appclass;
|
|
||||||
|
|
||||||
// basic details
|
|
||||||
$output['icon'] = $app_details->icon();
|
|
||||||
$output['name'] = $app_details->name;
|
|
||||||
$output['iconview'] = $app_details->iconView();
|
|
||||||
$output['colour'] = $app_details->defaultColour();
|
|
||||||
$output['class'] = $appclass;
|
|
||||||
|
|
||||||
// live details
|
|
||||||
if($app instanceof \App\EnhancedApps) {
|
|
||||||
$output['config'] = className($app_details->name).'.config';
|
|
||||||
} else {
|
|
||||||
$output['config'] = null;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
$output['config'] = null;
|
$output['config'] = null;
|
||||||
$output['custom'] = null;
|
$output['custom'] = null;
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class ProcessApps implements ShouldQueue
|
class ProcessApps implements ShouldQueue
|
||||||
|
@ -33,6 +34,7 @@ class ProcessApps implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
Log::debug('Process Apps dispatched');
|
||||||
$localapps = Application::whereNull('class')->get();
|
$localapps = Application::whereNull('class')->get();
|
||||||
$json = SupportedApps::getList()->getBody();
|
$json = SupportedApps::getList()->getBody();
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@ use App\Application;
|
||||||
use App\Jobs\ProcessApps;
|
use App\Jobs\ProcessApps;
|
||||||
use App\Setting;
|
use App\Setting;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -129,17 +130,10 @@ class AppServiceProvider extends ServiceProvider
|
||||||
touch(database_path('app.sqlite'));
|
touch(database_path('app.sqlite'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Schema::hasTable('settings')) {
|
if ($this->needsDBUpdate()) {
|
||||||
// check version to see if an upgrade is needed
|
|
||||||
$db_version = Setting::_fetch('version');
|
|
||||||
$app_version = config('app.version');
|
|
||||||
if (version_compare($app_version, $db_version) == 1) {
|
|
||||||
// app is higher than db, so need to run migrations etc
|
|
||||||
Artisan::call('migrate', ['--path' => 'database/migrations', '--force' => true, '--seed' => true]);
|
|
||||||
ProcessApps::dispatch();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Artisan::call('migrate', ['--path' => 'database/migrations', '--force' => true, '--seed' => true]);
|
Artisan::call('migrate', ['--path' => 'database/migrations', '--force' => true, '--seed' => true]);
|
||||||
|
ProcessApps::dispatchSync();
|
||||||
|
$this->updateApps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,4 +148,31 @@ class AppServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
$this->genKey();
|
$this->genKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function needsDBUpdate(): bool
|
||||||
|
{
|
||||||
|
if (!Schema::hasTable('settings')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db_version = Setting::_fetch('version');
|
||||||
|
$app_version = config('app.version');
|
||||||
|
|
||||||
|
return version_compare($app_version, $db_version) === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateApps()
|
||||||
|
{
|
||||||
|
Log::debug('Update of all apps triggered');
|
||||||
|
|
||||||
|
foreach (Application::all(['appid']) as $app) {
|
||||||
|
Application::getApp($app->appid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,8 @@ abstract class SupportedApps
|
||||||
|
|
||||||
public static function getFiles($app)
|
public static function getFiles($app)
|
||||||
{
|
{
|
||||||
|
Log::debug("Download triggered for $app->name");
|
||||||
|
|
||||||
$zipurl = config('app.appsource').'files/'.$app->sha.'.zip';
|
$zipurl = config('app.appsource').'files/'.$app->sha.'.zip';
|
||||||
|
|
||||||
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15, 'verify' => false]);
|
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15, 'verify' => false]);
|
||||||
|
|
Loading…
Reference in a new issue