From d98644277c73ff6e91fa7dc91435ce3bc705ddf6 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Fri, 7 Aug 2015 13:31:15 -0700 Subject: [PATCH] Added isSymlink logic to determine if Grav is symbolically linked or not. --- admin.php | 3 ++- classes/controller.php | 8 ++------ classes/gpm.php | 10 ++++++++++ themes/grav/js/admin-all.js | 13 ++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/admin.php b/admin.php index f6a22abb..9c6dce3e 100644 --- a/admin.php +++ b/admin.php @@ -270,7 +270,8 @@ class AdminPlugin extends Plugin "assets" => $gpm->grav->getAssets(), "version" => GRAV_VERSION, "available" => $gpm->grav->getVersion(), - "date" => $gpm->grav->getDate() + "date" => $gpm->grav->getDate(), + "isSymlink" => $gpm->grav->isSymlink() ]; echo json_encode([ diff --git a/classes/controller.php b/classes/controller.php index 1a2c7362..b9050328 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -4,6 +4,7 @@ namespace Grav\Plugin; use Grav\Common\Cache; use Grav\Common\Config\Config; use Grav\Common\Filesystem\Folder; +use Grav\Common\GPM\Installer; use Grav\Common\Grav; use Grav\Common\Themes; use Grav\Common\Uri; @@ -705,17 +706,12 @@ class AdminController return; } - if (is_link(ROOT_DIR . 'index.php')) { - $this->admin->json_response = ['status' => 'error', 'message' => 'Cannot upgrade: Grav is symlinked. Please upgrade manually']; - return false; - } - $result = \Grav\Plugin\Admin\Gpm::selfupgrade(); if ($result) { $this->admin->json_response = ['status' => 'success', 'message' => 'Grav was successfully updated to ']; } else { - $this->admin->json_response = ['status' => 'error', 'message' => 'Grav update failed']; + $this->admin->json_response = ['status' => 'error', 'message' => 'Grav update failed
' . Installer::lastErrorMsg()]; } return true; diff --git a/classes/gpm.php b/classes/gpm.php index ab39cd0c..97375393 100644 --- a/classes/gpm.php +++ b/classes/gpm.php @@ -168,6 +168,16 @@ class Gpm public static function selfupgrade() { $upgrader = new Upgrader(); + + if (!Installer::isGravInstance(GRAV_ROOT)) { + return false; + } + + if (is_link(GRAV_ROOT . DS . 'index.php')) { + Installer::setError(Installer::IS_LINK); + return false; + } + $update = $upgrader->getAssets()['grav-update']; $tmp = CACHE_DIR . 'tmp/Grav-' . uniqid(); $file = self::_downloadSelfupgrade($update, $tmp); diff --git a/themes/grav/js/admin-all.js b/themes/grav/js/admin-all.js index 50d4853f..2b597b5c 100644 --- a/themes/grav/js/admin-all.js +++ b/themes/grav/js/admin-all.js @@ -10,6 +10,13 @@ var getState = function(){ return loadValues.toString(); }; +var bytesToSize = function(bytes) { + var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; + if (bytes == 0) return '0 Byte'; + var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; +}; + $(function () { jQuery.substitute = function(str, sub) { return str.replace(/\{(.+?)\}/g, function($0, $1) { @@ -239,13 +246,17 @@ $(function () { content = 'Grav v{available} is now available! (Current: v{version}) ', button = ''; + if (grav.isSymlink) { + button = ''; + } + content = jQuery.substitute(content, {available: grav.available, version: grav.version}); $('[data-gpm-grav]').addClass('grav').html('

' + icon + content + button + '

'); window.grav_available_version = grav.available; } $('#grav-update-button').on('click', function() { - $(this).html('Updating... please wait, downloading 2MB+..'); + $(this).html('Updating... please wait, downloading ' + bytesToSize(grav.assets['grav-update'].size) + '..'); }); // dashboard