| Server IP : 158.247.231.215 / Your IP : 216.73.216.33 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/api/custom-api/ |
Upload File : |
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
// Load WordPress and auth helper
require_once('/mnt/blockstorage/ctms/wp-load.php');
require_once('auth-helper.php');
include('../database.php');
// Verify JWT token
$user_id = verify_jwt_token();
if (!$user_id) {
send_error_response('User not authenticated', 401);
}
// Main processing
if ($_SERVER['REQUEST_METHOD'] === 'POST' || $_SERVER['REQUEST_METHOD'] === 'DELETE') {
try {
// Get version_id
$version_id = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$version_id = isset($_POST['id']) ? intval($_POST['id']) : 0;
} else {
$delete_data = json_decode(file_get_contents('php://input'), true);
$version_id = isset($delete_data['id']) ? intval($delete_data['id']) : 0;
}
if ($version_id <= 0) {
throw new Exception('Valid version ID is required');
}
// Get version info
$sql = "SELECT v.*, c.id as content_id FROM vr_content_versions v
INNER JOIN vr_contents c ON v.content_id = c.id
WHERE v.id = $version_id";
$result = $conn->query($sql);
if (!$result || $result->num_rows === 0) {
throw new Exception('Version not found');
}
$version = $result->fetch_assoc();
// Delete APK files
if ($version['pico_apk_path']) {
$file_path = '/mnt/blockstorage/ctms/vr-content-uploads/' . $version['pico_apk_path'];
if (file_exists($file_path)) {
unlink($file_path);
}
}
if ($version['quest_apk_path']) {
$file_path = '/mnt/blockstorage/ctms/vr-content-uploads/' . $version['quest_apk_path'];
if (file_exists($file_path)) {
unlink($file_path);
}
}
// Delete version directory if empty
$version_dir = '/mnt/blockstorage/ctms/vr-content-uploads/contents/' . $version['content_id'] . '/versions/' . $version['version_number'];
if (file_exists($version_dir) && count(scandir($version_dir)) == 2) { // Only . and ..
rmdir($version_dir);
}
// Delete version from database
$delete_sql = "DELETE FROM vr_content_versions WHERE id = $version_id";
if ($conn->query($delete_sql) !== TRUE) {
throw new Exception('Failed to delete version: ' . $conn->error);
}
$response = array(
'status' => 'success',
'message' => 'Version deleted successfully',
'data' => array(
'version_id' => $version_id,
'version_number' => $version['version_number'],
'content_id' => intval($version['content_id'])
)
);
header('Content-Type: application/json');
echo json_encode($response);
} catch (Exception $e) {
$response = array(
'status' => 'error',
'message' => $e->getMessage()
);
header('Content-Type: application/json');
http_response_code(400);
echo json_encode($response);
}
$conn->close();
} else {
$response = array(
'status' => 'error',
'message' => 'Only POST or DELETE requests are allowed'
);
header('Content-Type: application/json');
http_response_code(405);
echo json_encode($response);
}
?>