|
1 | 1 | <?php
|
2 | 2 | namespace Groupeat\Admin\Console;
|
3 | 3 |
|
4 |
| -use Groupeat\Admin\Services\GenerateAdminerFiles; |
5 | 4 | use Groupeat\Support\Console\Abstracts\Command;
|
| 5 | +use GuzzleHttp\Client; |
| 6 | +use Illuminate\Contracts\Filesystem\Filesystem; |
6 | 7 |
|
7 | 8 | class Adminer extends Command
|
8 | 9 | {
|
9 |
| - protected $name = 'adminer'; |
| 10 | + const THEME = 'pappu687'; |
| 11 | + const RED = '#ff4e50'; |
| 12 | + const GREEN = '#23AF50'; |
| 13 | + |
| 14 | + protected $signature = 'adminer'; |
10 | 15 | protected $description = "Generate the Adminer files to manage the DB";
|
11 | 16 |
|
12 |
| - private $generateAdminerFiles; |
| 17 | + private $client; |
| 18 | + private $filesystem; |
13 | 19 |
|
14 |
| - public function __construct(GenerateAdminerFiles $generateAdminerFiles) |
| 20 | + public function __construct(Filesystem $filesystem) |
15 | 21 | {
|
16 | 22 | parent::__construct();
|
17 | 23 |
|
18 |
| - $this->generateAdminerFiles = $generateAdminerFiles; |
| 24 | + $this->client = new Client; |
| 25 | + $this->filesystem = $filesystem; |
19 | 26 | }
|
20 | 27 |
|
21 |
| - public function fire() |
| 28 | + public function handle() |
22 | 29 | {
|
23 |
| - $this->generateAdminerFiles->call($this->getOutput()); |
| 30 | + $this->line("Listing available versions"); |
| 31 | + |
| 32 | + $response = $this->client->get('https://api.github.com/repos/vrana/adminer/tags'); |
| 33 | + |
| 34 | + $latestVersion = collect(json_decode($response->getBody(), true)) |
| 35 | + ->map(function ($tag) { |
| 36 | + return trim($tag['name'], 'v'); |
| 37 | + }) |
| 38 | + ->sortByDesc(null) |
| 39 | + ->first(); |
| 40 | + |
| 41 | + $this->line("Latest version found: $latestVersion"); |
| 42 | + $this->line("Downloading PHP file"); |
| 43 | + |
| 44 | + $this->client->get("http://downloads.sourceforge.net/adminer/adminer-$latestVersion-en.php", [ |
| 45 | + 'save_to' => storage_path('app/adminer.php'), |
| 46 | + ]); |
| 47 | + |
| 48 | + $this->line("Downloading CSS file"); |
| 49 | + |
| 50 | + $css = (string) $this->client |
| 51 | + ->get('https://raw.github.com/vrana/adminer/master/designs/' . static::THEME . '/adminer.css') |
| 52 | + ->getBody(); |
| 53 | + |
| 54 | + $this->line("Applying GroupEat theme"); |
| 55 | + |
| 56 | + $css = str_replace('#34495e', static::RED, $css); |
| 57 | + $css = str_replace(['#48A5BF', '#65ADC3', 'rgb(85, 112, 139)', '#2980b9'], static::GREEN, $css); |
| 58 | + |
| 59 | + $this->line("Saving CSS file"); |
| 60 | + |
| 61 | + $this->filesystem->put('adminer.css', $css); |
24 | 62 | }
|
25 | 63 | }
|
0 commit comments