Changeset - 09d0e466a11b
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 15 years ago 2011-01-01 02:31:37
ohnobinki@ohnopublishing.net
Fix the admin page's count of saved schedules.
2 files changed with 27 insertions and 3 deletions:
0 comments (0 inline, 0 general)
admin.php
Show inline comments
 
@@ -117,26 +117,28 @@ require_once('inc/admin.inc');
 
  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>";
 
  }
 

	
 
  function getNumSaved(){
 
    return file_get_contents("saved_schedules/lastid");
 
  function getMaxSaved()
 
  {
 
    $schedule_store = schedule_store_init();
 
    return schedule_store_getmaxid($schedule_store);
 
  }
 

	
 
?>
 

	
 

	
 
<?php /* Check if authorized */ 
 

	
 
  $res = checkAction();
 
  if($res != '') {
 
    echo '<p><em>' . $res . '</em> <a href="admin.php">(x)</a></p>';
 
  }
 
?>
 
@@ -160,20 +162,20 @@ require_once('inc/admin.inc');
 
  <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 saved schedule fs-db currently contains <?php echo getNumSaved(); ?> schedules.</p>
 
    <p>The highest saved_schedule id is <a href="<?php $max_saved = getMaxSaved(); echo Schedule::url($max_saved); ?>"><?php echo $max_saved;?></a>.</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>
 
</ul>
 

	
 
<?php
 
$adminpage->foot();
inc/schedule_store.inc
Show inline comments
 
@@ -125,24 +125,46 @@ function schedule_store_retrieve($schedu
 
 *   The identifier of the schedule to delete.
 
 */
 
function schedule_store_delete($schedule_store, $schedule_id)
 
{
 
  $remove_filename = $schedule_store['dir'] . DIRECTORY_SEPARATOR . $schedule_id;
 
  /* avoid an E_WARNING if the file doesn't exist */
 
  if (file_exists($remove_filename))
 
    unlink($remove_filename);
 
}
 

	
 
/**
 
 * \brief
 
 *   Get an unreliable max schedule_id number.
 
 *
 
 * Useful for stats-only: for when the user is interested in knowing
 
 * the last registered schedule_id. Don't use this for creating new
 
 * schedule_ids, use schedule_store_store() for that instead.
 
 *
 
 * \param $schedule_store
 
 *   The schedule_store handle.
 
 * \return
 
 *   An integer, the last schedule_id.
 
 */
 
function schedule_store_getmaxid($schedule_store)
 
{
 
  _schedule_store_flock_grab($schedule_store, LOCK_SH);
 
  $schedule_id = (int)file_get_contents($schedule_store['dir'] . DIRECTORY_SEPARATOR . 'lastid');
 
  _schedule_store_flock_release($schedule_store);
 
  return $schedule_id;
 
}
 

	
 

	
 
/**
 
 * \brief
 
 *   Obtains a lock on the /lastid file in the schedule_store.
 
 *
 
 * \see _schedule_store_flock_release().
 
 *
 
 * \param $schedule_store
 
 *   The schedule_store instance we're working with.
 
 * \param $operation
 
 *   Which flock() operation to perform: valid are LOCK_SH and LOCK_EX.
 
 * \return
 
 *   TRUE on success, FALSE on failure. (see flock()).
 
 */
 
function _schedule_store_flock_grab(&$schedule_store, $operation)
0 comments (0 inline, 0 general)