Index: branches/5.2.x/core/units/configuration/configuration_event_handler.php =================================================================== diff -u -N -r14787 -r14934 --- branches/5.2.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 14787) +++ branches/5.2.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 14934) @@ -1,6 +1,6 @@ Array ('self' => 'add|edit'), + ); + + $this->permMapping = array_merge($this->permMapping, $permissions); + } + /** * Changes permission section to one from REQUEST, not from config * @@ -136,13 +147,24 @@ } } - if ( $object->GetDBField('VariableName') == 'AdminConsoleInterface' ) { + $variable_name = $object->GetDBField('VariableName'); + $new_value = $object->GetDBField('VariableValue'); + + if ( $variable_name == 'AdminConsoleInterface' ) { $can_change = $this->Application->ConfigValue('AllowAdminConsoleInterfaceChange'); - if ( ($object->GetDBField('VariableValue') != $object->GetOriginalField('VariableValue')) && !$can_change ) { + if ( ($new_value != $object->GetOriginalField('VariableValue')) && !$can_change ) { $object->SetError('VariableValue', 'not_allowed', 'la_error_OperationNotAllowed'); } } + elseif ( $variable_name == 'HardMaintenanceTemplate' ) { + $compile = $event->MasterEvent->getEventParam('compile_maintenance_template'); + $compile = $compile || $new_value != $object->GetOriginalField('VariableValue'); + + if ( $compile && !$this->generateMaintenancePage($new_value) ) { + $object->SetError('VariableValue', 'template_file_missing', 'la_error_TemplateFileMissing'); + } + } } /** @@ -172,6 +194,9 @@ if ( $object->GetDBField('VariableValue') != $object->GetOriginalField('VariableValue') ) { $changed[] = $variable_name; $this->Application->SetVar($event->getPrefixSpecial() . '_changed', $changed); + + // update value in cache, so other code (during this script run) would use new value + $this->Application->SetConfigValue($variable_name, $object->GetDBField('VariableValue'), true); } if ( $variable_name == 'Require_AdminSSL' || $variable_name == 'AdminSSL_URL' ) { @@ -289,4 +314,44 @@ $event->SetRedirectParam('opener', 'u'); } + /** + * Generates maintenance page + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnGenerateMaintenancePage(kEvent &$event) + { + $event->setEventParam('compile_maintenance_template', 1); + + $event->CallSubEvent('OnUpdate'); + } + + /** + * Generates HTML version of hard maintenance template + * + * @param string $template + * @return bool + * @access protected + */ + protected function generateMaintenancePage($template = null) + { + if ( !isset($template) ) { + $template = $this->Application->ConfigValue('HardMaintenanceTemplate'); + } + + $curl_helper =& $this->Application->recallObject('CurlHelper'); + /* @var $curl_helper kCurlHelper */ + + $html = $curl_helper->Send($this->Application->BaseURL() . '?t=' . $template); + + if ( $curl_helper->isGoodResponseCode() ) { + file_put_contents(WRITEABLE . DIRECTORY_SEPARATOR . 'maintenance.html', $html); + + return true; + } + + return false; + } } \ No newline at end of file