/**
* Method to preload the Rules objects for all components.
*
* Note: This will only get the base permissions for the component.
* e.g. it will get 'com_content', but not 'com_content.article.1' or
* any more specific asset type rules.
*
* @return array Array of component names that were preloaded.
*
* @since 1.6
*/
protected static function preloadComponents()
{
// If the components already been preloaded do nothing.
if (isset(self::$preloadedAssetTypes['components'])) {
return array();
}
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::preloadComponents (all components)');
// Add root to asset names list.
$components = array('root.1');
// Add enabled components to asset names list.
foreach (ComponentHelper::getComponents() as $component) {
if ($component->enabled) {
$components[] = $component->option;
}
}
// Get the database connection object.
$db = Factory::getDbo();
// Get the asset info for all assets in asset names list.
$query = $db->getQuery(true)->select($db->quoteName(array('id', 'name', 'rules', 'parent_id')))->from($db->quoteName('#__assets'))->whereIn($db->quoteName('name'), $components, ParameterType::STRING);
// Get the Name Permission Map List
$assets = $db->setQuery($query)->loadObjectList();
$rootAsset = null;
// First add the root asset and save it to preload memory and mark it as preloaded.
foreach ($assets as &$asset) {
if ((int) $asset->parent_id === 0) {
$rootAsset = $asset;
self::$rootAssetId = $asset->id;
self::$preloadedAssetTypes[$asset->name] = true;
self::$preloadedAssets[$asset->id] = $asset->name;
self::$assetPermissionsParentIdMapping[$asset->name][$asset->id] = $asset;
unset($asset);
break;
}
}
// Now create save the components asset tree to preload memory.
foreach ($assets as $asset) {
if (!isset(self::$assetPermissionsParentIdMapping[$asset->name])) {
self::$assetPermissionsParentIdMapping[$asset->name] = array($rootAsset->id => $rootAsset, $asset->id => $asset);
self::$preloadedAssets[$asset->id] = $asset->name;
}
}
// Mark all components asset type as preloaded.
self::$preloadedAssetTypes['components'] = true;
!JDEBUG ?: Profiler::getInstance('Application')->mark('After Access::preloadComponents (all components)');
return $components;
}