load_plugins() static public method

static public load_plugins ( $context )
Beispiel #1
0
 /**
  * Rebuild caches, indexes, etc.
  */
 static function rebuild($forceFullRebuild = false)
 {
     gb::log(LOG_NOTICE, 'rebuilding cache' . ($forceFullRebuild ? ' (forcing full rebuild)' : ''));
     $time_started = microtime(1);
     $failures = array();
     # Load rebuild plugins
     gb::load_plugins('rebuild');
     # Load rebuilders if needed
     if (empty(self::$rebuilders)) {
         self::loadRebuilders();
     }
     # Create rebuilder instances
     $rebuilders = array();
     foreach (self::$rebuilders as $cls) {
         $rebuilders[] = new $cls($forceFullRebuild);
     }
     # Load rebuild plugins (2nd offer)
     gb::load_plugins('rebuild');
     # Query ls-tree
     $ls = rtrim(git::exec('ls-files --stage'));
     if ($ls) {
         # Iterate objects
         $ls = explode("\n", $ls);
         foreach ($ls as $line) {
             try {
                 # <mode> SP <object> SP <stage no> TAB <name>
                 if (!$line) {
                     continue;
                 }
                 $line = explode(' ', $line, 3);
                 $id = $line[1];
                 $name = gb_normalize_git_name(substr($line[2], strpos($line[2], "\t") + 1));
                 foreach ($rebuilders as $rebuilder) {
                     $rebuilder->onObject($name, $id);
                 }
             } catch (RuntimeException $e) {
                 gb::log(LOG_ERR, 'failed to rebuild object %s %s: %s', var_export($name, 1), $e->getMessage(), $e->getTraceAsString());
                 $failures[] = array($rebuilder, $name);
             }
         }
     }
     # Let rebuilders finalize
     foreach ($rebuilders as $rebuilder) {
         try {
             $rebuilder->finalize();
         } catch (RuntimeException $e) {
             gb::log(LOG_ERR, 'rebuilder %s (0x%x) failed to finalize: %s', get_class($rebuilder), spl_object_hash($rebuilder), GBException::format($e, true, false, null, 0));
             $failures[] = array($rebuilder, null);
         }
     }
     gb::log(LOG_NOTICE, 'cache updated -- time spent: %s', gb_format_duration(microtime(1) - $time_started));
     return $failures;
 }
Beispiel #2
0
/**
 * Takes care of removing comments.
 * 
 * Events:
 * 
 * - "did-remove-comment", $comment
 *   Posted after a comment was removed, but before the response is sent.
 * 
 */
require '../../gitblog.php';
ini_set('html_errors', '0');
header('Content-Type: text/plain; charset=utf-8');
header('Cache-Control: no-cache');
gb::verify();
gb::authenticate();
gb::load_plugins('admin');
static $fields = array('object' => FILTER_REQUIRE_SCALAR, 'comment' => FILTER_REQUIRE_SCALAR);
static $required_fields = array('object', 'comment');
# sanitize and validate input
$input = filter_input_array($_SERVER['REQUEST_METHOD'] === 'POST' ? INPUT_POST : INPUT_GET, $fields);
function exit2($msg, $status = '400 Bad Request')
{
    header('Status: ' . $status);
    exit($status . "\n" . $msg . "\n");
}
# Optimally only allow the DELETE method, but as we live with HTML that's not
# gonna happen very soon unfortunately.
# assure required fields are OK
$fields_missing = array();
foreach ($required_fields as $field) {
    if (!$input[$field]) {
Beispiel #3
0
 static function loadWork($path, $post = false, $class = 'GBExposedContent', $id = null, $slug = null, $applyBodyFilters = true)
 {
     if ($post === false) {
         $post = new $class(self::pathspecFromAbsPath($path), $id, $slug);
     }
     $post->id = $id;
     gb::event('will-load-work-object', $post);
     # load rebuild plugins before calling reload
     gb::load_plugins('rebuild');
     # reload post with work data
     $post->reload(file_get_contents($path), null, $applyBodyFilters);
     # set modified date from file
     $post->modified = new GBDateTime(filemtime($path));
     # set author if needed
     if (!$post->author) {
         # GBUser have the same properties as the regular class-less author
         # object, so it's safe to just pass it on here, as a clone.
         if (gb::$authorized) {
             $post->author = clone gb::$authorized;
             unset($post->passhash);
         } elseif ($padmin = GBUser::findAdmin()) {
             $post->author = clone $padmin;
             unset($post->passhash);
         } else {
             $post->author = new GBAuthor();
         }
     }
     gb::event('did-load-work-object', $post);
     return $post;
 }