-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcsdb_compo_clear_cache.php
More file actions
47 lines (37 loc) · 1.69 KB
/
csdb_compo_clear_cache.php
File metadata and controls
47 lines (37 loc) · 1.69 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
/**
* DeepSID
*
* Clear the cache of a competition folder. This will make the folder ready to
* be refreshed from the original CSDb release pages.
*
* @uses $_POST['competition']
*
* @used-by main.js
*/
require_once("class.account.php"); // Includes setup
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest')
die("Direct access not permitted.");
$user_id = $account->CheckLogin() ? $account->UserID() : 0;
if (!$user_id)
die(json_encode(array('status' => 'error', 'message' => 'You must be logged in to clear the cache of a competition folder.')));
if (!isset($_POST['competition']))
die(json_encode(array('status' => 'error', 'message' => 'You must specify the proper GET variable.')));
try {
$db = $account->GetDB();
// Get event ID
$select = $db->prepare('SELECT event_id FROM competitions WHERE competition = :compo LIMIT 1');
$select->execute(array(':compo'=>$_POST['competition']));
$select->setFetchMode(PDO::FETCH_OBJ);
$event_id = $select->rowCount() ? $select->fetch()->event_id : 0;
if (!$event_id)
die(json_encode(array('status' => 'error', 'message' => 'Event ID not found for the "'.$_POST['competition'].'" competition folder')));
// Now delete all entries with this event ID in the cache table
$delete = $db->query('DELETE FROM competitions_cache WHERE event_id = '.$event_id);
$account->LogActivity('User "'.$_SESSION['user_name'].'" cleared the cache for the "'.$_POST['competition'].'" competition folder');
} catch(PDOException $e) {
$account->LogActivityError(basename(__FILE__), $e->getMessage());
die(json_encode(array('status' => 'error', 'message' => DB_ERROR)));
}
echo json_encode(array('status' => 'ok'));
?>