~catch-drupal/+junk/pressflow-content-cache-variable

« back to all changes in this revision

Viewing changes to includes/bootstrap.inc

  • Committer: David Strauss
  • Date: 2010-06-23 21:02:47 UTC
  • mfrom: (82.1.7 merge-drupal-6.17)
  • Revision ID: david@fourkitchens.com-20100623210247-ggd9fi82dyiayz98
Merge changes from the 6.17 branch that were intended for the mainline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
552
552
 * with variable_set() as well as those explicitly specified in the configuration
553
553
 * file.
554
554
 */
555
 
function variable_init($conf = array(), $regenerate = FALSE) {
 
555
function variable_init($conf = array(), $regenerate = FALSE, $recursion_depth = 0) {
556
556
  // NOTE: caching the variables improves performance by 20% when serving cached pages.
557
557
  if (!$regenerate && $cached = cache_get('variables', 'cache')) {
558
558
    $variables = $cached->data;
572
572
      // Wait for another request that is already doing this work.
573
573
      lock_wait('variable_cache_regenerate');
574
574
 
575
 
      // Run the function again.
576
 
      return variable_init($conf, $regenerate);
 
575
      // Run the function again. Try a limited number of times to avoid 
 
576
      // infinite recursion if the database connection is invalid for  
 
577
      // some reason, e.g., mysqld restart, loss of network, etc.
 
578
      $recursion_depth++;
 
579
      if ($recursion_depth < 50) {
 
580
        return variable_init($conf, $regenerate, $recursion_depth);
 
581
      }
 
582
 
 
583
      $variables = array();
577
584
    }
578
585
  }
579
586
 
614
621
 * @see variable_del(), variable_get()
615
622
 */
616
623
function variable_set($name, $value) {
617
 
  global $conf;
 
624
  global $conf, $db_prefix;
618
625
 
619
626
  $serialized_value = serialize($value);
620
627
  db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $name);
624
631
 
625
632
  $conf[$name] = $value;
626
633
 
 
634
  // The write-through rebuild optimization isn't compatible with SimpleTest.
 
635
  if (strpos($db_prefix, 'simpletest') === 0) {
 
636
    cache_clear_all('variables', 'cache');
 
637
  }
 
638
  
627
639
  variable_cache_rebuild();
628
640
}
629
641
 
636
648
 * @see variable_get(), variable_set()
637
649
 */
638
650
function variable_del($name) {
639
 
  global $conf;
 
651
  global $conf, $db_prefix;
640
652
 
641
653
  db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
642
654
 
643
655
  unset($conf[$name]);
644
656
 
 
657
  // The write-through rebuild optimization isn't compatible with SimpleTest.
 
658
  if (strpos($db_prefix, 'simpletest') === 0) {
 
659
    cache_clear_all('variables', 'cache');
 
660
  }
 
661
  
645
662
  variable_cache_rebuild();
646
663
}
647
664
 
1362
1379
 *     DRUPAL_BOOTSTRAP_PATH: set $_GET['q'] to Drupal path of request.
1363
1380
 *     DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data.
1364
1381
 */
1365
 
function drupal_bootstrap($phase) {
 
1382
function drupal_bootstrap($phase = NULL) {
1366
1383
  static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0;
1367
1384
 
1368
 
  while ($phase >= $phase_index && isset($phases[$phase_index])) {
1369
 
    $current_phase = $phases[$phase_index];
1370
 
    unset($phases[$phase_index++]);
1371
 
    _drupal_bootstrap($current_phase);
 
1385
  if (isset($phase)) {
 
1386
    while ($phase >= $phase_index && isset($phases[$phase_index])) {
 
1387
      $current_phase = $phases[$phase_index];
 
1388
      unset($phases[$phase_index++]);
 
1389
      _drupal_bootstrap($current_phase);
 
1390
    }
1372
1391
  }
 
1392
  
 
1393
  return $phase_index;
1373
1394
}
1374
1395
 
1375
1396
function _drupal_bootstrap($phase) {
1403
1424
      // running tests. However, for security reasons, it is imperative that we
1404
1425
      // validate we ourselves made the request.
1405
1426
      $GLOBALS['simpletest_installed'] = TRUE;
1406
 
      if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) && !drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) {
1407
 
        header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
1408
 
        exit;
1409
 
      }
1410
1427
      if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);/", $_SERVER['HTTP_USER_AGENT'], $matches)) {
 
1428
        if (!drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) {
 
1429
          header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
 
1430
          exit;
 
1431
        }
1411
1432
        $db_prefix .= $matches[1];
1412
1433
      }
1413
1434
 
1772
1793
  }
1773
1794
  return $save_session;
1774
1795
}
 
1796
        
 
1797
/**
 
1798
 * Returns the current bootstrap phase for this Drupal process.
 
1799
 *
 
1800
 * The current phase is the one most recently completed by drupal_bootstrap().
 
1801
 *
 
1802
 * @see drupal_bootstrap()
 
1803
 */
 
1804
function drupal_get_bootstrap_phase() {
 
1805
  return drupal_bootstrap();
 
1806
}
1775
1807
 
1776
1808
/**
1777
1809
 * Validate the HMAC and timestamp of a user agent header from simpletest.
1778
1810
 */
1779
1811
function drupal_valid_test_ua($user_agent) {
 
1812
//  global $dbatabases;
1780
1813
  global $db_url;
1781
1814
 
1782
1815
  list($prefix, $time, $salt, $hmac) = explode(';', $user_agent);
1784
1817
  // We use the database credentials from settings.php to make the HMAC key, since
1785
1818
  // the database is not yet initialized and we can't access any Drupal variables.
1786
1819
  // The file properties add more entropy not easily accessible to others.
 
1820
//  $filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
1787
1821
  $filepath = './includes/bootstrap.inc';
 
1822
//  $key = sha1(serialize($databases) . filectime($filepath) . fileinode($filepath), TRUE);
1788
1823
  $key = sha1(serialize($db_url) . filectime($filepath) . fileinode($filepath), TRUE);
1789
1824
  // The HMAC must match.
1790
1825
  return $hmac == base64_encode(hash_hmac('sha1', $check_string, $key, TRUE));
1802
1837
    // We use the database credentials to make the HMAC key, since we
1803
1838
    // check the HMAC before the database is initialized. filectime()
1804
1839
    // and fileinode() are not easily determined from remote.
1805
 
    $filepath = './includes/bootstrap.inc';
 
1840
//    $filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
 
1841
    $filepath = './includes/bootstrap.inc';                
 
1842
//    $key = sha1(serialize($databases) . filectime($filepath) . fileinode($filepath), TRUE);
1806
1843
    $key = sha1(serialize($db_url) . filectime($filepath) . fileinode($filepath), TRUE);
1807
1844
  }
1808
1845
   // Generate a moderately secure HMAC based on the database credentials.