diff --git a/admin.php b/admin.php --- a/admin.php +++ b/admin.php @@ -18,7 +18,9 @@ * along with SlatePermutate. If not, see . */ - include_once 'inc/class.page.php'; +require_once('inc/class.page.php'); +require_once('inc/admin.inc'); + $scripts = array('jQuery','jQueryUI'); $adminpage = new page('Administration',$scripts,FALSE); @@ -79,7 +81,17 @@ $result = ''; if(isset($_GET['rehash'])) { // Run the rehash - $result = 'Rehash Complete'; + + $crawl_schools = NULL; + if (isset($_REQUEST['rehash_school'])) + $crawl_schools = array($_REQUEST['rehash_school']); + + if (school_cache_recreate($crawl_schools)) + $result = 'Rehash Failed'; + else + $result = 'Rehash Successful'; + if ($crawl_schools !== NULL) + $result .= ': ' . implode(', ', $crawl_schools); } else if(isset($_GET['purgetodate'])) { // Purge saved schedule cache up to date @@ -102,28 +114,15 @@ return date("F j, Y, g:i a", $stats[9]); } - function getSchools() { - if(!stat("cache/schools")){ - return false; - } - $schoolsArr = unserialize(file_get_contents("cache/schools")); - return $schoolsArr; - } - - function schoolsDropList(){ - $schools = getSchools(); - echo ''; - foreach($schools['list'] as $school){ - if(!$school['name'] != "Generic College") { - echo ''; - echo $school['name']; - echo ""; + function schoolsDropList() + { + $school_ids = school_list(); + echo ''; + foreach($school_ids as $school_id) + { + $school = school_load($school_id); + echo ' ' . $school['name'] . '' . "\n"; } - } echo ""; } @@ -158,12 +157,19 @@ } ?> - Rehash All Institutions - Rehash schedules for + + Rehash All Institutions + + + Rehash schedules for + + + + Purge -The cache currently contains schedules. +The saved schedule fs-db currently contains schedules. Purge Entire Cache Purge cache up to diff --git a/admin/rehash.php b/admin/rehash.php --- a/admin/rehash.php +++ b/admin/rehash.php @@ -44,10 +44,6 @@ function main($argc, $argv) return 1; } - $crawl = TRUE; - $crawl_semester_year = '2011'; - $crawl_semester_season = Semester::SEASON_SPRING; - $opts = getopt('hV:', array('no-crawl', 'crawl-only:', 'help', 'verbosity:')); if (isset($opts['help']) || isset($opts['h'])) @@ -56,6 +52,7 @@ function main($argc, $argv) return 0; } + $crawl = TRUE; if (isset($opts['no-crawl'])) $crawl = FALSE; if (isset($opts['crawl-only'])) @@ -74,54 +71,18 @@ function main($argc, $argv) return 1; } - $school_id_list = school_list(); - if (!$school_id_list) - { - fprintf(STDERR, "error: Unable to load schools.\n"); - return 1; - } - - $schools = array(); - $old_school_cache = _school_cache_load(); - foreach ($school_id_list as $school_id) + if ($crawl) { - $school = school_load($school_id, TRUE); - if (!$school) + $ret = school_cache_recreate($crawl_only); + if ($ret) { - fprintf(STDERR, "Error loading school with school_id=%s\n", - $school_id); + fprintf(STDERR, "error: Unable to successfully crawl schools.\n"); return 1; } - - if ($crawl - && (!isset($crawl_only) || in_array($school['id'], $crawl_only))) - { - school_crawl($school, $crawl_semester_year, $crawl_semester_season, $verbosity); - } else { - /* - * try to allow incremental crawling by not wiping out old - * data and preserving the cached $school['crawled']. - */ - if ($old_school_cache && isset($old_school_cache['list'][$school['id']])) - { - $old_school = $old_school_cache['list'][$school['id']]; - $school['crawled'] = FALSE; - if (isset($old_school['crawled'])) - $school['crawled'] = $old_school['crawled']; - if ($school['crawled']) - $school['crawled_notreally'] = TRUE; - } + fprintf(STDERR, "Crawling successful.\n"); } - - $schools[] = $school; - } - - if (school_cache($schools)) - { - fprintf(STDERR, "Error writing out school cache\n"); - return 1; } return 0; diff --git a/inc/admin.inc b/inc/admin.inc --- a/inc/admin.inc +++ b/inc/admin.inc @@ -18,9 +18,12 @@ * along with slate_permutate. If not, see . */ -$incdir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR; +$inc_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR; -require_once($incdir . 'schedule_store.inc'); +require_once($inc_dir . 'schedule_store.inc'); +require_once($inc_dir . 'class.semester.inc'); +require_once($inc_dir . 'school.inc'); +require_once($inc_dir . 'school.crawl.inc'); /** * \file @@ -239,6 +242,83 @@ function school_crawl(&$school, $semeste fwrite(STDERR, "\n"); } + +/** + * \brief + * Recreate/update the school section autocomplete cache. + * + * \param $crawl_only + * If non-NULL, an array of school_ids to limit the cache recreation + * to. Useful for when developing a certain school's crawling + * function. + */ +function school_cache_recreate($crawl_only = NULL) +{ + $crawl_semester_year = '2011'; + $crawl_semester_season = Semester::SEASON_SPRING; + + $school_id_list = school_list(); + if (!$school_id_list) + { + fprintf(STDERR, "error: Unable to load schools.\n"); + return 1; + } + + if ($crawl_only !== NULL) + foreach ($crawl_only as $crawl_only_school_id) + if (!in_array($crawl_only_school_id, $school_id_list)) + { + fprintf(STDERR, "error: Invalid school_id specified for crawling: %s", + $crawl_only_school_id); + return 1; + } + + $schools = array(); + $old_school_cache = _school_cache_load(); + foreach ($school_id_list as $school_id) + { + $school = school_load($school_id, TRUE); + if (!$school) + { + fprintf(STDERR, "Error loading school with school_id=%s\n", + $school_id); + return 1; + } + + if ($crawl_only === NULL || in_array($school['id'], $crawl_only)) + { + school_crawl($school, $crawl_semester_year, $crawl_semester_season, $verbosity); + } + else + { + /* + * try to allow incremental crawling by not wiping out old + * data and preserving the cached $school['crawled']. + */ + if ($old_school_cache && isset($old_school_cache['list'][$school['id']])) + { + $old_school = $old_school_cache['list'][$school['id']]; + $school['crawled'] = FALSE; + if (isset($old_school['crawled'])) + $school['crawled'] = $old_school['crawled']; + if ($school['crawled']) + $school['crawled_notreally'] = TRUE; + } + } + + $schools[] = $school; + } + + if (school_cache($schools)) + { + fprintf(STDERR, "Error writing out school cache\n"); + return 1; + } + + return 0; +} + + /** * \brief * A small testsuite to help developers.
The cache currently contains schedules.
The saved schedule fs-db currently contains schedules.