init(); self::$environment_bootstrapped = true; } public function bootstrap() { if ( self::is_bootstrapped() ) { return; } self::$bootstrapped_by_wordpress = true; self::$assume_not_bootstrapped = false; // we need to unset it again to prevent recursion self::bootstrap_environment(); FrontController::unsetInstance(); $controller = FrontController::getInstance(); $controller->init(); add_action( 'set_current_user', function () { $access = \Piwik\Access::getInstance(); if ( $access ) { $access->reloadAccess(); } } ); } public static function is_bootstrapped() { if ( true === self::$assume_not_bootstrapped ) { return false; } return defined( 'PIWIK_DOCUMENT_ROOT' ); } /** * @api */ public static function do_bootstrap() { $bootstrap = new Bootstrap(); $bootstrap->bootstrap(); } public static function destroy_bootstrapped_environment() { if ( ! self::$environment_bootstrapped ) { return; } Option::clearCache(); \Piwik\Site::clearCache(); Cache::getTransientCache()->flushAll(); \Piwik\Plugin\API::unsetAllInstances(); \Piwik\Tracker\Cache::$cache = null; \Piwik\DataTable\Manager::getInstance()->deleteAll(); \Piwik\DataAccess\ArchiveTableCreator::clear(); \Piwik\Plugins\ScheduledReports\API::$cache = []; \Piwik\Singleton::clearAll(); \Piwik\ArchiveProcessor\PluginsArchiver::$archivers = []; \Piwik\Notification\Manager::cancelAllNotifications(); StaticContainer::clearContainer(); self::$environment_bootstrapped = false; self::$bootstrapped_by_wordpress = false; self::$assume_not_bootstrapped = true; } }