This commit is contained in:
Bozhidar 2024-05-10 11:49:28 +03:00
parent 0f89caca63
commit 93558a2b74
3 changed files with 103 additions and 61 deletions

View file

@ -10,6 +10,8 @@ use MicroweberPackages\SharedServerScripts\MicroweberDownloader;
use MicroweberPackages\SharedServerScripts\MicroweberModuleConnectorsDownloader;
use MicroweberPackages\SharedServerScripts\MicroweberTemplatesDownloader;
use Modules\Microweber\Filament\Clusters\MicroweberCluster;
use Modules\Microweber\Jobs\DownloadMicroweber;
use Modules\Microweber\MicroweberComposerClientHelper;
class Version extends Page
{
@ -35,14 +37,14 @@ class Version extends Page
protected function getViewData(): array
{
$release = $this->__getMicroweberDownloaderInstance()->getRelease();
$mwComposerClientHelper = new MicroweberComposerClientHelper();
$sharedPath = new MicroweberAppPathHelper();
$sharedPath->setPath(config('microweber.sharedPaths.app'));
$this->supportedLanguages = $sharedPath->getSupportedLanguages();
$this->supportedTemplates = $sharedPath->getSupportedTemplates();
$this->latestVersionOfApp = $this->__getMicroweberDownloaderInstance()->getVersion();
$this->latestVersionOfApp = $mwComposerClientHelper->getMicroweberDownloaderInstance()->getVersion();
$this->currentVersionOfApp = $sharedPath->getCurrentVersion();
$this->latestDownloadDateOfApp = $sharedPath->getCreatedAt();
@ -60,65 +62,7 @@ class Version extends Page
public function checkForUpdates()
{
$sharedAppPath = config('microweber.sharedPaths.app');
DownloadMicroweber::dispatch();
if (! is_dir(dirname($sharedAppPath))) {
mkdir(dirname($sharedAppPath));
}
$shellPath = '/usr/local/phyre/web/vendor/microweber-packages/shared-server-scripts/shell-scripts';
ShellApi::exec('chmod +x '.$shellPath.'/*');
// Download core app
$status = $this->__getMicroweberDownloaderInstance()
->download(config('microweber.sharedPaths.app'));
// Download modules
$modulesDownloader = new MicroweberModuleConnectorsDownloader();
$modulesDownloader->setComposerClient($this->__getComposerClientInstance());
$status = $modulesDownloader->download(config('microweber.sharedPaths.modules'));
// Download templates
$templatesDownloader = new MicroweberTemplatesDownloader();
$templatesDownloader->setComposerClient($this->__getComposerLicensedInstance());
$status = $templatesDownloader->download(config('microweber.sharedPaths.templates'));
}
private function __getComposerClientInstance()
{
// The module connector must have own instance of composer client
$composerClient = new Client();
$composerClient->packageServers = [
'https://market.microweberapi.com/packages/microweberserverpackages/packages.json',
];
return $composerClient;
}
private function __getComposerLicensedInstance()
{
$composerClientLicensed = new Client();
$composerClientLicensed->addLicense([
'local_key' => setting('whitelabel_license_key')
]);
return $composerClientLicensed;
}
private function __getMicroweberDownloaderInstance()
{
$coreDownloader = new MicroweberDownloader();
$updateAppChannel = 'stable';
if ($updateAppChannel == 'stable') {
$coreDownloader->setReleaseSource(MicroweberDownloader::STABLE_RELEASE);
} else {
$coreDownloader->setReleaseSource(MicroweberDownloader::DEV_RELEASE);
}
$coreDownloader->setComposerClient($this->__getComposerClientInstance());
return $coreDownloader;
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Modules\Microweber\Jobs;
use App\ShellApi;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use MicroweberPackages\ComposerClient\Client;
use MicroweberPackages\SharedServerScripts\MicroweberDownloader;
use MicroweberPackages\SharedServerScripts\MicroweberModuleConnectorsDownloader;
use MicroweberPackages\SharedServerScripts\MicroweberTemplatesDownloader;
use Modules\Microweber\MicroweberComposerClientHelper;
class DownloadMicroweber implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle(): void
{
$sharedAppPath = config('microweber.sharedPaths.app');
if (!is_dir(dirname($sharedAppPath))) {
mkdir(dirname($sharedAppPath));
}
$shellPath = '/usr/local/phyre/web/vendor/microweber-packages/shared-server-scripts/shell-scripts';
ShellApi::exec('chmod +x ' . $shellPath . '/*');
$mwComposerClientHelper = new MicroweberComposerClientHelper();
// Download core app
$status = $mwComposerClientHelper->getMicroweberDownloaderInstance()->download(config('microweber.sharedPaths.app'));
// Download modules
$modulesDownloader = new MicroweberModuleConnectorsDownloader();
$modulesDownloader->setComposerClient($mwComposerClientHelper->getComposerClientInstance());
$status = $modulesDownloader->download(config('microweber.sharedPaths.modules'));
// Download templates
$templatesDownloader = new MicroweberTemplatesDownloader();
$templatesDownloader->setComposerClient($mwComposerClientHelper->getComposerLicensedInstance());
$status = $templatesDownloader->download(config('microweber.sharedPaths.templates'));
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Modules\Microweber;
use MicroweberPackages\ComposerClient\Client;
use MicroweberPackages\SharedServerScripts\MicroweberDownloader;
class MicroweberComposerClientHelper
{
public function getComposerClientInstance()
{
// The module connector must have own instance of composer client
$composerClient = new Client();
$composerClient->packageServers = [
'https://market.microweberapi.com/packages/microweberserverpackages/packages.json',
];
return $composerClient;
}
public function getComposerLicensedInstance()
{
$composerClientLicensed = new Client();
$composerClientLicensed->addLicense([
'local_key' => setting('whitelabel_license_key')
]);
return $composerClientLicensed;
}
public function getMicroweberDownloaderInstance()
{
$coreDownloader = new MicroweberDownloader();
$updateAppChannel = 'stable';
if ($updateAppChannel == 'stable') {
$coreDownloader->setReleaseSource(MicroweberDownloader::STABLE_RELEASE);
} else {
$coreDownloader->setReleaseSource(MicroweberDownloader::DEV_RELEASE);
}
$coreDownloader->setComposerClient($this->getComposerClientInstance());
return $coreDownloader;
}
}