FIX: fix theme:set command.

This command did not set theme properly, when THEME was in .env file, but with no value (THEME= only - as default in .env.example).
This commit is contained in:
Michal Kváček
2016-04-04 20:20:33 +02:00
parent 85dcf29c41
commit f27ad7c421
3 changed files with 44 additions and 29 deletions
+20 -5
View File
@@ -40,16 +40,31 @@ class SetTheme extends Command
throw new NotFoundHttpException('Invalid theme ' . $theme . '!');
}
$env = file_get_contents(base_path('.env'));
// load .env file
$envFile = base_path('.env');
$env = file_get_contents($envFile);
$env = preg_replace('/THEME=(.+)/i', 'THEME=' . $theme, $env);
if (!Str::contains($env, 'THEME')) {
if (!Str::contains($env, 'THEME=')) {
$env = sprintf("%s\nTHEME=%s\n", $env, $theme);
} else {
$env = preg_replace('/THEME=(.*)/i', 'THEME=' . $theme, $env, -1, $cnt);
}
file_put_contents(base_path('.env'), $env);
// try to write content
$bytesWritten = file_put_contents($envFile, $env);
// check if write was successfull
if (!$bytesWritten) {
throw new \Exception('Cannot write to ' . base_path('.env') . '. Add THEME=' . $theme . ' to your .env file manualy.');
}
// theme written
$this->line('Theme successfully setup.');
$this->line('');
$this->line(' ** PUBLISHING ASSETS AND VIEWS **');
// publish assets and views for module and theme
$this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]);
$this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]);
$this->call('vendor:publish');
}
}
+20 -20
View File
@@ -13,12 +13,12 @@ use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter;
use App\Handlers\Search\Presenters\AdminFiles;
use App\Models\Template;
use App\Widgets\HtmlCode\HtmlCode;
use App\Widgets\Menu\Extensions\URL;
use App\Widgets\Menu\Menu;
use App\Widgets\OrbitSlider\OrbitSlider;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Process\Exception\InvalidArgumentException;
class AppServiceProvider extends ServiceProvider
{
@@ -39,6 +39,13 @@ class AppServiceProvider extends ServiceProvider
$this->registerTemplates();
$this->registerSettings();
$this->registerSearch();
// check if given template is valid
$theme = config('app.theme');
$themeDir = resource_path('views/visitor/' . $theme);
if (!$theme || empty($theme) || !is_dir($themeDir)) {
throw new InvalidArgumentException('No or invalid theme set! Use artisan theme:set or edit .env file manually and include THEME option, please');
}
}
/**
@@ -95,8 +102,8 @@ class AppServiceProvider extends ServiceProvider
$registrator->register(OrbitSlider::class);
// register some menu extensions
// $menuExtensions = $this->app->make('registerMenuExtension');
// $menuExtensions->register(new URL());
// $menuExtensions = $this->app->make('registerMenuExtension');
// $menuExtensions->register(new URL());
}
/**
@@ -140,35 +147,28 @@ class AppServiceProvider extends ServiceProvider
*/
private function publishViewResources()
{
$themes = File::directories(resource_path('views/visitor'));
$theme = config('app.theme');
$themeDir = resource_path('views/visitor/' . $theme);
$assets = [];
foreach ($themes as $theme) {
$themeName = basename($theme);
if (is_dir($theme . '/'.Template::ASSETS_DIRECTORY)) {
$assets[$theme . '/'.Template::ASSETS_DIRECTORY] = public_path('assets/' . $themeName);
// publish assets if exists for current theme
if (is_dir($themeDir . '/' . Template::ASSETS_DIRECTORY)) {
$this->publishes([$themeDir . '/' . Template::ASSETS_DIRECTORY => public_path('assets/' . $theme)], 'public-assets');
}
if (is_dir($theme . '/'.Template::MODULES_DIRECTORY)) {
$this->publishModuleViews($theme . '/'.Template::MODULES_DIRECTORY, $themeName);
if (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) {
// $this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY);
}
}
if (!empty($assets)) {
$this->publishes($assets, 'public-assets');
}
}
private function publishModuleViews($themeModules, $themeName)
private function publishModuleViews($themeModules)
{
$theme = config('app.theme');
$modules = File::directories($themeModules);
$moduleViews = [];
foreach ($modules as $module) {
$moduleName = strtolower(basename($module));
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $themeName);
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $theme);
}
if (!empty($moduleViews)) {
+4 -4
View File
@@ -37,7 +37,7 @@ return [
|
*/
'url' => 'http://localhost',
'url' => env('SITE_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
| Application Timezone
@@ -49,7 +49,7 @@ return [
|
*/
'timezone' => 'UTC',
'timezone' => env('TIMEZONE', 'UTC'),
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
@@ -61,7 +61,7 @@ return [
|
*/
'locale' => 'en',
'locale' => env('LOCALES', 'en'),
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
@@ -97,7 +97,7 @@ return [
*/
'upload_url' => env('UPLOAD_URL', PHP_SAPI === 'cli' ? '' : url('uploads')),
'thumbnail_url' => env('THUMBNAIL_URL', PHP_SAPI === 'cli' ? '' : url('uploads/thumbnails')),
'theme' => env('THEME', 'default_theme'),
'theme' => env('THEME'),
/*
|--------------------------------------------------------------------------
| Logging Configuration