public function runStructure($captureOnly = false)
{
$addons = array_reverse(Gdn::addonManager()->getEnabled());
// These variables are required for included structure files.
$Database = Gdn::database();
$SQL = $this->SQL;
$SQL->CaptureModifications = $captureOnly;
$Structure = Gdn::structure();
$Structure->CaptureOnly = $captureOnly;
/* @var Addon $addon */
foreach ($addons as $addon) {
// Look for a structure file.
if ($structure = $addon->getSpecial('structure')) {
Logger::event('addon_structure', Logger::INFO, "Executing structure for {addonKey}.", ['addonKey' => $addon->getKey(), 'structureType' => 'file']);
try {
include $addon->path($structure);
} catch (\Exception $ex) {
if (debug()) {
throw $ex;
}
}
}
// Look for a structure method on the plugin.
if ($addon->getPluginClass()) {
$plugin = Gdn::pluginManager()->getPluginInstance($addon->getPluginClass(), Gdn_PluginManager::ACCESS_CLASSNAME);
if (is_object($plugin) && method_exists($plugin, 'structure')) {
Logger::event('addon_structure', Logger::INFO, "Executing structure for {addonKey}.", ['addonKey' => $addon->getKey(), 'structureType' => 'method']);
try {
call_user_func([$plugin, 'structure']);
} catch (\Exception $ex) {
if (debug()) {
throw $ex;
}
}
}
}
// Register permissions.
$permissions = $addon->getInfoValue('registerPermissions');
if (!empty($permissions)) {
Logger::event('addon_permissions', Logger::INFO, "Defining permissions for {addonKey}.", ['addonKey' => $addon->getKey(), 'permissions' => $permissions]);
Gdn::permissionModel()->define($permissions);
}
}
$this->fireEvent('AfterStructure');
if ($captureOnly && property_exists($Structure->Database, 'CapturedSql')) {
return $Structure->Database->CapturedSql;
}
return [];
}