/** * * * @param null $AddonCode * @param bool $Explicit * @param bool $Drop * @throws Exception */ public function runStructure($AddonCode = null, $Explicit = false, $Drop = false) { // Get the structure files for all of the enabled applications. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->enabledApplications(); $AppNames = consolidateArrayValuesByKey($Apps, 'Folder'); $Paths = array(); foreach ($Apps as $Key => $AppInfo) { $Path = PATH_APPLICATIONS . "/{$AppInfo['Folder']}/settings/structure.php"; if (file_exists($Path)) { $Paths[] = $Path; } Gdn::applicationManager()->registerPermissions($Key, $this->Validation); } // Execute the structures. $Database = Gdn::database(); $SQL = Gdn::sql(); $Structure = Gdn::structure(); foreach ($Paths as $Path) { include $Path; } // Execute the structures for all of the plugins. $PluginManager = Gdn::pluginManager(); $Registered = $PluginManager->registeredPlugins(); foreach ($Registered as $ClassName => $Enabled) { if (!$Enabled) { continue; } try { $Plugin = $PluginManager->getPluginInstance($ClassName, Gdn_PluginManager::ACCESS_CLASSNAME); if (method_exists($Plugin, 'Structure')) { trace("{$ClassName}->Structure()"); $Plugin->structure(); } } catch (Exception $Ex) { // Do nothing, plugin wouldn't load/structure. if (Debug()) { throw $Ex; } } } $this->fireEvent('AfterStructure'); }
/** * Run the database structure or /utility/structure. * * Note: Keep this method protected! * * @param string $appName Unique app name or 'all' (default). * @param bool $captureOnly Whether to list changes rather than execute (0 or 1). * @throws Exception */ protected function runStructure($appName = 'all', $captureOnly = true) { // This permission is run again to be sure someone doesn't accidentally call this method incorrectly. $this->permission('Garden.Settings.Manage'); $Files = array(); $appName = $appName == '' ? 'all' : $appName; if ($appName == 'all') { // Load all application structure files. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->enabledApplications(); $AppNames = array_column($Apps, 'Folder'); foreach ($AppNames as $appName) { $Files[] = combinePaths(array(PATH_APPLICATIONS, $appName, 'settings', 'structure.php'), DS); } $appName = 'all'; } else { // Load that specific application structure file. $Files[] = combinePaths(array(PATH_APPLICATIONS, $appName, 'settings', 'structure.php'), DS); } $Drop = false; $Explicit = false; $captureOnly = !($captureOnly == '0'); $Structure = Gdn::structure(); $Structure->CaptureOnly = $captureOnly; $SQL = Gdn::sql(); $SQL->CaptureModifications = $captureOnly; $this->setData('CaptureOnly', $Structure->CaptureOnly); $this->setData('Drop', $Drop); $this->setData('Explicit', $Explicit); $this->setData('ApplicationName', $appName); $this->setData('Status', ''); $FoundStructureFile = false; foreach ($Files as $File) { if (file_exists($File)) { $FoundStructureFile = true; try { include $File; } catch (Exception $Ex) { $this->Form->addError($Ex); } } } // Run the structure of all of the plugins. $Plugins = Gdn::pluginManager()->enabledPlugins(); foreach ($Plugins as $PluginKey => $Plugin) { $PluginInstance = Gdn::pluginManager()->getPluginInstance($PluginKey, Gdn_PluginManager::ACCESS_PLUGINNAME); if (method_exists($PluginInstance, 'Structure')) { $PluginInstance->structure(); } } if (property_exists($Structure->Database, 'CapturedSql')) { $this->setData('CapturedSql', (array) $Structure->Database->CapturedSql); } else { $this->setData('CapturedSql', array()); } if ($this->Form->errorCount() == 0 && !$captureOnly && $FoundStructureFile) { $this->setData('Status', 'The structure was successfully executed.'); } }
/** * * * @param $ThemeName * @return bool * @throws Gdn_UserException */ public function testTheme($ThemeName) { // Get some info about the currently enabled theme. $EnabledTheme = $this->enabledThemeInfo(); $EnabledThemeFolder = val('Folder', $EnabledTheme, ''); $OldClassName = $EnabledThemeFolder . 'ThemeHooks'; // Make sure that the theme's requirements are met $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->enabledApplications(); $NewThemeInfo = $this->getThemeInfo($ThemeName); $ThemeName = val('Index', $NewThemeInfo, $ThemeName); $RequiredApplications = val('RequiredApplications', $NewThemeInfo, false); $ThemeFolder = val('Folder', $NewThemeInfo, ''); checkRequirements($ThemeName, $RequiredApplications, $EnabledApplications, 'application'); // Applications // If there is a hooks file, include it and run the setup method. $ClassName = "{$ThemeFolder}ThemeHooks"; $HooksFile = val("HooksFile", $NewThemeInfo, null); if (!is_null($HooksFile) && file_exists($HooksFile)) { include_once $HooksFile; if (class_exists($ClassName)) { $ThemeHooks = new $ClassName(); $ThemeHooks->Setup(); } } // If there is a hooks in the old theme, include it and run the ondisable method. if (class_exists($OldClassName)) { $ThemeHooks = new $OldClassName(); if (method_exists($ThemeHooks, 'OnDisable')) { $ThemeHooks->OnDisable(); } } return true; }
/** * Update database structure based on current definitions in each app's structure.php file. * * @since 2.0.? * @access public * @param string $AppName Unique app name or 'all' (default). * @param int $CaptureOnly Whether to list changes rather than execture (0 or 1). * @param int $Drop Whether to drop first (0 or 1). * @param int $Explicit Whether to force to only columns currently listed (0 or 1). */ public function structure($AppName = 'all', $CaptureOnly = '1', $Drop = '0', $Explicit = '0') { $this->permission('Garden.Settings.Manage'); $Files = array(); $AppName = $AppName == '' ? 'all' : $AppName; if ($AppName == 'all') { // Load all application structure files. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->enabledApplications(); $AppNames = array_column($Apps, 'Folder'); foreach ($AppNames as $AppName) { $Files[] = combinePaths(array(PATH_APPLICATIONS, $AppName, 'settings', 'structure.php'), DS); } $AppName = 'all'; } else { // Load that specific application structure file. $Files[] = combinePaths(array(PATH_APPLICATIONS, $AppName, 'settings', 'structure.php'), DS); } $Validation = new Gdn_Validation(); $Database = Gdn::database(); $Drop = $Drop == '0' ? false : true; $Explicit = $Explicit == '0' ? false : true; $CaptureOnly = !($CaptureOnly == '0'); $Structure = Gdn::structure(); $Structure->CaptureOnly = $CaptureOnly; $SQL = Gdn::sql(); $SQL->CaptureModifications = $CaptureOnly; $this->setData('CaptureOnly', $Structure->CaptureOnly); $this->setData('Drop', $Drop); $this->setData('Explicit', $Explicit); $this->setData('ApplicationName', $AppName); $this->setData('Status', ''); $FoundStructureFile = false; foreach ($Files as $File) { if (file_exists($File)) { $FoundStructureFile = true; try { include $File; } catch (Exception $Ex) { $this->Form->addError($Ex); } } } // Run the structure of all of the plugins. $Plugins = Gdn::pluginManager()->enabledPlugins(); foreach ($Plugins as $PluginKey => $Plugin) { $PluginInstance = Gdn::pluginManager()->getPluginInstance($PluginKey, Gdn_PluginManager::ACCESS_PLUGINNAME); if (method_exists($PluginInstance, 'Structure')) { $PluginInstance->structure(); } } if (property_exists($Structure->Database, 'CapturedSql')) { $this->setData('CapturedSql', (array) $Structure->Database->CapturedSql); } else { $this->setData('CapturedSql', array()); } if ($this->Form->errorCount() == 0 && !$CaptureOnly && $FoundStructureFile) { $this->setData('Status', 'The structure was successfully executed.'); } $this->addSideMenu('dashboard/settings/configure'); $this->addCssFile('admin.css'); $this->setData('Title', t('Database Structure Upgrades')); $this->render(); }