ch1p_io_web/cli_util.php
2024-01-31 20:45:40 +03:00

84 lines
1.8 KiB
PHP
Executable File

#!/usr/bin/env php8.1
<?php
namespace cli_util;
use cli;
use pages;
use posts;
use tags;
use uploads;
require_once __DIR__.'/init.php';
require_once 'lib/stored_config.php';
$cli = new cli(__NAMESPACE__);
$cli->run();
function admin_reset(): void {
$pwd1 = cli::silentInput("New password: ");
$pwd2 = cli::silentInput("Again: ");
if ($pwd1 != $pwd2)
cli::die("Passwords do not match");
if (trim($pwd1) == '')
cli::die("Password can not be empty");
if (!scSet('admin_pwd', salt_password($pwd1)))
cli::die("Database error");
}
function admin_check(): void {
$pwd = scGet('admin_pwd');
echo is_null($pwd) ? "Not set" : $pwd;
echo "\n";
}
function blog_erase(): void {
$db = DB();
$tables = ['posts', 'posts_tags', 'tags'];
foreach ($tables as $t) {
$db->query("TRUNCATE TABLE $t");
}
}
function tags_recount(): void {
$tags = tags::getAll(true);
foreach ($tags as $tag)
posts::tagsRecountPosts($tag->id);
}
function posts_html(): void {
$kw = ['include_hidden' => true];
$posts = posts::getList(0, posts::getCount(...$kw), ...$kw);
foreach ($posts as $p) {
$p->updateHtml();
$p->updateText();
}
}
function posts_images(): void {
$kw = ['include_hidden' => true];
$posts = posts::getList(0, posts::getCount(...$kw), ...$kw);
foreach ($posts as $p) {
$p->updateImagePreviews(true);
}
}
function pages_html(): void {
$pages = pages::getAll();
foreach ($pages as $p) {
$p->updateHtml();
}
}
function add_files_to_uploads(): void {
$path = cli::input('Enter path: ');
if (!file_exists($path))
cli::die("file $path doesn't exists");
$name = basename($path);
$id = uploads::add($path, $name, '');
echo "upload id: $id\n";
}