Skip to content

Commit

Permalink
Merge pull request #45 from BlueprintFramework/console-api
Browse files Browse the repository at this point in the history
Add Artisan and Schedule support through the new Blueprint Console API.
  • Loading branch information
prplwtf authored Jun 22, 2024
2 parents a0a04f0 + 5417a1e commit bef4542
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 27 deletions.
11 changes: 0 additions & 11 deletions app/BlueprintFramework/Console/KernelExtensions.php

This file was deleted.

16 changes: 16 additions & 0 deletions app/BlueprintFramework/GetExtensionSchedules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Pterodactyl\BlueprintFramework;

use Illuminate\Console\Scheduling\Schedule;
use File;

class GetExtensionSchedules {
public static function schedules(Schedule $schedule) {
foreach (File::allFiles(app_path('BlueprintFramework/Schedules/')) as $file) {
if ($file->getExtension() == 'php') {
require $file->getPathname();
}
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public function fileRead($path) {
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileMake($path) {
return shell_exec("touch ".escapeshellarg($path).";");
$file = fopen($path, "w");
fclose($file);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function fileRead($path) {
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileMake($path) {
return shell_exec("touch ".escapeshellarg($path).";");
$file = fopen($path, "w");
fclose($file);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

// Core file for the console library for Blueprint Extensions


namespace Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Console;

use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;

class BlueprintConsoleLibrary
{
// Construct core
public function __construct(
private SettingsRepositoryInterface $settings,
) {
}

/**
* Fetch a record from the database.
*
* @param string $table Database table
* @param string $record Database record
* @return mixed Database value
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function dbGet($table, $record): mixed {
return $this->settings->get($table."::".$record);
}

/**
* Set a database record.
*
* @param string $table Database table
* @param string $record Database record
* @param string $value Value to store
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function dbSet($table, $record, $value) {
return $this->settings->set($table."::".$record, $value);
}

/**
* Delete/forget a database record.
*
* @param string $table Database table
* @param string $record Database record
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function dbForget($table, $record) {
return $this->settings->forget($table."::".$record);
}

/**
* Read and returns the content of a given file.
*
* @param string $path Path to file
* @return string File contents
* @throws string Errors encountered by `cat` shell utility
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileRead($path) {
return shell_exec("cat ".escapeshellarg($path).";");
}

/**
* Attempts to (non-recursively) create a file.
*
* @param string $path File name/path
* @return string Empty string unless error
* @throws string Errors encountered by `touch` shell utility
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileMake($path) {
$file = fopen($path, "w");
fclose($file);
}

/**
* Attempts to (recursively) remove a file/folder.
* 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.
*
* @param string $path Path to file/folder
* @return string Empty string unless error
* @throws string Errors encountered by `rm` shell utility
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileWipe($path) {
return shell_exec("yes | rm -r ".escapeshellarg($path).";");
}

/**
* Check if an extension is installed based on it's identifier.
*
* @param string $identifier Extension identifier
* @return bool Boolean
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function extension($identifier): bool {
if(str_contains($this->fileRead(base_path(".blueprint/extensions/blueprint/private/db/installed_extensions")), $identifier.',')) {
return true;
} else {
return false;
}
}
}
Empty file.
4 changes: 2 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Database\Console\PruneCommand;
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Pterodactyl\BlueprintFramework\Console\KernelExtensions;
use Pterodactyl\BlueprintFramework\GetExtensionSchedules;
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected function schedule(Schedule $schedule): void
$this->registerTelemetry($schedule);
}

KernelExtensions::schedules($schedule);
GetExtensionSchedules::schedules($schedule);
}

/**
Expand Down
Loading

0 comments on commit bef4542

Please sign in to comment.