Merge pull request #1012 from keriati/feat/appupdateon
feat: Trigger app update when new version is deployed
This commit is contained in:
commit
4b29b476df
5 changed files with 86 additions and 41 deletions
|
@ -3,14 +3,23 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Application extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'appid';
|
||||
|
||||
//
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function icon()
|
||||
{
|
||||
if (! file_exists(storage_path('app/public/'.$this->icon))) {
|
||||
|
@ -23,12 +32,18 @@ class Application extends Model
|
|||
return $this->icon;
|
||||
}
|
||||
|
||||
public function iconView()
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function iconView(): string
|
||||
{
|
||||
return asset('storage/'.$this->icon);
|
||||
}
|
||||
|
||||
public function defaultColour()
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function defaultColour(): string
|
||||
{
|
||||
// check if light or dark
|
||||
if ($this->tile_background == 'light') {
|
||||
|
@ -38,7 +53,10 @@ class Application extends Model
|
|||
return '#161b1f';
|
||||
}
|
||||
|
||||
public function class()
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function class(): string
|
||||
{
|
||||
$name = $this->name;
|
||||
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
||||
|
@ -48,6 +66,10 @@ class Application extends Model
|
|||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return string
|
||||
*/
|
||||
public static function classFromName($name)
|
||||
{
|
||||
$name = preg_replace('/[^\p{L}\p{N}]/u', '', $name);
|
||||
|
@ -57,16 +79,21 @@ class Application extends Model
|
|||
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'))) ?? [];
|
||||
$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();
|
||||
$list = [];
|
||||
|
@ -80,8 +107,14 @@ class Application extends Model
|
|||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $appid
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function getApp($appid)
|
||||
{
|
||||
Log::debug("Get app triggered for: $appid");
|
||||
|
||||
$localapp = self::where('appid', $appid)->first();
|
||||
$app = self::single($appid);
|
||||
|
||||
|
@ -106,6 +139,10 @@ class Application extends Model
|
|||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $appid
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function single($appid)
|
||||
{
|
||||
$apps = self::apps();
|
||||
|
@ -128,7 +165,10 @@ class Application extends Model
|
|||
return $app;
|
||||
}
|
||||
|
||||
public static function applist()
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function applist(): array
|
||||
{
|
||||
$list = [];
|
||||
$list['null'] = 'None';
|
||||
|
|
|
@ -369,26 +369,6 @@ class ItemController extends Controller
|
|||
if ($appid === '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['custom'] = null;
|
||||
|
|
|
@ -10,6 +10,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProcessApps implements ShouldQueue
|
||||
|
@ -33,6 +34,7 @@ class ProcessApps implements ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::debug('Process Apps dispatched');
|
||||
$localapps = Application::whereNull('class')->get();
|
||||
$json = SupportedApps::getList()->getBody();
|
||||
|
||||
|
|
|
@ -6,9 +6,10 @@ use App\Application;
|
|||
use App\Jobs\ProcessApps;
|
||||
use App\Setting;
|
||||
use App\User;
|
||||
use Artisan;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Schema;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
@ -129,17 +130,10 @@ class AppServiceProvider extends ServiceProvider
|
|||
touch(database_path('app.sqlite'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('settings')) {
|
||||
// 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 {
|
||||
if ($this->needsDBUpdate()) {
|
||||
Artisan::call('migrate', ['--path' => 'database/migrations', '--force' => true, '--seed' => true]);
|
||||
ProcessApps::dispatchSync();
|
||||
$this->updateApps();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,4 +148,31 @@ class AppServiceProvider extends ServiceProvider
|
|||
|
||||
$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)
|
||||
{
|
||||
Log::debug("Download triggered for $app->name");
|
||||
|
||||
$zipurl = config('app.appsource').'files/'.$app->sha.'.zip';
|
||||
|
||||
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15, 'verify' => false]);
|
||||
|
|
Loading…
Reference in a new issue