/** * Send updates to the current search processor for execution * * @param array $writes */ public static function process_writes($writes) { foreach ($writes as $write) { // For every index foreach (FullTextSearch::get_indexes() as $index => $instance) { // If that index as a field from this class if (SearchIntrospection::is_subclass_of($write['class'], $instance->dependancyList)) { // Get the dirty IDs $dirtyids = $instance->getDirtyIDs($write['class'], $write['id'], $write['statefulids'], $write['fields']); // Then add then then to the global list to deal with later foreach ($dirtyids as $dirtyclass => $ids) { if ($ids) { if (!self::$processor) { self::$processor = Injector::inst()->create('SearchUpdateProcessor'); } self::$processor->addDirtyIDs($dirtyclass, $ids, $index); } } } } } // If we do have some work to do register the shutdown function to actually do the work // Don't do it if we're testing - there's no database connection outside the test methods, so we'd // just get errors $runningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test(); if (self::$processor && !self::$registered && !$runningTests) { register_shutdown_function(array("SearchUpdater", "flush_dirty_indexes")); self::$registered = true; } }