Skip to content

Commit bef4542

Browse files
authored
Merge pull request #45 from BlueprintFramework/console-api
Add Artisan and Schedule support through the new Blueprint Console API.
2 parents a0a04f0 + 5417a1e commit bef4542

File tree

11 files changed

+364
-27
lines changed

11 files changed

+364
-27
lines changed

app/BlueprintFramework/Console/KernelExtensions.php

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Pterodactyl\BlueprintFramework;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use File;
7+
8+
class GetExtensionSchedules {
9+
public static function schedules(Schedule $schedule) {
10+
foreach (File::allFiles(app_path('BlueprintFramework/Schedules/')) as $file) {
11+
if ($file->getExtension() == 'php') {
12+
require $file->getPathname();
13+
}
14+
}
15+
}
16+
};

app/BlueprintFramework/Libraries/ExtensionLibrary/Admin/BlueprintAdminLibrary.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public function fileRead($path) {
119119
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
120120
*/
121121
public function fileMake($path) {
122-
return shell_exec("touch ".escapeshellarg($path).";");
122+
$file = fopen($path, "w");
123+
fclose($file);
123124
}
124125

125126
/**

app/BlueprintFramework/Libraries/ExtensionLibrary/Client/BlueprintClientLibrary.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public function fileRead($path) {
7676
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
7777
*/
7878
public function fileMake($path) {
79-
return shell_exec("touch ".escapeshellarg($path).";");
79+
$file = fopen($path, "w");
80+
fclose($file);
8081
}
8182

8283
/**
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
// Core file for the console library for Blueprint Extensions
4+
5+
6+
namespace Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Console;
7+
8+
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
9+
10+
class BlueprintConsoleLibrary
11+
{
12+
// Construct core
13+
public function __construct(
14+
private SettingsRepositoryInterface $settings,
15+
) {
16+
}
17+
18+
/**
19+
* Fetch a record from the database.
20+
*
21+
* @param string $table Database table
22+
* @param string $record Database record
23+
* @return mixed Database value
24+
*
25+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
26+
*/
27+
public function dbGet($table, $record): mixed {
28+
return $this->settings->get($table."::".$record);
29+
}
30+
31+
/**
32+
* Set a database record.
33+
*
34+
* @param string $table Database table
35+
* @param string $record Database record
36+
* @param string $value Value to store
37+
*
38+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
39+
*/
40+
public function dbSet($table, $record, $value) {
41+
return $this->settings->set($table."::".$record, $value);
42+
}
43+
44+
/**
45+
* Delete/forget a database record.
46+
*
47+
* @param string $table Database table
48+
* @param string $record Database record
49+
*
50+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
51+
*/
52+
public function dbForget($table, $record) {
53+
return $this->settings->forget($table."::".$record);
54+
}
55+
56+
/**
57+
* Read and returns the content of a given file.
58+
*
59+
* @param string $path Path to file
60+
* @return string File contents
61+
* @throws string Errors encountered by `cat` shell utility
62+
*
63+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
64+
*/
65+
public function fileRead($path) {
66+
return shell_exec("cat ".escapeshellarg($path).";");
67+
}
68+
69+
/**
70+
* Attempts to (non-recursively) create a file.
71+
*
72+
* @param string $path File name/path
73+
* @return string Empty string unless error
74+
* @throws string Errors encountered by `touch` shell utility
75+
*
76+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
77+
*/
78+
public function fileMake($path) {
79+
$file = fopen($path, "w");
80+
fclose($file);
81+
}
82+
83+
/**
84+
* Attempts to (recursively) remove a file/folder.
85+
* It's good practice to terminate this function after a certain timeout, to prevent infinite page loads upon input. Blueprint attempts to use `yes` as an input for all questions, but might not succeed.
86+
*
87+
* @param string $path Path to file/folder
88+
* @return string Empty string unless error
89+
* @throws string Errors encountered by `rm` shell utility
90+
*
91+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
92+
*/
93+
public function fileWipe($path) {
94+
return shell_exec("yes | rm -r ".escapeshellarg($path).";");
95+
}
96+
97+
/**
98+
* Check if an extension is installed based on it's identifier.
99+
*
100+
* @param string $identifier Extension identifier
101+
* @return bool Boolean
102+
*
103+
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
104+
*/
105+
public function extension($identifier): bool {
106+
if(str_contains($this->fileRead(base_path(".blueprint/extensions/blueprint/private/db/installed_extensions")), $identifier.',')) {
107+
return true;
108+
} else {
109+
return false;
110+
}
111+
}
112+
}

app/BlueprintFramework/Schedules/.gitkeep

Whitespace-only changes.

app/Console/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Database\Console\PruneCommand;
99
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
1010
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
11-
use Pterodactyl\BlueprintFramework\Console\KernelExtensions;
11+
use Pterodactyl\BlueprintFramework\GetExtensionSchedules;
1212
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
1313
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
1414
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
@@ -49,7 +49,7 @@ protected function schedule(Schedule $schedule): void
4949
$this->registerTelemetry($schedule);
5050
}
5151

52-
KernelExtensions::schedules($schedule);
52+
GetExtensionSchedules::schedules($schedule);
5353
}
5454

5555
/**

0 commit comments

Comments
 (0)