Add logic for downloading themes

This commit is contained in:
Sam Georges 2014-07-24 20:07:52 +10:00
parent 1d90ae25f7
commit ecf026d1df
3 changed files with 69 additions and 10 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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.',