Changeset - 3abd7f81e51a
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2010-11-29 23:43:06
ohnobinki@ohnopublishing.net
Expand the admin script to allow verbosity to be specified.
1 file changed with 22 insertions and 4 deletions:
0 comments (0 inline, 0 general)
admin/rehash.php
Show inline comments
 
@@ -38,57 +38,73 @@ function main($argc, $argv)
 
  $n = test();
 
  if ($n)
 
    {
 
      fprintf(STDERR, "%d tests failed; exiting\n",
 
	      $n);
 
      return 1;
 
    }
 

	
 
  $crawl = TRUE;
 
  $crawl_semester_year = '2011';
 
  $crawl_semester_season = Semester::SEASON_SPRING;
 

	
 
  $opts = getopt('h', array('no-crawl', 'crawl-only:', 'help'));
 
  $opts = getopt('hV:', array('no-crawl', 'crawl-only:', 'help', 'verbosity:'));
 

	
 
  if (isset($opts['help']) || isset($opts['h']))
 
    {
 
      usage($argv[0]);
 
      return 0;
 
    }
 

	
 
  if (isset($opts['no-crawl']))
 
    $crawl = FALSE;
 
  if (isset($opts['crawl-only']))
 
    $crawl_only = split(',', $opts['crawl-only']);
 

	
 
  $verbosity = 1;
 
  if (isset($opts['verbosity']))
 
    $verbosity = (int)$opts['verbosity'];
 
  if (isset($opts['V']))
 
    $verbosity = (int)$opts['V'];
 
  if ($verbosity < 0 || $verbosity > 10)
 
    {
 
      fprintf(STDERR, "error: Invalid verbosity level: %d\n", $verbosity);
 
      fprintf(STDERR, "\n");
 
      usage();
 
      return 1;
 
    }
 

	
 
  $school_id_list = school_list();
 
  if (!$school_id_list)
 
    return 1;
 
    {
 
      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)
 
    {
 
      $school = school_load($school_id, TRUE);
 
      if (!$school)
 
	{
 
	  fprintf(STDERR, "Error loading school with school_id=%s\n",
 
		  $school_id);
 
	  return 1;
 
	}
 

	
 
      if ($crawl
 
	  && (!isset($crawl_only) || in_array($school['id'], $crawl_only)))
 
	{
 
	  school_crawl($school, $crawl_semester_year, $crawl_semester_season);
 
	  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']))
 
@@ -331,25 +347,27 @@ function school_crawl(&$school, $semeste
 
 *   Display CLI interface usage.
 
 */
 
function usage($progname)
 
{
 
  fprintf(STDERR, "Usage: %s [--no-crawl] [--crawl-only=<school_id1>,<school_id2>,...] [--help] [-h]\n"
 
	  . "\n"
 
	  . " -h, --help   Show this usage information and exit.\n"
 
	  . "\n"
 
	  . " --no-crawl   Disable crawling during this rehash but preserve\n"
 
	  . "              previous cached crawl data.\n"
 
	  . " --crawl-only Takes a comma-separated list of school_ids whose\n"
 
	  . "              registration systems should be crawled for autofill\n"
 
	  . "              data. Cached data from schools not listed is preserved\n",
 
	  . "              data. Cached data from schools not listed is preserved\n"
 
	  . " -v, --verbosity Set the verbosity level. Valid range is from 0\n"
 
	  . "              through 10.",
 
	  $progname);
 
}
 

	
 
/**
 
 * \brief
 
 *   A small testsuite to help developers.
 
 *
 
 * \return
 
 *   Number of failures.
 
 */
 
function test()
 
{
0 comments (0 inline, 0 general)