diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index a1d2f5c16..89197c48e 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -447,6 +447,32 @@ class UpdateManager // Themes // + /** + * Downloads a theme from the update server. + * @param string $name Theme name. + * @param string $hash Expected file hash. + * @return self + */ + public function downloadTheme($name, $hash) + { + $fileCode = $name . $hash; + $this->requestServerFile('theme/get', $fileCode, $hash, ['name' => $name]); + } + + /** + * Extracts a theme after it has been downloaded. + */ + public function extractTheme($name, $hash) + { + $fileCode = $name . $hash; + $filePath = $this->getFilePath($fileCode); + + if (!Zip::extract($filePath, $this->baseDirectory . '/themes/')) + throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath])); + + @unlink($filePath); + } + /** * Checks if a theme has ever been installed before. * @param string $name Theme code diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index 1d830a70b..8c85a8f3f 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -119,10 +119,18 @@ class Updates extends Controller $manager->downloadPlugin(post('name'), post('hash')); break; + case 'downloadTheme': + $manager->downloadTheme(post('name'), post('hash')); + break; + case 'extractPlugin': $manager->extractPlugin(post('name'), post('hash')); break; + case 'extractTheme': + $manager->extractTheme(post('name'), post('hash')); + break; + case 'completeUpdate': $manager->update(); Flash::success(Lang::get('system::lang.updates.update_success')); @@ -215,18 +223,20 @@ class Updates extends Controller public function onApplyUpdates() { try { - $plugins = post('plugins', []); - if (!is_array($plugins)) - $plugins = []; - $coreHash = post('hash'); $coreBuild = post('build'); $core = [$coreHash, $coreBuild]; + $plugins = post('plugins', []); + if (!is_array($plugins)) $plugins = []; + + $themes = post('themes', []); + if (!is_array($themes)) $themes = []; + /* * Update steps */ - $updateSteps = $this->buildUpdateSteps($core, $plugins); + $updateSteps = $this->buildUpdateSteps($core, $plugins, $themes); /* * Finish up @@ -245,13 +255,16 @@ class Updates extends Controller return $this->makePartial('execute'); } - private function buildUpdateSteps($core, $plugins) + private function buildUpdateSteps($core, $plugins, $themes) { + if (!is_array($core)) + $core = [null, null]; + if (!is_array($plugins)) $plugins = []; - if (!is_array($core)) - $core = [null, null]; + if (!is_array($themes)) + $themes = []; $updateSteps = []; list($coreHash, $coreBuild) = $core; @@ -276,6 +289,15 @@ class Updates extends Controller ]; } + foreach ($themes as $name => $hash) { + $updateSteps[] = [ + 'code' => 'downloadTheme', + 'label' => Lang::get('system::lang.updates.theme_downloading', compact('name')), + 'name' => $name, + 'hash' => $hash + ]; + } + /* * Extract */ @@ -297,6 +319,15 @@ class Updates extends Controller ]; } + foreach ($themes as $name => $hash) { + $updateSteps[] = [ + 'code' => 'extractTheme', + 'label' => Lang::get('system::lang.updates.theme_extracting', compact('name')), + 'name' => $name, + 'hash' => $hash + ]; + } + return $updateSteps; } diff --git a/modules/system/lang/en/lang.php b/modules/system/lang/en/lang.php index 0be1c384f..e337e01e7 100644 --- a/modules/system/lang/en/lang.php +++ b/modules/system/lang/en/lang.php @@ -137,14 +137,16 @@ return [ 'plugin_version_none' => 'New plugin', 'plugin_version_old' => 'Current v:version', 'plugin_version_new' => 'v:version', + 'theme_label' => 'Theme', + 'theme_new_install' => 'New theme installation.', + 'theme_downloading' => 'Downloading theme: :name', + 'theme_extracting' => 'Unpacking theme: :name', 'update_label' => 'Update software', 'update_completing' => 'Finishing update process', 'update_loading' => 'Loading available updates...', 'update_success' => 'The update process was performed successfully.', 'update_failed_label' => 'Update failed', 'force_label' => 'Force update', - 'theme_label' => 'Theme', - 'theme_new_install' => 'New theme installation.', 'found' => [ 'label' => 'Found new updates!', 'help' => 'Click Update software to begin the update process.',