-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
47 lines (37 loc) · 1.21 KB
/
Copy pathcli.php
File metadata and controls
47 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
require __DIR__ . '/bootstrap/app.php';
$app = bootstrap_app();
$command = $argv[1] ?? '';
if (!in_array($command, ['export-markdown', 'reset-password', 'migrate'], true)) {
echo "Usage:\n";
echo " php cli.php migrate\n";
echo " php cli.php export-markdown\n";
echo " php cli.php reset-password <email>\n";
exit(1);
}
if ($command === 'migrate') {
$app->db()->migrate();
echo "Database migration completed.\n";
exit(0);
}
if ($command === 'export-markdown') {
$service = new \Blogme\Services\MarkdownExportService($app->root(), $app->posts());
$result = $service->exportAll($app->config() ?? []);
echo "Exported {$result['count']} posts to {$result['directory']}\n";
exit(0);
}
$app->db()->migrate();
$email = $argv[2] ?? '';
if ($email === '') {
echo "Email is required.\n";
exit(1);
}
$user = $app->users()->byEmail($email);
if ($user === null) {
echo "User not found: {$email}\n";
exit(1);
}
$random = rtrim(strtr(base64_encode(random_bytes(12)), '+/', '-_'), '=');
$app->users()->updatePassword((string) $user['ID'], password_hash($random, PASSWORD_BCRYPT));
echo "Password for {$email} has been reset to: \"{$random}\"\n";