123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- exit();
- if (PHP_SAPI !== 'cli') {
- die('This script can only be executed from the command line');
- }
- require __DIR__.'/../../main/inc/conf/configuration.php';
- $expiryDate = '2015-06-01';
- $fromDate = '2011-01-01';
- $sessionCourses = array();
- $coursesCodes = array();
- $coursesDirs = array();
- if (!$conexion = mysql_connect($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password'])) {
- echo 'Could not connect to database';
- exit;
- }
- if (!mysql_select_db($_configuration['main_database'], $conexion)) {
- echo 'Could not select database '.$_configuration['main_database'];
- exit;
- }
- echo "[".time()."] Querying sessions\n";
- $sql = "SELECT id FROM session where access_start_date < '$expiryDate' AND access_start_date > '$fromDate'";
- $res = mysql_query($sql, $conexion);
- if ($res === false) {
- }
- $countSessions = mysql_num_rows($res);
- $sql = "SELECT count(*) FROM session";
- $resc = mysql_query($sql, $conexion);
- if ($resc === false) {
- }
- $countAllSessions = mysql_result($resc, 0, 0);
- echo "[".time()."] Found $countSessions sessions between $fromDate and $expiryDate on a total of $countAllSessions sessions."."\n";
- while ($session = mysql_fetch_assoc($res)) {
- $sql2 = "SELECT c.id AS cid, c.code as ccode, c.directory as cdir
- FROM course c, session_rel_course s
- WHERE s.id_session = ".$session['id']."
- AND s.course_code = c.code";
- $res2 = mysql_query($sql2, $conexion);
- if ($res2 === false) {
- die("Error querying courses for session ".$session['id'].": ".mysql_error($res2)."\n");
- }
- if (mysql_num_rows($res2) > 0) {
- while ($course = mysql_fetch_assoc($res2)) {
- $sessionCourses[$session['id']] = $course['cid'];
-
- if (empty($coursesCodes[$course['cid']])) {
- $coursesCodes[$course['cid']] = $course['ccode'];
- }
- if (empty($coursesDirs[$course['cid']])) {
- $coursesDirs[$course['cid']] = $course['cdir'];
- }
- }
- }
- }
- echo "[".time()."] Filled courses arrays. Now checking tasks...\n";
- $totalSize = 0;
- foreach ($sessionCourses as $sid => $cid) {
-
-
-
-
- $sql = "SELECT id, url FROM c_student_publication
- WHERE filetype = 'folder'
- AND c_id = $cid
- AND session_id = $sid
- AND active = 1
- AND url LIKE '%ALP%'";
- $resCarpetas = mysql_query($sql, $conexion);
- if (mysql_num_rows($resCarpetas) > 0) {
- while ($rowDemo = mysql_fetch_assoc($resCarpetas)) {
- $carpetaAlpElimina = $_configuration['root_sys'].'courses/'.$coursesDirs[$cid].'/work'.$rowDemo['url'];
-
- $size = folderSize($carpetaAlpElimina);
- $totalSize += $size;
- echo "Freeing $size of a total $totalSize bytes in $carpetaAlpElimina\n";
- exec('rm -rf '.$carpetaAlpElimina);
- }
- $sqldel = "DELETE FROM c_student_publication
- WHERE
- c_id = $cid
- AND session_id = $sid AND active = 1;";
- $resdel = mysql_query($sqldel);
- if ($resdel === false) {
- echo "Error querying sessions";
- }
- }
- }
- echo "[".time()."] Deleted tasks from $countSessions sessions between $fromDate and $expiryDate on a total of $countAllSessions sessions."."\n";
- function folderSize($dir) {
- $size = 0;
- $contents = glob(rtrim($dir, '/').'/*', GLOB_NOSORT);
- foreach ($contents as $contents_value) {
- if (is_file($contents_value)) {
- $size += filesize($contents_value);
- } else {
- $size += folderSize($contents_value);
- }
- }
- return $size;
- }
|