kuvia/app/Console/Commands/ThemesScann.php

108 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2021-01-21 17:56:30 +00:00
<?php
namespace App\Console\Commands;
use App\Models\Theme;
use Illuminate\Console\Command;
class ThemesScann extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'theme:scan';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
2021-02-09 00:04:17 +00:00
$themesGallery = scandir(__DIR__."/../../../resources/views/themes/tenant");
2021-01-21 17:56:30 +00:00
foreach ($themesGallery as $theme) {
2021-02-09 00:04:17 +00:00
$this->info("Check Theme: ".$theme);
2021-01-21 17:56:30 +00:00
if(substr($theme, 0, 1) == ".") {
continue;
}
2021-02-09 00:04:17 +00:00
$settings = json_decode(file_get_contents(__DIR__."/../../../resources/views/themes/tenant/".$theme."/settings.json"));
$themeModel = Theme::query()->where("name", "=", $theme)->where("typ", "=", "tenant")->first();
2021-01-21 17:56:30 +00:00
if(!is_null($themeModel)) {
2021-02-09 00:04:17 +00:00
$this->info("Themes already exists: ".$theme);
2021-01-21 17:56:30 +00:00
continue;
}
2021-02-09 00:04:17 +00:00
2021-01-21 17:56:30 +00:00
$this->info("Found new Theme: ".$theme);
$themeModel = new Theme();
2021-02-09 00:04:17 +00:00
$themeModel->typ = "tenant";
2021-01-21 17:56:30 +00:00
$themeModel->name = $theme;
$themeModel->status = "private";
2021-02-09 00:04:17 +00:00
if($settings->public) {
$themeModel->status = "public";
}
$themeModel->img_pixel = $settings->usesSize->pixel;
$themeModel->img_small = $settings->usesSize->small;
$themeModel->img_medium = $settings->usesSize->medium;
$themeModel->img_big = $settings->usesSize->big;
2021-01-21 17:56:30 +00:00
$themeModel->saveOrFail();
}
2021-02-09 00:04:17 +00:00
$themesGallery = scandir(__DIR__."/../../../resources/views/themes/gallery");
2021-01-21 17:56:30 +00:00
foreach ($themesGallery as $theme) {
$this->info("Check Theme: ".$theme);
if(substr($theme, 0, 1) == ".") {
continue;
}
2021-02-09 00:04:17 +00:00
$settings = json_decode(file_get_contents(__DIR__."/../../../resources/views/themes/gallery/".$theme."/settings.json"));
$themeModel = Theme::query()->where("name", "=", $theme)->where("typ", "=", "gallery")->first();
2021-01-21 17:56:30 +00:00
if(!is_null($themeModel)) {
$this->info("Themes already exists: ".$theme);
continue;
}
2021-02-09 00:04:17 +00:00
2021-01-21 17:56:30 +00:00
$this->info("Found new Theme: ".$theme);
$themeModel = new Theme();
2021-02-09 00:04:17 +00:00
$themeModel->typ = "gallery";
2021-01-21 17:56:30 +00:00
$themeModel->name = $theme;
$themeModel->status = "private";
2021-02-09 00:04:17 +00:00
if($settings->public) {
$themeModel->status = "public";
}
$themeModel->img_pixel = $settings->usesSize->pixel;
$themeModel->img_small = $settings->usesSize->small;
$themeModel->img_medium = $settings->usesSize->medium;
$themeModel->img_big = $settings->usesSize->big;
2021-01-21 17:56:30 +00:00
$themeModel->saveOrFail();
}
}
}