added temporary file cleaner

This commit is contained in:
crispycat 2024-06-02 23:34:34 -04:00
parent e3601dbd84
commit 26d98853f8
6 changed files with 75 additions and 53 deletions

View File

@ -15,6 +15,8 @@
defined("ROOT") or die();
use \Crispage\Auth\CorePermissions;
use \Crispage\ApplicationConfig;
use \Crispage\Utils\FileUtils;
class SettingsAction extends \Crispage\Framework\Action {
public static function getExtensionInfo(): array {
@ -24,10 +26,6 @@
];
}
public function __construct(\Crispage $app, array $data) {
parent::__construct($app, $data);
}
public function run(): void {
$settings = $this->app->request->params["settings"] ?? [];
if (!is_array($settings)) $settings = [];
@ -98,28 +96,44 @@
break;
}
case "clean": {
$this->app->database->delete(
"sessions", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->database->delete(
"rme", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->database->delete(
"userconfirmation", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->page->data["messages"]["database_cleaned"] = [
"content" => $this->app->i18n->translate("{%DATABASE_CLEANED}"),
"color" => "success"
];
break;
}
case "ccache": {
$count = $this->app->cache->initializeCache();
$this->app->page->data["messages"]["cache_cleared"] = [
"content" => $this->app->i18n->translate("{%CLEARED_CACHE_ENTRIES}", $count),
"color" => "success"
];
break;
switch ($data) {
case "database": {
$this->app->database->delete(
"sessions", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->database->delete(
"rme", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->database->delete(
"userconfirmation", ["expire_time" => [time(), $this->app->database::OP_LESS]]
);
$this->app->page->data["messages"]["database_cleaned"] = [
"content" => $this->app->i18n->translate("{%DATABASE_CLEANED}"),
"color" => "success"
];
break;
}
case "cache": {
$count = $this->app->cache->initializeCache();
$this->app->page->data["messages"]["cache_cleared"] = [
"content" => $this->app->i18n->translate("{%CLEARED_CACHE_ENTRIES}", $count),
"color" => "success"
];
break;
}
case "temp": {
$temp_path = ROOT . ApplicationConfig::get("crispage.paths.temp");
$paths = ["$temp_path/pkguploads"];
$count = 0;
foreach ($paths as $path)
$count += FileUtils::emptyDirectory($path);
$this->app->page->data["messages"]["tempfiles_deleted"] = [
"content" => $this->app->i18n->translate("{%DELETED_TEMP_FILES}", $count),
"color" => "success"
];
}
}
}
}
}

View File

@ -57,7 +57,7 @@
$com_lc = $this->app->page->createComponent(
"\\Crispage\\Components\\ListControlsComponent", [
"sortby_options" => array_combine(
array_keys($this->data["columns"]),
array_map(fn(AssetListColumn $x) => $x->name, $this->data["columns"]),
array_map(fn(AssetListColumn $x) => $x->label, $this->data["columns"])
)
]

View File

@ -69,11 +69,11 @@
<tr>
<td>
<code><?php echo $ext->id; ?></code><br />
<?php echo $extinfo["name"] ?? ""; ?>
<?php ($this->app->i18n)($extinfo["name"] ?? ""); ?>
</td>
<td><?php echo $extinfo["version"] ?? ""; ?></td>
<td><?php echo $extinfo["author"] ?? ""; ?></td>
<td><?php echo $extinfo["description"] ?? ""; ?></td>
<td><?php ($this->app->i18n)($extinfo["version"] ?? ""); ?></td>
<td><?php ($this->app->i18n)($extinfo["author"] ?? ""); ?></td>
<td><?php ($this->app->i18n)($extinfo["description"] ?? ""); ?></td>
<td>
<?php
$com = $this->app->page->createComponent(

View File

@ -130,7 +130,6 @@
<hr />
<form method="post">
<input type="hidden" name="route" value="settings" />
<input type="hidden" name="tools[clean]" value="clean" />
<?php
$com_clean = $this->app->page->createComponent(
"\\Crispage\\Components\\ButtonsComponent", [
@ -138,7 +137,29 @@
[
"type" => "submit",
"label" => "{%CLEAN_DATABASE}",
"color" => "primary"
"color" => "primary",
"attrs" => [
"name" => "tools[clean]",
"value" => "database"
]
],
[
"type" => "submit",
"label" => "{%CLEAR_CACHE}",
"color" => "primary",
"attrs" => [
"name" => "tools[clean]",
"value" => "cache"
]
],
[
"type" => "submit",
"label" => "{%CLEAN_TEMPORARY_FILES}",
"color" => "primary",
"attrs" => [
"name" => "tools[clean]",
"value" => "temp"
]
]
]
]
@ -147,26 +168,6 @@
$this->app->page->renderComponent($com_clean);
?>
</form>
<br />
<form method="post">
<input type="hidden" name="route" value="settings" />
<input type="hidden" name="tools[ccache]" value="ccache" />
<?php
$com_ccache = $this->app->page->createComponent(
"\\Crispage\\Components\\ButtonsComponent", [
"buttons" => [
[
"type" => "submit",
"label" => "{%CLEAR_CACHE}",
"color" => "primary"
]
]
]
);
$this->app->page->renderComponent($com_ccache);
?>
</form>
</div>
</div>
</div>

View File

@ -54,6 +54,7 @@ CHANGES_SAVED = Changes saved.
CHECK_FOR_UPDATES = Check for updates
CLEAN_DATABASE = Clean Database
CLEAR_CACHE = Clear Cache
CLEAN_TEMPORARY_FILES = Clean temporary files
COMMENT = Comment
COMMENT_BODY_EMPTY = Comment body empty.
COMMENT_POSTED = Comment posted.
@ -71,6 +72,7 @@ CREATE_USER = Create User
CREATED = Created
CRISPAGE_DASHBOARD = Crispage Dashboard
CRISPAGE_VERSION = Crispage version
EDIT_BACKEND_MENU = Edit Backend Menu
DASHBOARD = Dashboard
DATABASE = Database
DATABASE_CLEANED = Database cleaned.
@ -84,6 +86,8 @@ DEFAULT_ROLES = "Default role(s)"
DEFAULT_TEMPLATE = Default template
DELETE = Delete
DELETE_OCCUPIED_DIRECTORIES=Delete occupied directories
DELETED_TEMP_FILES = Deleted %d temporary files
DESCRIPTION = Description
DISABLED = Disabled
DISPLAY_NAME = Display Name
DOCS = Docs
@ -245,6 +249,7 @@ ROLES = Roles
SAVE_CHANGES = Save Changes
SEARCH = Search
SEARCH_SITE_CONTENT = Search site content...
SELECT = Select
SELECT_FILES = Select files
SEND_AS_HTML = Send as HTML
SEND_CONFIRMATION_EMAIL = Send Confirmation Email
@ -264,6 +269,7 @@ SITE_ROBOTS = Site meta robots
SITE_ROOT = Site root
SITE_STATS = Site stats
SIZE = Size
SHOW_COMMENT_FORM = Show Comment Form
SHOW_COMMENTS = Show Comments
SHOW_INFO = Show Info
SHOW_LOGIN__LINK = Show login/logout link
@ -321,6 +327,7 @@ USERNAME = Username
USERNAME_CANNOT_BE_CHANGED=Username cannot be changed after registration.
USERNAME_TAKEN = Username taken.
USERS = Users
VERSION = Version
VIEW_UNPUBLISHED = View Unpublished
WELCOME_X = Welcome, %s
X_FILES_UPLOADED = %d files uploaded.

View File