From ae5a84b0531b751d06d940cb9282f4acdc790c7d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Fri, 28 May 2021 18:06:01 +1000 Subject: [PATCH] Plugin can now upgrade October v1 sites --- beacon/scripts/clear_cache.txt | 11 ++++ beacon/templates/app/bootstrap/beacon.stub | 12 ++++- controllers/Servers.php | 50 +++++++++++++++++++ .../servers/_action_convert_legacy.htm | 21 ++++++++ controllers/servers/_action_update_config.htm | 2 +- controllers/servers/_manage_scoreboard.htm | 3 ++ controllers/servers/config_form.yaml | 3 ++ lang/ar.json | 11 +++- lang/cs.json | 11 +++- lang/de.json | 11 +++- lang/es.json | 11 +++- lang/fr.json | 11 +++- lang/it.json | 11 +++- lang/nl.json | 11 +++- lang/ru.json | 11 +++- lang/xx.json | 11 +++- lang/zh-cn.json | 11 +++- lang/zh-tw.json | 11 +++- models/Server.php | 27 ++++++++-- models/server/fields_manage_legacy.yaml | 21 ++++++++ models/server/fields_upgrade_legacy.yaml | 9 ++++ plugin.yaml | 4 +- widgets/Deployer.php | 6 ++- 23 files changed, 260 insertions(+), 30 deletions(-) create mode 100644 beacon/scripts/clear_cache.txt create mode 100644 controllers/servers/_action_convert_legacy.htm create mode 100644 models/server/fields_manage_legacy.yaml create mode 100644 models/server/fields_upgrade_legacy.yaml diff --git a/beacon/scripts/clear_cache.txt b/beacon/scripts/clear_cache.txt new file mode 100644 index 0000000..86633dc --- /dev/null +++ b/beacon/scripts/clear_cache.txt @@ -0,0 +1,11 @@ +// Ouptut +$result = [ + 'status' => 'ok', +]; + +// Remove cache files +@unlink(__DIR__ . '/../storage/framework/classes.php'); +@unlink(__DIR__ . '/../storage/framework/packages.php'); +@unlink(__DIR__ . '/../storage/framework/services.php'); + +return $result; diff --git a/beacon/templates/app/bootstrap/beacon.stub b/beacon/templates/app/bootstrap/beacon.stub index 6bfd8d9..eceb6ad 100644 --- a/beacon/templates/app/bootstrap/beacon.stub +++ b/beacon/templates/app/bootstrap/beacon.stub @@ -61,7 +61,9 @@ function processHealthCheck() outputResponse([ 'appWritable' => isAppWritable(), 'appInstalled' => isAppInstalled(), - 'storageWritable' => isStorageWritable() + 'storageWritable' => isStorageWritable(), + 'envFound' => isEnvFound(), + 'phpVersion' => PHP_VERSION ]); } @@ -449,6 +451,14 @@ function isAppInstalled(): bool return file_exists(__DIR__.'/../vendor/october/rain/src/Support/helpers.php'); } +/** + * isEnvFound checks if an environment variable file is found + */ +function isEnvFound(): bool +{ + return file_exists(__DIR__.'/../.env'); +} + /** * isAppWritable checks if the root directory is writable */ diff --git a/controllers/Servers.php b/controllers/Servers.php index 033776a..057cd65 100644 --- a/controllers/Servers.php +++ b/controllers/Servers.php @@ -46,6 +46,7 @@ class Servers extends SettingsController 'privkey' => '/plugins/rainlab/deploy/models/server/fields_privkey.yaml', 'env_config' => '/plugins/rainlab/deploy/models/server/fields_env_config.yaml', 'shell_script' => '/plugins/rainlab/deploy/models/server/fields_shell_script.yaml', + 'upgrade_legacy' => '/plugins/rainlab/deploy/models/server/fields_upgrade_legacy.yaml', ]; /** @@ -111,6 +112,10 @@ public function manage($recordId = null) $context = 'manage_download'; break; + case $model::STATUS_LEGACY: + $context = 'manage_legacy'; + break; + default: $context = 'manage'; break; @@ -323,6 +328,12 @@ public function manage_onSaveDeployToServer($serverId) ]; } + $deployActions[] = [ + 'label' => 'Clearing Cache', + 'action' => 'transmitScript', + 'script' => 'clear_cache' + ]; + $deployActions[] = [ 'label' => 'Migrating Database', 'action' => 'transmitArtisan', @@ -463,6 +474,45 @@ public function manage_onSaveInstallToServer($serverId) return $this->deployerWidget->executeSteps($serverId, $deployActions); } + + /** + * manage_onLoadUpgradeLegacy upgrades a legacy version + */ + public function manage_onLoadUpgradeLegacy() + { + $widget = $this->formWidgetInstances['upgrade_legacy']; + + $this->vars['actionTitle'] = 'Upgrade Config'; + $this->vars['actionHandler'] = 'onRunUpgradeLegacy'; + $this->vars['submitText'] = 'Run'; + $this->vars['closeText'] = 'Close'; + $this->vars['widget'] = $widget; + + return $this->makePartial('action_form'); + } + + /** + * manage_onRunUpgradeLegacy deploys selected objects to the server + */ + public function manage_onRunUpgradeLegacy($serverId) + { + // Create deployment chain + $deployActions = []; + + $deployActions[] = [ + 'label' => 'Upgrading Legacy Site', + 'action' => 'transmitArtisan', + 'artisan' => 'october:env' + ]; + + $deployActions[] = [ + 'label' => 'Finishing Up', + 'action' => 'final' + ]; + + return $this->deployerWidget->executeSteps($serverId, $deployActions); + } + /** * buildArchiveDeployStep builds a single archive step used for deployment */ diff --git a/controllers/servers/_action_convert_legacy.htm b/controllers/servers/_action_convert_legacy.htm new file mode 100644 index 0000000..304e8ad --- /dev/null +++ b/controllers/servers/_action_convert_legacy.htm @@ -0,0 +1,21 @@ + +
+
+
+
+

+
+
+
+ +
+
+
+
diff --git a/controllers/servers/_action_update_config.htm b/controllers/servers/_action_update_config.htm index c346326..8d2239b 100644 --- a/controllers/servers/_action_update_config.htm +++ b/controllers/servers/_action_update_config.htm @@ -13,7 +13,7 @@
data-size="huge" data-request-data="server_id: 'id ?>'" data-handler="onLoadEnvConfig"> - + diff --git a/controllers/servers/_manage_scoreboard.htm b/controllers/servers/_manage_scoreboard.htm index 8569274..84c290a 100644 --- a/controllers/servers/_manage_scoreboard.htm +++ b/controllers/servers/_manage_scoreboard.htm @@ -14,6 +14,9 @@

status_code === $formModel::STATUS_READY): ?>

+ status_code === $formModel::STATUS_LEGACY): ?> +

+ status_code === $formModel::STATUS_UNREACHABLE): ?>

diff --git a/controllers/servers/config_form.yaml b/controllers/servers/config_form.yaml index af5720c..d94170f 100644 --- a/controllers/servers/config_form.yaml +++ b/controllers/servers/config_form.yaml @@ -35,3 +35,6 @@ manage_download: manage_install: form: $/rainlab/deploy/models/server/fields_manage_install.yaml + +manage_legacy: + form: $/rainlab/deploy/models/server/fields_manage_legacy.yaml diff --git a/lang/ar.json b/lang/ar.json index 8a007aa..c217847 100644 --- a/lang/ar.json +++ b/lang/ar.json @@ -35,12 +35,13 @@ "Open Console": "افتح وحدة التحكم", "Update Environment Variables": "تحديث متغيرات البيئة", "Modify the configuration values on the server": "قم بتعديل قيم التكوين على الخادم", - "Update Config": "تحديث التكوين", + "Update Environment": "تحديث التكوين", "View Deployment Key": "عرض مفتاح النشر", "Display the private key used to deploy to this server": "اعرض المفتاح الخاص المستخدم للنشر على هذا الخادم", "Show Key": "اظهر المفتاح", "Current Version": "النسخة الحالية", "Active": "نشيط", + "Legacy": "ميراث", "Ready": "مستعد", "Unreachable": "لا يمكن الوصول إليه", "Beacon Status": "حالة منارة", @@ -73,5 +74,11 @@ "Migrating Database": "ترحيل قاعدة البيانات", "Building :type Archive": "المبنى: نوع الأرشيف", "Checking Database Config": "التحقق من تكوين قاعدة البيانات", - "Setting Build Number": "تحديد رقم البنية" + "Setting Build Number": "تحديد رقم البنية", + "A Legacy Version of October CMS is Detected": "تم اكتشاف إصدار قديم من October CMS", + "Upgrade Configuration Files": "تحويل ملفات التكوين", + "Runs the artisan command to create an environment file": "يقوم بتشغيل الأمر الحرفي لإنشاء ملف بيئة", + "Upgrade Config": "تحويل التكوين", + "Upgrading Legacy Site": "ترقية الموقع القديم", + "Clearing Cache": "مسح ذاكرة التخزين المؤقت" } \ No newline at end of file diff --git a/lang/cs.json b/lang/cs.json index 53f33e7..18cb3b6 100644 --- a/lang/cs.json +++ b/lang/cs.json @@ -35,12 +35,13 @@ "Open Console": "Otevřete konzolu", "Update Environment Variables": "Aktualizujte proměnné prostředí", "Modify the configuration values on the server": "Upravte konfigurační hodnoty na serveru", - "Update Config": "Aktualizovat konfiguraci", + "Update Environment": "Aktualizovat konfiguraci", "View Deployment Key": "Zobrazit klíč nasazení", "Display the private key used to deploy to this server": "Zobrazit soukromý klíč použitý k nasazení na tento server", "Show Key": "Zobrazit klíč", "Current Version": "Současná verze", "Active": "Aktivní", + "Legacy": "Dědictví", "Ready": "Připraven", "Unreachable": "Nedostupný", "Beacon Status": "Stav majáku", @@ -73,5 +74,11 @@ "Migrating Database": "Migrace databáze", "Building :type Archive": "Budova :type Archiv", "Checking Database Config": "Kontrola konfigurace databáze", - "Setting Build Number": "Nastavení čísla sestavení" + "Setting Build Number": "Nastavení čísla sestavení", + "A Legacy Version of October CMS is Detected": "Byla zjištěna starší verze říjnového CMS", + "Upgrade Configuration Files": "Převést konfigurační soubory", + "Runs the artisan command to create an environment file": "Spustí příkaz řemeslník a vytvoří soubor prostředí", + "Upgrade Config": "Převést konfiguraci", + "Upgrading Legacy Site": "Aktualizace starších stránek", + "Clearing Cache": "Vymazání mezipaměti" } \ No newline at end of file diff --git a/lang/de.json b/lang/de.json index 4a45af1..4ff8f8d 100644 --- a/lang/de.json +++ b/lang/de.json @@ -35,12 +35,13 @@ "Open Console": "Konsole öffnen", "Update Environment Variables": "Umgebungsvariablen aktualisieren", "Modify the configuration values on the server": "Ändern Sie die Konfigurationswerte auf dem Server", - "Update Config": "Konfiguration aktualisieren", + "Update Environment": "Konfiguration aktualisieren", "View Deployment Key": "Bereitstellungsschlüssel anzeigen", "Display the private key used to deploy to this server": "Zeigen Sie den privaten Schlüssel an, der für die Bereitstellung auf diesem Server verwendet wird", "Show Key": "Schlüssel anzeigen", "Current Version": "Aktuelle Version", "Active": "Aktiv", + "Legacy": "Erbe", "Ready": "Bereit", "Unreachable": "Nicht erreichbar", "Beacon Status": "Beacon Status", @@ -73,5 +74,11 @@ "Migrating Database": "Datenbank migrieren", "Building :type Archive": "Gebäude :type Archiv", "Checking Database Config": "Überprüfen der Datenbankkonfiguration", - "Setting Build Number": "Build-Nummer einstellen" + "Setting Build Number": "Build-Nummer einstellen", + "A Legacy Version of October CMS is Detected": "Eine Legacy-Version des Oktober-CMS wird erkannt", + "Upgrade Configuration Files": "Konfigurationsdateien konvertieren", + "Runs the artisan command to create an environment file": "Führt den Befehl artisan aus, um eine Umgebungsdatei zu erstellen", + "Upgrade Config": "Konvertieren Sie Konfig", + "Upgrading Legacy Site": "Aktualisieren der Legacy-Site", + "Clearing Cache": "Cache leeren" } \ No newline at end of file diff --git a/lang/es.json b/lang/es.json index 6f560dc..7141f17 100644 --- a/lang/es.json +++ b/lang/es.json @@ -35,12 +35,13 @@ "Open Console": "Consola abierta", "Update Environment Variables": "Actualizar variables de entorno", "Modify the configuration values on the server": "Modificar los valores de configuración en el servidor.", - "Update Config": "Actualizar configuración", + "Update Environment": "Actualizar configuración", "View Deployment Key": "Ver clave de implementación", "Display the private key used to deploy to this server": "Muestra la clave privada utilizada para implementar en este servidor", "Show Key": "Mostrar clave", "Current Version": "Versión actual", "Active": "Activo", + "Legacy": "Legado", "Ready": "Listo", "Unreachable": "Inalcanzable", "Beacon Status": "Estado de la baliza", @@ -73,5 +74,11 @@ "Migrating Database": "Migración de la base de datos", "Building :type Archive": "Edificio type: Archivo", "Checking Database Config": "Comprobación de la configuración de la base de datos", - "Setting Build Number": "Configuración del número de compilación" + "Setting Build Number": "Configuración del número de compilación", + "A Legacy Version of October CMS is Detected": "Se detecta una versión heredada del CMS de octubre", + "Upgrade Configuration Files": "Convertir archivos de configuración", + "Runs the artisan command to create an environment file": "Ejecuta el comando artisan para crear un archivo de entorno.", + "Upgrade Config": "Convertir configuración", + "Upgrading Legacy Site": "Actualización del sitio heredado", + "Clearing Cache": "Borrar caché" } \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json index f507222..b1ab84f 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -35,12 +35,13 @@ "Open Console": "Ouvrez la console", "Update Environment Variables": "Mettre à jour les variables d'environnement", "Modify the configuration values on the server": "Modifier les valeurs de configuration sur le serveur", - "Update Config": "Mettre à jour la configuration", + "Update Environment": "Mettre à jour la configuration", "View Deployment Key": "Afficher la clé de déploiement", "Display the private key used to deploy to this server": "Afficher la clé privée utilisée pour déployer sur ce serveur", "Show Key": "Afficher la touche", "Current Version": "Version actuelle", "Active": "actif", + "Legacy": "Héritage", "Ready": "Prêt", "Unreachable": "Inaccessible", "Beacon Status": "État de la balise", @@ -73,5 +74,11 @@ "Migrating Database": "Migration de la base de données", "Building :type Archive": "Bâtiment archive de :type", "Checking Database Config": "Vérification de la configuration de la base de données", - "Setting Build Number": "Définition du numéro de build" + "Setting Build Number": "Définition du numéro de build", + "A Legacy Version of October CMS is Detected": "Une ancienne version du CMS d'octobre est détectée", + "Upgrade Configuration Files": "Convertir les fichiers de configuration", + "Runs the artisan command to create an environment file": "Exécute la commande artisan pour créer un fichier d'environnement", + "Upgrade Config": "Convertir la configuration", + "Upgrading Legacy Site": "Mise à niveau du site hérité", + "Clearing Cache": "Effacer le cache" } \ No newline at end of file diff --git a/lang/it.json b/lang/it.json index 211d49e..65bceaf 100644 --- a/lang/it.json +++ b/lang/it.json @@ -35,12 +35,13 @@ "Open Console": "Console aperta", "Update Environment Variables": "Aggiorna variabili d'ambiente", "Modify the configuration values on the server": "Modificare i valori di configurazione sul server", - "Update Config": "Aggiorna config", + "Update Environment": "Aggiorna config", "View Deployment Key": "Visualizza chiave di distribuzione", "Display the private key used to deploy to this server": "Visualizza la chiave privata utilizzata per la distribuzione su questo server", "Show Key": "Mostra chiave", "Current Version": "Versione corrente", "Active": "Attivo", + "Legacy": "Legacy", "Ready": "Pronto", "Unreachable": "Irraggiungibile", "Beacon Status": "Stato beacon", @@ -73,5 +74,11 @@ "Migrating Database": "Database in migrazione", "Building :type Archive": "Edificio :type Archivio", "Checking Database Config": "Controllo della configurazione del database", - "Setting Build Number": "Impostazione del numero di build" + "Setting Build Number": "Impostazione del numero di build", + "A Legacy Version of October CMS is Detected": "È stata rilevata una versione precedente di October CMS", + "Upgrade Configuration Files": "Converti file di configurazione", + "Runs the artisan command to create an environment file": "Esegue il comando artisan per creare un file di ambiente", + "Upgrade Config": "Converti configurazione", + "Upgrading Legacy Site": "Aggiornamento del sito precedente", + "Clearing Cache": "Cancellazione della cache" } \ No newline at end of file diff --git a/lang/nl.json b/lang/nl.json index c95c15f..0b9eed2 100644 --- a/lang/nl.json +++ b/lang/nl.json @@ -35,12 +35,13 @@ "Open Console": "Open de console", "Update Environment Variables": "Werk omgevingsvariabelen bij", "Modify the configuration values on the server": "Wijzig de configuratiewaarden op de server", - "Update Config": "Update Config", + "Update Environment": "Update Environment", "View Deployment Key": "Bekijk implementatiesleutel", "Display the private key used to deploy to this server": "Geef de persoonlijke sleutel weer die wordt gebruikt om op deze server te implementeren", "Show Key": "Toon sleutel", "Current Version": "Huidige versie", "Active": "Actief", + "Legacy": "Legacy", "Ready": "Klaar", "Unreachable": "Onbereikbaar", "Beacon Status": "Bakenstatus", @@ -73,5 +74,11 @@ "Migrating Database": "Database migreren", "Building :type Archive": "Gebouw :type Archief", "Checking Database Config": "Databaseconfiguratie controleren", - "Setting Build Number": "Build-nummer instellen" + "Setting Build Number": "Build-nummer instellen", + "A Legacy Version of October CMS is Detected": "Er is een oudere versie van October CMS gedetecteerd", + "Upgrade Configuration Files": "Converteer configuratiebestanden", + "Runs the artisan command to create an environment file": "Voert de artisan-opdracht uit om een omgevingsbestand te maken", + "Upgrade Config": "Converteer Config", + "Upgrading Legacy Site": "Verouderde site upgraden", + "Clearing Cache": "Cache wissen" } \ No newline at end of file diff --git a/lang/ru.json b/lang/ru.json index 9a851c2..3176ad0 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -35,12 +35,13 @@ "Open Console": "Открыть консоль", "Update Environment Variables": "Обновить переменные среды", "Modify the configuration values on the server": "Измените значения конфигурации на сервере", - "Update Config": "Обновить конфигурацию", + "Update Environment": "Обновить конфигурацию", "View Deployment Key": "Просмотреть ключ развертывания", "Display the private key used to deploy to this server": "Показать закрытый ключ, используемый для развертывания на этом сервере", "Show Key": "Показать ключ", "Current Version": "Текущая версия", "Active": "Активный", + "Legacy": "Наследие", "Ready": "Готов", "Unreachable": "Недоступен", "Beacon Status": "Статус маяка", @@ -73,5 +74,11 @@ "Migrating Database": "Перенос базы данных", "Building :type Archive": "type: тип Архив", "Checking Database Config": "Проверка конфигурации базы данных", - "Setting Build Number": "Установка номера сборки" + "Setting Build Number": "Установка номера сборки", + "A Legacy Version of October CMS is Detected": "Обнаружена устаревшая версия October CMS", + "Upgrade Configuration Files": "Конвертировать файлы конфигурации", + "Runs the artisan command to create an environment file": "Запускает команду artisan для создания файла среды", + "Upgrade Config": "Конвертировать конфигурацию", + "Upgrading Legacy Site": "Обновление устаревшего сайта", + "Clearing Cache": "Очистка кеша" } \ No newline at end of file diff --git a/lang/xx.json b/lang/xx.json index 38230cb..9ceb29e 100644 --- a/lang/xx.json +++ b/lang/xx.json @@ -35,12 +35,13 @@ "Open Console": "Open Console", "Update Environment Variables": "Update Environment Variables", "Modify the configuration values on the server": "Modify the configuration values on the server", - "Update Config": "Update Config", + "Update Environment": "Update Environment", "View Deployment Key": "View Deployment Key", "Display the private key used to deploy to this server": "Display the private key used to deploy to this server", "Show Key": "Show Key", "Current Version": "Current Version", "Active": "Active", + "Legacy": "Legacy", "Ready": "Ready", "Unreachable": "Unreachable", "Beacon Status": "Beacon Status", @@ -73,5 +74,11 @@ "Migrating Database": "Migrating Database", "Building :type Archive": "Building :type Archive", "Checking Database Config": "Checking Database Config", - "Setting Build Number": "Setting Build Number" + "Setting Build Number": "Setting Build Number", + "A Legacy Version of October CMS is Detected": "A Legacy Version of October CMS is Detected", + "Upgrade Configuration Files": "Convert Configuration Files", + "Runs the artisan command to create an environment file": "Runs the artisan command to create an environment file", + "Upgrade Config": "Convert Config", + "Upgrading Legacy Site": "Upgrading Legacy Site", + "Clearing Cache": "Clearing Cache" } diff --git a/lang/zh-cn.json b/lang/zh-cn.json index 2ca3424..f40d708 100644 --- a/lang/zh-cn.json +++ b/lang/zh-cn.json @@ -35,12 +35,13 @@ "Open Console": "打开控制台", "Update Environment Variables": "更新环境变量", "Modify the configuration values on the server": "修改服务器上的配置值", - "Update Config": "更新配置", + "Update Environment": "更新配置", "View Deployment Key": "查看部署密钥", "Display the private key used to deploy to this server": "显示用于部署到此服务器的私钥", "Show Key": "显示密钥", "Current Version": "当前版本", "Active": "积极的", + "Legacy": "遗产", "Ready": "准备好", "Unreachable": "无法到达", "Beacon Status": "信标状态", @@ -73,5 +74,11 @@ "Migrating Database": "迁移数据库", "Building :type Archive": ":type类型档案", "Checking Database Config": "检查数据库配置", - "Setting Build Number": "设置内部版本号" + "Setting Build Number": "设置内部版本号", + "A Legacy Version of October CMS is Detected": "检测到传统版本的十月CMS", + "Upgrade Configuration Files": "转换配置文件", + "Runs the artisan command to create an environment file": "运行artisan命令以创建环境文件", + "Upgrade Config": "转换配置", + "Upgrading Legacy Site": "升级旧版网站", + "Clearing Cache": "清除缓存" } \ No newline at end of file diff --git a/lang/zh-tw.json b/lang/zh-tw.json index 0c3ab99..58d1dbf 100644 --- a/lang/zh-tw.json +++ b/lang/zh-tw.json @@ -35,12 +35,13 @@ "Open Console": "打開控制台", "Update Environment Variables": "更新環境變量", "Modify the configuration values on the server": "修改服務器上的配置值", - "Update Config": "更新配置", + "Update Environment": "更新配置", "View Deployment Key": "查看部署密鑰", "Display the private key used to deploy to this server": "顯示用於部署到此服務器的私鑰", "Show Key": "顯示密鑰", "Current Version": "當前版本", "Active": "積極的", + "Legacy": "遺產", "Ready": "準備好", "Unreachable": "無法到達", "Beacon Status": "信標狀態", @@ -73,5 +74,11 @@ "Migrating Database": "遷移數據庫", "Building :type Archive": ":type類型檔案", "Checking Database Config": "檢查數據庫配置", - "Setting Build Number": "設置內部版本號" + "Setting Build Number": "設置內部版本號", + "A Legacy Version of October CMS is Detected": "檢測到傳統版本的十月CMS", + "Upgrade Configuration Files": "轉換配置文件", + "Runs the artisan command to create an environment file": "運行artisan命令以創建環境文件", + "Upgrade Config": "轉換配置", + "Upgrading Legacy Site": "升級舊版網站", + "Clearing Cache": "清除緩存" } \ No newline at end of file diff --git a/models/Server.php b/models/Server.php index bc605f8..33190fb 100644 --- a/models/Server.php +++ b/models/Server.php @@ -15,6 +15,7 @@ class Server extends Model const STATUS_ACTIVE = 'active'; const STATUS_READY = 'ready'; + const STATUS_LEGACY = 'legacy'; const STATUS_UNREACHABLE = 'unreachable'; /** @@ -80,7 +81,16 @@ public function testBeacon(): bool try { $response = $this->transmit('healthCheck'); $isInstalled = $response['appInstalled'] ?? false; - $wantCode = $isInstalled ? static::STATUS_ACTIVE : static::STATUS_READY; + $envFound = $response['envFound'] ?? false; + if (!$envFound) { + $wantCode = static::STATUS_LEGACY; + } + elseif (!$isInstalled) { + $wantCode = static::STATUS_READY; + } + else { + $wantCode = static::STATUS_ACTIVE; + } } catch (Exception $ex) { $wantCode = static::STATUS_UNREACHABLE; @@ -140,6 +150,7 @@ public function transmitShell($contents): array public function transmitFile(string $filePath, array $params = []): array { $response = Http::post($this->buildUrl('fileUpload', $params), function($http) use ($filePath) { + $http->maxRedirects = 0; $http->dataFile('file', $filePath); $http->data('filename', md5($filePath)); $http->data('filehash', md5_file($filePath)); @@ -167,11 +178,21 @@ protected function processTransmitResponse($response) traceLog($response); } + // Redirects seem to drop the POST variables and this is a security precaution + if (in_array($response->code, [301, 302])) { + $redirectTo = array_get($response->info, 'redirect_url'); + $redirectTo = explode("?", $redirectTo)[0]; + throw new ApplicationException( + 'Server responded with redirect ('.$redirectTo.')' + . ' please update the server address to exactly this and try again.' + ); + } + if ($response->code !== 201 && $response->code !== 400) { throw new ApplicationException( 'A valid response from a beacon was not found.' - .' '. - 'Add ?debug=1 to your URL, try again and check the logs.' + . ' ' + . 'Add ?debug=1 to your URL, try again and check the logs.' ); } diff --git a/models/server/fields_manage_legacy.yaml b/models/server/fields_manage_legacy.yaml new file mode 100644 index 0000000..17a4a9c --- /dev/null +++ b/models/server/fields_manage_legacy.yaml @@ -0,0 +1,21 @@ +# =================================== +# Form Field Definitions +# =================================== + +fields: + _tip1: + type: hint + mode: info + label: A Legacy Version of October CMS is Detected + + _action_action_convert_legacy: + type: partial + path: action_convert_legacy + + _action_run_shell: + type: partial + path: action_run_shell + + _action_view_key: + type: partial + path: action_view_key diff --git a/models/server/fields_upgrade_legacy.yaml b/models/server/fields_upgrade_legacy.yaml new file mode 100644 index 0000000..f276584 --- /dev/null +++ b/models/server/fields_upgrade_legacy.yaml @@ -0,0 +1,9 @@ +# =================================== +# Form Field Definitions +# =================================== + +fields: + _tip1: + type: hint + mode: info + label: This step will convert the configuration files to environment files on your server diff --git a/plugin.yaml b/plugin.yaml index 7e25696..b6f2eca 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -6,7 +6,7 @@ plugin: name: Deploy description: A simple way to deploy your application to a remote location. author: Alexey Bobkov, Samuel Georges - icon: icon-cloud + icon: icon-hdd-o homepage: https://github.com/rainlab/deploy-plugin settings: @@ -14,7 +14,7 @@ settings: label: Deploy description: Manage deployments category: CATEGORY_SYSTEM - icon: icon-cloud + icon: icon-hdd-o url: rainlab/deploy/servers order: 500 keywords: deploy diff --git a/widgets/Deployer.php b/widgets/Deployer.php index fecbaec..291ee06 100644 --- a/widgets/Deployer.php +++ b/widgets/Deployer.php @@ -98,10 +98,14 @@ public function onExecuteStep() case 'transmitScript': $scriptName = post('script'); $scriptVars = post('vars'); - if (!$scriptName || !$scriptVars) { + if (!$scriptName) { throw new ApplicationException('Missing script or vars'); } + if (!$scriptVars) { + $scriptVars = []; + } + $response = $this->findServerModelObject()->transmitScript($scriptName, $scriptVars); $statusCode = $response['status'] ?? null; if ($statusCode !== 'ok') {