parent
b276ac7f6a
commit
186d770741
3 changed files with 80 additions and 26 deletions
|
|
@ -1,28 +1,80 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* ZapMachine Reset Script
|
||||||
|
*
|
||||||
|
* CLI only. Resets the current session and optionally purges all session
|
||||||
|
* folders. Confirmation is required before any destructive action.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* php cli_scripts/reset.php Reset current session only
|
||||||
|
* php cli_scripts/reset.php --all Purge all session folders (with prompt)
|
||||||
|
* php cli_scripts/reset.php --all -f Purge all session folders, no prompt
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (php_sapi_name() !== 'cli') {
|
||||||
|
die('This script can only be run from the command line.' . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure relative paths in init.php resolve against the project root
|
||||||
|
chdir(__DIR__);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../conf/init.php';
|
||||||
|
|
||||||
|
// Start a session so reset/destroy have something to work with
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
unset($_SESSION['imgOriginal']);
|
|
||||||
unset($_SESSION['words']);
|
|
||||||
unset($_SESSION['folder']);
|
|
||||||
unset($_SESSION['collages']);
|
|
||||||
unset($_SESSION['width']);
|
|
||||||
unset($_SESSION['height']);
|
|
||||||
|
|
||||||
echo '<p>session reset</p><p>';
|
|
||||||
|
|
||||||
if ($_GET['allcollages'] == 'clear') {
|
|
||||||
$sessions = glob('./Sessions/*');
|
|
||||||
foreach($sessions as $folder){
|
|
||||||
$files = glob($folder.'/*');
|
|
||||||
foreach($files as $fileToDelete){
|
|
||||||
echo "$fileToDelete deleted<br />";
|
|
||||||
unlink($fileToDelete);
|
|
||||||
}
|
}
|
||||||
echo "$folder deleted<br />";
|
|
||||||
|
// --- Session reset ---
|
||||||
|
Session::reset();
|
||||||
|
|
||||||
|
echo 'Session reset.' . PHP_EOL;
|
||||||
|
|
||||||
|
// --- Optional: purge all session folders ---
|
||||||
|
$purgeAll = in_array('--all', $argv);
|
||||||
|
|
||||||
|
if ($purgeAll) {
|
||||||
|
$force = in_array('-f', $argv);
|
||||||
|
|
||||||
|
if (!$force) {
|
||||||
|
echo 'WARNING: This will permanently delete ALL session folders.' . PHP_EOL;
|
||||||
|
echo 'Are you sure? (type "yes" to confirm): ';
|
||||||
|
$handle = fopen('php://stdin', 'r');
|
||||||
|
$input = trim(fgets($handle));
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
if (strtolower($input) !== 'yes') {
|
||||||
|
echo 'Aborted.' . PHP_EOL;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sessionsDir = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR . ZAP_SESSIONS_DIR;
|
||||||
|
$folders = glob($sessionsDir . DIRECTORY_SEPARATOR . '*');
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
|
foreach ($folders as $folder) {
|
||||||
|
if (!is_dir($folder)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$files = glob($folder . DIRECTORY_SEPARATOR . '*');
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (is_file($file)) {
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
rmdir($folder);
|
rmdir($folder);
|
||||||
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
echo '</p>';
|
|
||||||
|
|
||||||
session_destroy();
|
echo "Purged $count session folder(s)." . PHP_EOL;
|
||||||
?>
|
}
|
||||||
|
|
||||||
|
// Only destroy if a session was actually started
|
||||||
|
if (session_status() === PHP_SESSION_ACTIVE) {
|
||||||
|
Session::destroy();
|
||||||
|
echo 'Session destroyed.' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
@ -85,9 +85,10 @@ function testImgSearch() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$folder = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR . ZAP_SESSIONS_DIR . DIRECTORY_SEPARATOR . 'search_test_' . ZAP_MOMENT;
|
$suffix = bin2hex(random_bytes(4));
|
||||||
|
$folder = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR . ZAP_SESSIONS_DIR . DIRECTORY_SEPARATOR . 'search_test_' . ZAP_MOMENT . '_' . $suffix;
|
||||||
if (!is_dir($folder)) {
|
if (!is_dir($folder)) {
|
||||||
@mkdir($folder, 0777, true);
|
mkdir($folder, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "\nQuery: '$word'\n\n";
|
echo "\nQuery: '$word'\n\n";
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,10 @@ class ZAPDisplay implements ZAPHandler {
|
||||||
*/
|
*/
|
||||||
private function createFolder() {
|
private function createFolder() {
|
||||||
try {
|
try {
|
||||||
|
$suffix = bin2hex(random_bytes(4));
|
||||||
$folder = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR
|
$folder = ZAP_APP_BASE_DIR . DIRECTORY_SEPARATOR
|
||||||
. ZAP_SESSIONS_DIR . DIRECTORY_SEPARATOR . 'zap_' . ZAP_MOMENT;
|
. ZAP_SESSIONS_DIR . DIRECTORY_SEPARATOR . 'zap_' . ZAP_MOMENT . '_' . $suffix;
|
||||||
if (!@mkdir($folder, 0777)) {
|
if (!mkdir($folder, 0777, true)) {
|
||||||
throw new Exception('<p>' . ERROR_PREFIX . 'Unable to create base dir: ' . $folder . '</p>');
|
throw new Exception('<p>' . ERROR_PREFIX . 'Unable to create base dir: ' . $folder . '</p>');
|
||||||
}
|
}
|
||||||
return $folder;
|
return $folder;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue