/
pruneSchedules.php
39 lines (32 loc) · 1.37 KB
/
pruneSchedules.php
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
<?php
////////////////////////////////////////////////////////////////////////////
// SAVED SCHEDULE PRUNER
//
// @author Ben Russell (benrr101@csh.rit.edu)
//
// @file tools/pruneSchedules.php
// @descrip A stand alone tool (that should be cronjobbed) to prune saved
// schedules that are older than 90 days.
////////////////////////////////////////////////////////////////////////////
// Make sure the working directory is correct
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
// Bring in the database connection
require "../inc/databaseConn.php";
global $dbConn;
// Build a where clause that will be resued
$where = "WHERE (NOW() - datelastaccessed > (60 * 60 * 24 * 90))";
// Run the query to delete the courses of the schedule that are older than
// 90 days
$query = "DELETE FROM schedulecourses WHERE schedule = (SELECT id FROM schedules {$where})";
$result = mysql_query($query);
if(!$result) { echo(mysql_error() . "\n"); }
// Run the query to delete the non-course items of the schedule that are older
// than 90 days
$query = "DELETE FROM schedulenoncourses WHERE schedule = (SELECT id FROM schedules {$where})";
$result = mysql_query($query);
if(!$result) { echo(mysql_error() . "\n"); }
// Run the query to delete the schedules that are older than 90 days
$query = "DELETE FROM schedules {$where}";
$result = mysql_query($query);
if(!$result) { echo(mysql_error() . "\n"); }
?>