diff --git a/Config/laraupdater.php b/Config/laraupdater.php index 360eddd..235ade0 100644 --- a/Config/laraupdater.php +++ b/Config/laraupdater.php @@ -1,7 +1,7 @@ for example: [1] OR [1,3,0] OR false * Generally, ADMIN have user_id=1; set FALSE to disable this check (not recommended) */ - 'allow_users_id' => [1], - - /* - * Laravel migrate settings - */ - 'migrate' => true, - /* - * Set the update check time period, to prevent update server overload. - * Set the number in minutes - */ - 'version_check_time' => 15, + 'allow_users_id' => [1] ]; diff --git a/lang/ar/laraupdater.php b/lang/ar/laraupdater.php deleted file mode 100644 index 5367cc2..0000000 --- a/lang/ar/laraupdater.php +++ /dev/null @@ -1,43 +0,0 @@ - 'LaraUpdater', - 'Return_to_App_HOME' => 'العودة للصفحة الرئيسية ', - 'ACTION_NOT_ALLOWED.' => 'الإجراء غير مصرّح به', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'النظام محدث بالفعل لآخر إصدار', - 'UPDATE_FOUND' => 'تم العثور على تحديث', - 'current_version' => "الإصدار الحالي", - 'DESCRIPTION' => 'الوصف', - 'Update_downloading_..' => 'جارٍ تحميل التحديث ........', - 'Error_during_download.' => 'حدث خطأ أثناء التحميل.', - 'OK' => 'موافق', - 'SYSTEM_Mantence_Mode' => 'وضع صيانة النظام', - 'ON' => 'مفعل', - 'OFF' => 'مقفل', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'تم تحديث النظام للإصدار', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'خطأ أثناء التحديث (!! افحص ملف التحديث المضغوط !!) -- حاول استعادة الحالة القديمة .......', - 'CHANGELOG' => 'سجل التغييرات', - 'Directory' => 'المجلد', - 'File' => 'ملف', - 'Commands_successfully_executed.' => 'تم تنفيذ الأوامر بنجاح.', - 'Error_during_commands_execution.' => ' حدث خطأ أثناء تنفيذ الأوامر.', - 'Could_not_save_new_update' => 'لم نستطع حفظ ملف التحديث (افحص تصارح الكتابة لمجلد tmp/). تم إلغاء التحديث.', - 'FAILED' => 'فشل', - 'Backup_folder_is_located_in:' => 'ملف النسخة الإحتياطية محفوظ في:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'تذكر استعادة حالة تشغيل النظام عبر سطر الأوامر:', - 'RESTORED' => 'تمت الإسستعادة', - 'Update_Now' => 'تحديث الآن', - 'Update_Available' => 'يتوفر تحديث للنظام ', - 'Updated' => 'تم التحديث', - 'Updating' => 'جارٍ التحديث', - 'error_try_again' => 'خطأ. حاول مرة أخرى' -]; diff --git a/lang/de/laraupdater.php b/lang/de/laraupdater.php deleted file mode 100644 index acbdabb..0000000 --- a/lang/de/laraupdater.php +++ /dev/null @@ -1,43 +0,0 @@ - 'LaraUpdater', - 'Return_to_App_HOME' => 'Zurück zur Startseote', - 'ACTION_NOT_ALLOWED.' => 'DIESE AKTION IST NICHT ERLAUBT', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'Das System benutzt bereits die neuste Version.', - 'UPDATE_FOUND' => 'Updater verfügbar', - 'current_version' => "aktuelle Version", - 'DESCRIPTION' => 'Beschreibung', - 'Update_downloading_..' => 'Update wird heruntergeladen ...........', - 'Error_during_download.' => 'Fehler während des Herunterladens', - 'OK' => 'OK', - 'SYSTEM_Mantence_Mode' => 'SYSTEM Wartungs Modus', - 'ON' => 'AN', - 'OFF' => 'AUS', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'Das System wurde aktualisiert auf Version ', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'FEHLER WÄHREND DES UPDATES (!!prüfen Sie das Update-Archiv!!) -- Versuche alten Stand wiederherzustellen ........... ', - 'CHANGELOG' => 'CHANGELOG', - 'Directory' => 'Verzeichnis', - 'File' => 'Datei', - 'Commands_successfully_executed.' => 'Befehle wurden erfolgreich ausgeführt.', - 'Error_during_commands_execution.' => ' Fehler beim Ausführen der Befehle', - 'Could_not_save_new_update' => 'Neues Update konnte nicht gespeichert werden (prüfen Sie die Ordnerberechtigung für tmp). Update abgebrochen.', - 'FAILED' => 'FAILED', - 'Backup_folder_is_located_in:' => 'Backup-Ordner befindet sich in:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'Denken Sie daran, den Wartungsmodus zu deaktieren (shell php artisan up):', - 'RESTORED' => 'Wiederhergestellt', - 'Update_Now' => 'Jetzt aktualisieren', - 'Update_Available' => 'Update verfügbar', - 'Updated' => 'Aktualisiert', - 'Updating' => 'Aktualisiere', - 'error_try_again' => 'Fehler. Bitte erneut versuchen' -]; diff --git a/lang/en/laraupdater.php b/lang/en/laraupdater.php index 79da718..fddbe00 100644 --- a/lang/en/laraupdater.php +++ b/lang/en/laraupdater.php @@ -1,43 +1,35 @@ 'LaraUpdater', - 'Return_to_App_HOME' => 'Return to App HOME ', - 'ACTION_NOT_ALLOWED.' => 'ACTION NOT ALLOWED', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'Your System IS ALREADY UPDATED to last version', - 'UPDATE_FOUND' => 'UPDATE FOUND', - 'current_version' => "current version", - 'DESCRIPTION' => 'DESCRIPTION', - 'Update_downloading_..' => 'Update, downloading ...........', - 'Error_during_download.' => 'Error during download.', - 'OK' => 'OK', - 'SYSTEM_Mantence_Mode' => 'SYSTEM Mantence Mode', - 'ON' => 'ON', - 'OFF' => 'OFF', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'SYSTEM IS NOW UPDATED TO VERSION', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'ERROR DURING UPDATE (!!check the update archive!!) --TRY to restore OLD status ........... ', - 'CHANGELOG' => 'CHANGELOG', - 'Directory' => 'Directory', - 'File' => 'File', - 'Commands_successfully_executed.' => 'Commands successfully executed.', - 'Error_during_commands_execution.' => ' Error during commands execution.', - 'Could_not_save_new_update' => 'Could not save new update (check tmp/ write permission). Update aborted.', - 'FAILED' => 'FAILED', - 'Backup_folder_is_located_in:' => 'Backup folder is located in:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'Remember to restore System UP-Status through shell command:', - 'RESTORED' => 'RESTORED', - 'Update_Now' => 'Update Now', - 'Update_Available' => 'Update Available', - 'Updated' => 'Updated', - 'Updating' => 'Updating', - 'error_try_again' => 'Error.Try Again' -]; + return [ + 'SYSTEM_VERSION' => 'System\'s version: ', + 'PERMISSION_DENIED' => 'The user is not authorized to perform updates.', + 'ALREADY_UPDATED' => 'The system IS ALREADY UPDATED to last version.', + 'BACKUP' => 'Backup folder created.', + 'BACKUP_FOUND' => 'Backup found: ', + 'DOWNLOADING' => 'Downloading the update...', + 'DOWNLOADING_SUCCESS' => 'Update downloaded successfully.', + 'DOWNLOADING_ERROR' => 'An error occurred during the download.', + 'MAINTENANCE_MODE_ON' => 'Maintenance mode: ON', + 'MAINTENANCE_MODE_OFF' => 'Maintenance mode: OFF', + 'INSTALLATION_SUCCESS' => 'Update installed successfully.', + 'INSTALLATION_ERROR' => 'An error occurred during the installation.', + 'RECOVERY' => 'LaraUpdater is attempting to recovery your system from backup.', + 'RECOVERY_SUCCESS' => 'Recovery completed successfully.', + 'RECOVERY_ERROR' => 'Recovery failed, try it manually. Remember: \'php artisan up\' to disable the maintenance mode.', + 'EXCEPTION' => 'An exception occurred: ', + 'CHANGELOG' => 'Changelog:', + 'DIRECTORY_CREATED' => 'Directory created: ', + 'FILE_EXIST' => 'File exist: ', + 'FILE_COPIED' => 'File copied: ', + 'EXECUTE_UPDATE_SCRIPT' => 'Execute the script included into the update.', + 'TEMP_CLEANED' => 'Temporary files deleted.', + ]; diff --git a/lang/fa/laraupdater.php b/lang/fa/laraupdater.php deleted file mode 100644 index da196c3..0000000 --- a/lang/fa/laraupdater.php +++ /dev/null @@ -1,43 +0,0 @@ - 'بروز کننده هسته لاراول', - 'Return_to_App_HOME' => 'بازگشت به صفخه اصلی برنامه', - 'ACTION_NOT_ALLOWED.' => 'این اقدام قابل انجام توسط شما نیست', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'هسته فعلی شما بروز می باشد.', - 'UPDATE_FOUND' => 'بروز رسانی جدید', - 'current_version' => "نسخه فعلی", - 'DESCRIPTION' => 'توضیحات', - 'Update_downloading_..' => 'بروز رسانی، در حال دریافت ...', - 'Error_during_download.' => 'خطا در دریافت فایل', - 'OK' => 'اوکی', - 'SYSTEM_Mantence_Mode' => 'سیستم در حال نگه داری', - 'ON' => 'فعال', - 'OFF' => 'غیر فعال', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'نسخه بروز شده هسته فعلی ', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'خطا در زمان بروز رسانی (!!check the update archive!!) --تلاش برای بازگردانی ........... ', - 'CHANGELOG' => 'ثبت تغییرات', - 'Directory' => 'مسیر پوشه', - 'File' => 'فایل', - 'Commands_successfully_executed.' => 'دستورات به درستی اجرا شد.', - 'Error_during_commands_execution.' => ' خطا در اجرای دستورات رخ داد.', - 'Could_not_save_new_update' => 'بروز رسانی رد شد. دسترسی مسیر پوشه را بررسی کنید.', - 'FAILED' => 'دچار مشکل شد', - 'Backup_folder_is_located_in:' => 'مسیر پوشه پشتیبانی:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'یادآوری برای بازگردانی مجدد سیستم توسط دستور:', - 'RESTORED' => 'بازگردانی شد', - 'Update_Now' => 'بروز کن', - 'Update_Available' => 'نسخه جدید', - 'Updated' => 'بروز شد', - 'Updating' => 'بروزرسانی', - 'error_try_again' => 'خطا! دوباره تلاش کنید' -]; diff --git a/lang/hu/laraupdater.php b/lang/hu/laraupdater.php deleted file mode 100644 index 05a8b2a..0000000 --- a/lang/hu/laraupdater.php +++ /dev/null @@ -1,43 +0,0 @@ - 'LaraUpdater', - 'Return_to_App_HOME' => 'Vissza a Főoldalra ', - 'ACTION_NOT_ALLOWED.' => 'AZ ESEMÉNY NEM ENGEDÉLYEZETT', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'A program MÁR FRISSÜLT a legutóbbi változatra', - 'UPDATE_FOUND' => 'FRISSÍTÉST TALÁLTAM', - 'current_version' => "jelenlegi verzió", - 'DESCRIPTION' => 'LEÍRÁS', - 'Update_downloading_..' => 'Frissítés, letöltés ...........', - 'Error_during_download.' => 'Hiba a letöltés közben.', - 'OK' => 'OK', - 'SYSTEM_Mantence_Mode' => 'RENDSZER Karbantartás Mód', - 'ON' => 'BE', - 'OFF' => 'KI', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'A RENDSZER MOST MÁR A LEGFRISSEBB VÁLTOZATTAL FUT', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'HIBA A FRISSÍTÉS KÖZBEN (!!ellenőrizd a frissítési fájlt!!) --MEGPRÓBÁLOM visszaállítani a RÉGI állapotot ........... ', - 'CHANGELOG' => 'VÁLTOZÁSI NAPLÓ', - 'Directory' => 'Könyvtár', - 'File' => 'Fájl', - 'Commands_successfully_executed.' => 'A parancsok sikeresen lefutottak.', - 'Error_during_commands_execution.' => ' Hiba a parancsok futtatása során.', - 'Could_not_save_new_update' => 'Nem tudom elmenteni az új frissítést (ellenőrizd a tmp/ könyvtár írási jogát). Frissítés megszakítva.', - 'FAILED' => 'HIBA', - 'Backup_folder_is_located_in:' => 'A mentés könyvtára megtalálható itt:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'Ne felejtsd el visszaállítani a rendszert az UP paranccsal a parancssorban:', - 'RESTORED' => 'VISSZAÁLLÍTVA', - 'Update_Now' => 'Frissítés Most', - 'Update_Available' => 'Frissítés érhető el!', - 'Updated' => 'Frissítve', - 'Updating' => 'Frissítés', - 'error_try_again' => 'Hiba. Próbáld újra' -]; diff --git a/lang/id/laraupdater.php b/lang/id/laraupdater.php deleted file mode 100644 index f081bc0..0000000 --- a/lang/id/laraupdater.php +++ /dev/null @@ -1,43 +0,0 @@ - 'LaraUpdater', - 'Return_to_App_HOME' => 'Kembali ke BERANDA ', - 'ACTION_NOT_ALLOWED.' => 'TINDAKAN TIDAK DIIZINKAN', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'Sistem Anda SUDAH DIPERBARUI ke versi terakhir', - 'UPDATE_FOUND' => 'PEMBARUAN DITEMUKAN', - 'current_version' => "versi sekarang", - 'DESCRIPTION' => 'DESKRIPSI', - 'Update_downloading_..' => 'Pembaharuan, sedang diunduh ...........', - 'Error_during_download.' => 'Kesalahan selama mengunduh.', - 'OK' => 'OK', - 'SYSTEM_Mantence_Mode' => 'Mode Pemeliharaan SISTEM', - 'ON' => 'ON', - 'OFF' => 'OFF', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'SISTEM SEKARANG DIPERBARUI KE VERSI', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'ERROR SELAMA PEMBARUAN (!! periksa arsip pembaruan !!) --COBA untuk memulihkan status LAMA ........... ', - 'CHANGELOG' => 'CHANGELOG', - 'Directory' => 'Direktori', - 'File' => 'File', - 'Commands_successfully_executed.' => 'Perintah berhasil dijalankan.', - 'Error_during_commands_execution.' => ' Kesalahan selama eksekusi perintah.', - 'Could_not_save_new_update' => 'Tidak dapat menyimpan pembaruan terbaru (periksa tmp / tulis izin). Pembaruan dibatalkan.', - 'FAILED' => 'GAGAL', - 'Backup_folder_is_located_in:' => 'Folder cadangan terletak di:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'Ingatlah untuk memulihkan Status-UP Sistem melalui perintah shell:', - 'RESTORED' => 'DIPULIHKAN', - 'Update_Now' => 'Perbarui sekarang', - 'Update_Available' => 'Pembaruan tersedia', - 'Updated' => 'Diperbarui', - 'Updating' => 'Memperbarui', - 'error_try_again' => 'Error. Coba Lagi' -]; diff --git a/lang/it/laraupdater.php b/lang/it/laraupdater.php new file mode 100644 index 0000000..5b7d4d2 --- /dev/null +++ b/lang/it/laraupdater.php @@ -0,0 +1,35 @@ + 'Versione del sistema: ', + 'PERMISSION_DENIED' => 'Utente non autorizzato ad eseguire aggiornamenti.', + 'ALREADY_UPDATED' => 'Il sistema risulta aggiornato all\'ultima versione.', + 'BACKUP' => 'Cartella di Backup creata.', + 'BACKUP_FOUND' => 'Backup trovato: ', + 'DOWNLOADING' => 'Download dell\'aggiornamento...', + 'DOWNLOADING_SUCCESS' => 'Aggiornamento scaricato con successo.', + 'DOWNLOADING_ERROR' => 'Errore durante il download.', + 'MAINTENANCE_MODE_ON' => 'Maintenance mode: ON', + 'MAINTENANCE_MODE_OFF' => 'Maintenance mode: OFF', + 'INSTALLATION_SUCCESS' => 'Aggiornamento installato con successo.', + 'INSTALLATION_ERROR' => 'Errore durante l\'installazione.', + 'RECOVERY' => 'LaraUpdater sta provando a recuperare il sistema dal backup.', + 'RECOVERY_SUCCESS' => 'Recupero completato con successo.', + 'RECOVERY_ERROR' => 'Recupero fallito, provare manualmente. Nota: \'php artisan up\' disabilita la maintenance mode.', + 'EXCEPTION' => 'Si è verificata una exception: ', + 'CHANGELOG' => 'Changelog:', + 'DIRECTORY_CREATED' => 'Directory creata: ', + 'FILE_EXIST' => 'File esistente: ', + 'FILE_COPIED' => 'File copiato: ', + 'EXECUTE_UPDATE_SCRIPT' => 'Esecuzione dello script di aggiornamento.', + 'TEMP_CLEANED' => 'File temporanei eliminati.', + ]; diff --git a/lang/tr/laraupdater.php b/lang/tr/laraupdater.php deleted file mode 100644 index b2d9865..0000000 --- a/lang/tr/laraupdater.php +++ /dev/null @@ -1,42 +0,0 @@ - 'Güncelleyici', - 'Return_to_App_HOME' => 'Uygulamaya Geri Dön ', - 'ACTION_NOT_ALLOWED.' => 'İzin Verilmeyen Yöntem', - 'Your_System_IS_ALREADY_UPDATED_to_last version' => 'Sisteminiz zaten son sürüme yükseltilmiş', - 'UPDATE_FOUND' => 'GÜNCELLEME BULUNDU', - 'current_version' => "aktif versiyon", - 'DESCRIPTION' => 'AÇIKLAMA', - 'Update_downloading_..' => 'Güncelleniyor, dosyalar indiriliyor ...........', - 'Error_during_download.' => 'İndirme sırasında hata oluştu.', - 'OK' => 'TAMAM', - 'SYSTEM_Mantence_Mode' => 'Sistem Bakım Modu', - 'ON' => 'AÇIK', - 'OFF' => 'KAPALI', - 'SYSTEM_IS_NOW_UPDATED_TO_VERSION' => 'Sistem Güncel versiyona yükseltildi', - 'ERROR_DURING_UPDATE_(!!check_the_update_archive!!)' => 'GÜNCELLEME YAPILIRKEN HATA OLUŞTU (!! güncelleme arşivini kontrol edin !!) - ESKİ durumuna geri yükleniyor ...........', - 'CHANGELOG' => 'Değişim Günlüğü', - 'Directory' => 'Dizin', - 'File' => 'Dosya', - 'Commands_successfully_executed.' => 'Komutlar başarıyla yürütüldü.', - 'Error_during_commands_execution.' => ' Komutlar yürütme sırasında hata oluştu.', - 'Could_not_save_new_update' => 'Yeni güncelleme indirilemedi(tmp/ yazma iznini ve yeterli disk alanı olup olmadığını kontrol edin). Güncelleme iptal edildi.', - 'FAILED' => 'BAŞARISIZ', - 'Backup_folder_is_located_in:' => 'Yedekleme klasörü:', - 'Remember_to_restore_System_UP-Status_through_shell_command:' => 'Shell komutu ile Sistemi Durumunu geri yüklemeyi unutmayın.Sistem Yöneticisine başvurunuz. komut:', - 'RESTORED' => 'GERİ YÜKLENDİ', - 'Update_Now' => 'Hemen Güncelle', - 'Update_Available' => 'Güncelleme Mevcut', - 'Updated' => 'Güncellendi', - 'Updating' => 'Güncelleniyor', - 'error_try_again' => 'Hata oluştu.Tekrar deneyiniz' -]; diff --git a/src/LaraUpdaterController.php b/src/LaraUpdaterController.php index 90f4f21..51c7e08 100644 --- a/src/LaraUpdaterController.php +++ b/src/LaraUpdaterController.php @@ -1,276 +1,267 @@ id, config('laraupdater.allow_users_id')) === true ) return true; - } + private function checkPermission() { + if( config('laraupdater.allow_users_id') !== null ) + if( config('laraupdater.allow_users_id') === false || in_array(Auth::User()->id, config('laraupdater.allow_users_id')) === true ) + return true; return false; } + + private function log($msg, $append_response=false, $type='info'){ + //Response HTML + if($append_response) + $this->response_html .= $msg . "
"; + //Log + $header = "LaraUpdater - "; + if($type == 'info') + Log::info($header . '[info]' . $msg); + elseif($type == 'warn') + Log::error($header . '[warn]' . $msg); + elseif($type == 'err') + Log::error($header . '[err]' . $msg); + else + return; + } + /* * Download and Install Update. */ public function update() - { - echo "

".trans("laraupdater.LaraUpdater")."

"; - echo '

'.trans("laraupdater.Return_to_App_HOME").'

'; + { + $this->log( trans("laraupdater.SYSTEM_VERSION") . $this->getCurrentVersion, true, 'info' ); if( ! $this->checkPermission() ){ - echo trans("laraupdater.ACTION_NOT_ALLOWED."); - exit; + $this->log( trans("laraupdater.PERMISSION_DENIED."), true, 'warn' ); + return; } - $lastVersionInfo = $this->getLastVersion(); + $last_version_info = $this->getLastVersion(); + $last_version = null; - if ( $lastVersionInfo['version'] <= $this->getCurrentVersion() ){ - echo '

» '.trans("laraupdater.Your_System_IS_ALREADY_UPDATED_to_last version").' !

'; - exit; + if ( $last_version_info['version'] <= $this->getCurrentVersion() ){ + $this->log( trans("laraupdater.ALREADY_UPDATED"), true, 'info' ); + return; } try{ - $this->tmp_backup_dir = base_path().'/backup_'.date('Ymd'); - - echo '

'.trans("laraupdater.UPDATE_FOUND").': '.$lastVersionInfo['version'].' ('.trans("laraupdater.current_version").': '.$this->getCurrentVersion().')

'; - echo '

'.trans("laraupdater.DESCRIPTION").': '.$lastVersionInfo['description'].'

'; - echo '

» '.trans("laraupdater.Update_downloading_..").' '; - $update_path = null; - if( ($update_path = $this->download($lastVersionInfo['archive'])) === false) - throw new \Exception(trans("laraupdater.Error_during_download.")); + if( ($last_version = $this->download($last_version_info['archive'])) === false){ + return; + } - echo trans("laraupdater.OK").'

'; + Artisan::call('down'); // Maintenance mode ON + $this->log( trans("laraupdater.MAINTENANCE_MODE_ON"), true, 'info' ); - Artisan::call('down'); - echo '

» '.trans("laraupdater.SYSTEM_Mantence_Mode").' => '.trans("laraupdater.ON").'

'; + if( ($status = $this->install($last_version)) === false ){ + $this->log( trans("laraupdater.INSTALLATION_ERROR"), true, 'err' ); + return; + } + $this->setCurrentVersion($last_version_info['version']); //update system version + $this->log( trans("laraupdater.INSTALLATION_SUCCESS"), true, 'info' ); - $status = $this->install($lastVersionInfo['version'], $update_path, $lastVersionInfo['archive']); + $this->log( trans("laraupdater.SYSTEM_VERSION") . $this->getCurrentVersion, true, 'info' ); - if($status){ - if( config('laraupdater.migrate')==true ) { - try { - Artisan::call('migrate'); - }catch(Exception $e) { - throw new \Exception(trans("laraupdater.Error_during_download.")); - } - } - $this->setCurrentVersion($lastVersionInfo['version']); //update system version - Artisan::call('up'); //restore system UP status - echo '

» '.trans("laraupdater.SYSTEM_Mantence_Mode").' => '.trans("laraupdater.OFF").'

'; - echo '

'.trans("laraupdater.SYSTEM_IS_NOW_UPDATED_TO_VERSION").': '.$lastVersionInfo['version'].'

'; - }else - throw new \Exception(trans("laraupdater.Error_during_download.")); + Artisan::call('up'); // Maintenance mode OFF + $this->log( trans("laraupdater.MAINTENANCE_MODE_OFF"), true, 'info' ); }catch (\Exception $e) { - echo '

'.trans("laraupdater.ERROR_DURING_UPDATE_(!!check_the_update_archive!!)"); - - $this->restore(); - - echo '

'; + $this->log( trans("laraupdater.EXCEPTION") . '' . $e->getMessage() . '', true, 'err' ); + $this->recovery(); } } - private function install($lastVersion, $update_path, $archive) + private function install($archive) { - try{ + try{ $execute_commands = false; - $upgrade_cmds_filename = 'upgrade.php'; - $upgrade_cmds_path = base_path().config('laraupdater.tmp_path').'/'.$upgrade_cmds_filename; - - $zip = new ZipArchive(); - $zip->open($update_path); - $extract_tmp_path = base_path().config('laraupdater.tmp_path').'/update'; - $zip->extractTo($extract_tmp_path); - - echo '

'.trans("laraupdater.CHANGELOG").':

'; - echo ''; - $zip->close(); if($execute_commands == true){ - if(file_exists($upgrade_cmds_path)) { - include ($upgrade_cmds_path); - - if(main()) //upgrade-VERSION.php contains the 'main()' method with a BOOL return to check its execution. - echo '

» '. trans("laraupdater.Commands_successfully_executed.") .'

'; - else - echo '

»'. trans("laraupdater.Error_during_commands_execution.") .'

'; - - unlink($upgrade_cmds_path); - File::delete($upgrade_cmds_path); //clean TMP - } else { - echo '

»'. trans("laraupdater.Error_during_commands_execution.") .'

'; - } + require_once($update_script); + // upgrade-VERSION.php contains the 'main()' method with a BOOL return to check its execution. + main(); + unlink($update_script); + $this->log( trans("laraupdater.EXECUTE_UPDATE_SCRIPT") . ' (\'upgrade.php\')', true, 'info' ); } - File::delete($update_path); //clean TMP - File::deleteDirectory($this->tmp_backup_dir); //remove backup temp folder - File::deleteDirectory($extract_tmp_path); //remove zip temp folder - Cache::forget('laraupdater_lastversion'); + File::delete($update_path); + File::deleteDirectory($this->tmp_backup_dir); + $this->log( trans("laraupdater.TEMP_CLEANED"), true, 'info' ); - } catch (\Exception $e) { return false; } + }catch (\Exception $e) { + $this->log( trans("laraupdater.EXCEPTION") . '' . $e->getMessage() . '', true, 'err' ); + return false; + } return true; } /* - * Download Update from $update_baseurl to $tmp_path (local folder). + * Download Update from $update_baseurl to $tmp_folder_name (local folder). */ - private function download($update_name) - { - try{ - if(!file_exists(base_path().config('laraupdater.tmp_path'))) { - File::makeDirectory(base_path().config('laraupdater.tmp_path'), 0750); - } - $filename_tmp = base_path().config('laraupdater.tmp_path').'/'.$update_name; - - if ( !is_file( $filename_tmp ) ) { - $newUpdate = file_get_contents(config('laraupdater.update_baseurl').'/'.$update_name); + private function download($filename) { + $this->log( trans("laraupdater.DOWNLOADING"), true, 'info' ); - $dlHandler = fopen($filename_tmp, 'w'); + $tmp_folder_name = base_path().'/'.config('laraupdater.tmp_folder_name'); - if ( !fwrite($dlHandler, $newUpdate) ){ - echo '

'.trans("laraupdater.Could_not_save_new_update").'

'; - exit(); - } - } + if ( !is_dir($tmp_folder_name) ) + File::makeDirectory($tmp_folder_name, $mode = 0755, true, true); + + try{ + $local_file = $tmp_folder_name.'/'.$filename; + $remote_file_url = config('laraupdater.update_baseurl').'/'.$filename; + + $update = file_get_contents($remote_file_url); + file_put_contents($local_file, $update); - }catch (\Exception $e) { return false; } + }catch (\Exception $e) { + $this->log( trans("laraupdater.DOWNLOADING_ERROR"), true, 'err' ); + $this->log( trans("laraupdater.EXCEPTION") . '' . $e->getMessage() . '', true, 'err' ); + return false; + } - return $filename_tmp; + $this->log( trans("laraupdater.DOWNLOADING_SUCCESS"), true, 'info' ); + return $local_file; } /* - * Return current version (as plain text). + * Current version ('version.txt' in main folder) */ - public function getCurrentVersion(){ + public function getCurrentVersion() { // todo: env file version $version = File::get(base_path().'/version.txt'); - return trim($version); + return $version; } - - /* - * Check if a new Update exist. - */ - public function check() - { - $lastVersionInfo = $this->getLastVersion(); - if( version_compare($lastVersionInfo['version'], $this->getCurrentVersion(), ">") ) - return $lastVersionInfo; // Return full array so we can display change log in notification - - return ''; + private function setCurrentVersion($version) { + // todo: env file version + File::put(base_path().'/version.txt', $version); } /* - * Get the update description. + * Check if a new Update exist. */ - public function getDescription() - { - $lastVersionInfo = $this->getLastVersion(); - if( version_compare($lastVersionInfo['version'], $this->getCurrentVersion(), ">") ) - return $lastVersionInfo['description']; - + public function check() { + $last_version = $this->getLastVersion(); + if( version_compare($last_version['version'], $this->getCurrentVersion(), ">") ) + return $last_version; return ''; } - private function setCurrentVersion($last){ - File::put(base_path().'/version.txt', $last); //UPDATE $current_version to last version + private function getLastVersion() { + $last_version = file_get_contents(config('laraupdater.update_baseurl').'/laraupdater.json'); + $last_version = json_decode($last_version, true); + // $last_version : ['version' => $v, 'archive' => 'RELEASE-$v.zip', 'description' => 'plainText']; + return $last_version; } - private function getLastVersion(){ - $content = Cache::remember('laraupdater_lastversion', (config('laraupdater.version_check_time') * 60), function () { - return file_get_contents(config('laraupdater.update_baseurl').'/laraupdater.json'); - }); - $content = json_decode($content, true); - return $content; //['version' => $v, 'archive' => 'RELEASE-$v.zip', 'description' => 'plain text...']; - } + /* + * Backup files before performing the update. + */ + private function backup($filename) { + if( !isset($this->tmp_backup_dir) ) + $this->tmp_backup_dir = base_path().'/backup_'.date('Ymd'); - private function backup($filename){ - $backup_dir = $this->tmp_backup_dir; + if ( !is_dir($backup_dir) ) + File::makeDirectory($backup_dir, $mode = 0755, true, true); - if ( !is_dir($backup_dir) ) File::makeDirectory($backup_dir, $mode = 0755, true, true); - if ( !is_dir($backup_dir.'/'.dirname($filename)) ) File::makeDirectory($backup_dir.'/'.dirname($filename), $mode = 0755, true, true); + if ( !is_dir($backup_dir.'/'.dirname($filename)) ) + File::makeDirectory($backup_dir.'/'.dirname($filename), $mode = 0755, true, true); File::copy(base_path().'/'.$filename, $backup_dir.'/'.$filename); //to backup folder } - private function restore(){ - if( !isset($this->tmp_backup_dir) ) + /* + * Recovery system from the last backup. + */ + private function recovery(){ + $this->log( trans("laraupdater.RECOVERY") . '' . $e . '', true, 'info' ); + + if( !isset($this->tmp_backup_dir) ){ $this->tmp_backup_dir = base_path().'/backup_'.date('Ymd'); + $this->log( trans("laraupdater.BACKUP_FOUND") . '' . $this->tmp_backup_dir . '', true, 'info' ); + } try{ $backup_dir = $this->tmp_backup_dir; $backup_files = File::allFiles($backup_dir); - foreach ($backup_files as $file){ $filename = (string)$file; $filename = substr($filename, (strlen($filename)-strlen($backup_dir)-1)*(-1)); - echo $backup_dir.'/'.$filename." => ".base_path().'/'.$filename; File::copy($backup_dir.'/'.$filename, base_path().'/'.$filename); //to respective folder } }catch(\Exception $e) { - echo "Exception => ".$e->getMessage(); - echo "
[ ".trans("laraupdater.FAILED")." ]"; - echo "
".trans("laraupdater.Backup_folder_is_located_in:")." ".$backup_dir."."; - echo "
".trans("laraupdater.Remember_to_restore_System_UP-Status_through_shell_command:")." php artisan up."; + $this->log( trans("laraupdater.RECOVERY_ERROR"), true, 'err' ); + $this->log( trans("laraupdater.EXCEPTION") . '' . $e->getMessage() . '', true, 'err' ); return false; } - echo "[ ".trans("laraupdater.RESTORED")." ]"; + $this->log( trans("laraupdater.RECOVERY_SUCCESS"), true, 'info' ); return true; } -} +} \ No newline at end of file diff --git a/src/LaraUpdaterServiceProvider.php b/src/LaraUpdaterServiceProvider.php index 41c2490..d62d858 100644 --- a/src/LaraUpdaterServiceProvider.php +++ b/src/LaraUpdaterServiceProvider.php @@ -1,7 +1,7 @@ publishes([ __DIR__ . '/../Config/laraupdater.php' => config_path('laraupdater.php'), ], 'laraupdater'); + $this->publishes([ __DIR__ . '/../config/laraupdater.php' => config_path('laraupdater.php'), ], 'laraupdater'); $this->publishes([__DIR__ . '/../lang' => resource_path('lang')], 'laraupdater'); $this->publishes([__DIR__.'/../views' => resource_path('views/vendor/laraupdater')], 'laraupdater'); - $this->loadRoutesFrom(__DIR__ . '/Http/routes.php'); + $this->loadRoutesFrom(__DIR__ . '/http/routes.php'); $this->loadTranslationsFrom(__DIR__ . '/lang', 'laraupdater'); - } public function register() diff --git a/views/laraupdater_check_update.blade.php b/views/laraupdater_check_update.blade.php deleted file mode 100644 index 84221e3..0000000 --- a/views/laraupdater_check_update.blade.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/views/notification.blade.php b/views/notification.blade.php new file mode 100644 index 0000000..e171fef --- /dev/null +++ b/views/notification.blade.php @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + \ No newline at end of file