Changeset - 830e818d2625
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 15 years ago 2011-01-01 02:15:45
ohnobinki@ohnopublishing.net
Support rehashing stuffage through the web interface. Only per-school rehashing is tested so far.
3 files changed with 120 insertions and 73 deletions:
0 comments (0 inline, 0 general)
admin.php
Show inline comments
 
@@ -18,7 +18,9 @@
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
  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 '<select>';
 
    foreach($schools['list'] as $school){
 
      if(!$school['name'] != "Generic College") {
 
        echo '<option ';
 
        if(!$school['crawled']) {
 
          echo 'class="bold" ';
 
        }
 
        echo 'value="' . $school['name'] . '">';
 
        echo $school['name'];   
 
        echo "</option>";
 
  function schoolsDropList()
 
  {
 
    $school_ids = school_list();
 
    echo '<select name="rehash_school">';
 
    foreach($school_ids as $school_id)
 
      {
 
	$school = school_load($school_id);
 
	echo '  <option value="' . $school_id . '">' . $school['name'] . '</option>' . "\n";
 
      }
 
    }
 
    echo "</select>";
 
  }
 

	
 
@@ -158,12 +157,19 @@
 
      }
 
?>
 
<ul>
 
  <li><a href="admin.php?rehash">Rehash All Institutions</a></li>
 
  <li><form action="admin.php">Rehash schedules for <?php schoolsDropList(); ?> <input type="submit" value="Go &raquo;" /> </form></li>
 
  <li>
 
    <a href="admin.php?rehash">Rehash All Institutions</a>
 
  </li>
 
  <li>
 
    <form action="admin.php">Rehash schedules for <?php schoolsDropList(); ?>
 
      <input type="hidden" name="rehash" value="1" />
 
      <input type="submit" value="Go &raquo;" />
 
    </form>
 
  </li>
 
</ul>
 

	
 
<h3>Purge</h3>
 
<p>The cache currently contains <?php echo getNumSaved(); ?> schedules.</p>
 
<p>The saved schedule fs-db currently contains <?php echo getNumSaved(); ?> schedules.</p>
 
<ul>
 
  <li><a href="admin.php?purge">Purge Entire Cache</a></li>
 
  <li><form action="admin.php">Purge cache up to <input type="text" name="purgetodate" size="8" id="datepicker"/> <input type="submit" value="Go &raquo;" /></form></li>
admin/rehash.php
Show inline comments
 
@@ -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;
inc/admin.inc
Show inline comments
 
@@ -18,9 +18,12 @@
 
 * along with slate_permutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
$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.
0 comments (0 inline, 0 general)