Files
@ 318a910b91ad
Branch filter:
Location: SlatePermutate/admin/saveschedule_purge.php
318a910b91ad
4.6 KiB
text/x-php
Now instead of automatically guessing that a user want to register for the next semester, assume they want to register for a semester whose middle is half a year into the future.
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 151 152 153 154 155 156 157 | #!/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
*
* Provides a way to easily purge a number of saved schedules through
* a date range.
*/
$inc_base = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR;
require_once($inc_base . 'admin.inc');
return main($argc, $argv);
function main($argc, $argv)
{
global $admin_enable_purge;
$n = test();
if ($n)
{
fprintf(STDERR, "%d tests failed; exiting\n",
$n);
return 1;
}
$opts = getopt('hV:', array('all', 'max-time:', 'min-time:', 'help', 'verbosity:'));
if (isset($opts['help']) || isset($opts['h']))
{
usage($argv[0]);
return 0;
}
$all = FALSE;
if (isset($opts['all']))
$crawl = TRUE;
foreach (array('min', 'max') as $time_var)
{
if (isset($opts[$time_var . '-time']))
{
${$time_var . '_time'} = strtotime($opts[$time_var . '-time']);
/* two ways of saying the thing failed -- was -1 until PHP 5.1.0 */
if (${$time_var . '_time'} === FALSE || ${$time_var . '_time'} == -1)
{
fprintf(STDERR, "%s-time: Invalid date/time format, can't understand string: ``%s''.\n",
$time_var, $opts['min-time']);
return 1;
}
}
}
if ($all && (isset($min_time) || isset($max_time)))
{
fprintf(STDERR, "error: Both --all and one of --max-time or --min-time were specified. These options are mutually exclusive.\n");
return 1;
}
if (!$all && (!isset($min_time) || !isset($max_time)))
{
if (isset($min_time) || isset($max_time))
fprintf(STDERR, "error: If --min-time is set, --max-time must also be set and vice versa. This is to prevent accidents.\n");
else
fprintf(STDERR, "error: Either --all or both of --min-time and --max-time must be passed to purge saved schedules.\n");
return 1;
}
$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;
}
if ($all)
{
fprintf(STDOUT, "Purging all schedules.\n");
}
if (!isset($min_time))
$min_time = 0;
if (!isset($max_time))
$max_time = NULL;
else
fprintf(STDOUT, "Purging from %s to %s.\n",
strftime("%F %T", $min_time), strftime("%F %T", $max_time));
$schedule_store = schedule_store_init();
if (!$schedule_store)
{
fprintf(STDERR, "error: Unable to initialize schedule_store.\n");
return 1;
}
$ret = schedule_store_purge_range($schedule_store, $min_time, $max_time);
if ($ret === FALSE)
{
fprintf(STDERR, "error: Unable to purge schedule_store%s.\n",
$all ? '' : ' range');
if (!$admin_enable_purge)
fprintf(STDERR, "error: You need to set " . '$admin_enable_purge' . " in config.inc to enable purging schedules through the administration utilities.\n");
return 1;
}
fprintf(STDOUT, "Schedules deleted: %s\n",
$ret);
fprintf(STDOUT, "Purge successful.\n");
return 0;
}
/**
* \brief
* Display CLI interface usage.
*/
function usage($progname)
{
fprintf(STDERR, "Usage: %s [--all] [--min-time=<min time>] [--max-time=<max time>] [--help] [-h]\n"
. "\n"
. " -h, --help Show this usage information and exit.\n"
. "\n"
. " --all Purge all saved schedules.\n"
. " --min-time Takes a date/time string after which a schedule must\n"
. " have been created to be deleted.\n"
. " --max-time Takes a date/time string before which a schedule must\n"
. " be saved to be dleted.\n"
. " -v, --verbosity Set the verbosity level. Valid range is from 0\n"
. " through 10.",
$progname);
}
|