Files
        @ 250c30fbed1a
    
        
              Branch filter: 
        
    Location: SlatePermutate/admin/rehash.php - annotation
        
            
            250c30fbed1a
            4.1 KiB
            text/x-php
        
        
    
    Reorganize administration functions into inc/admin.inc so that both admin/rehash.php and admin.php (the web interface) can access them.
    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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150  | d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 250c30fbed1a 6cb196f112d9 d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6786c2eb6ae7 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 3abd7f81e51a 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a d903bd3d579e d903bd3d579e 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a d903bd3d579e d903bd3d579e 1d8c169ca478 d903bd3d579e d903bd3d579e 6cb196f112d9 d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e 6cb196f112d9 1d8c169ca478 1d8c169ca478 1d8c169ca478 3abd7f81e51a 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 6cb196f112d9 d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e d903bd3d579e 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 1d8c169ca478 3abd7f81e51a 3abd7f81e51a 3abd7f81e51a 1d8c169ca478 1d8c169ca478 6786c2eb6ae7  | #!/usr/bin/env php
<?php
/*
 * Copyright 2010 Nathan Phillip Brink <ohnobinki@ohnopublishing.net>
 *
 * This file is a part of slate_permutate.
 *
 * slate_permutate is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * slate_permutate is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with slate_permutate.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * \file
 *
 * Runs through schools.d grabbing and caching data, such as the
 * school listing used for the ``choose your school list''.
 */
$inc_base = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR;
require_once($inc_base . 'school.inc');
require_once($inc_base . 'school.crawl.inc');
require_once($inc_base . 'class.semester.inc');
require_once($inc_base . 'admin.inc');
return main($argc, $argv);
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('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)
    {
      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, $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
 *   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"
	  . " -v, --verbosity Set the verbosity level. Valid range is from 0\n"
	  . "              through 10.",
	  $progname);
}
 |