Fixed PHP timeout option merging bug

This commit is contained in:
Marc Aymerich 2015-06-05 09:57:06 +00:00
parent b4670610ee
commit c8ceff0358
6 changed files with 26 additions and 19 deletions

View File

@ -421,3 +421,6 @@ serailzer self.instance on create.
# use namedtuples!
# Negative transactionsx
# check certificate: websites directive ssl + domains search on miscellaneous

View File

@ -40,7 +40,7 @@ class WebAppOptionInline(admin.TabularInline):
webapp_modeladmin = get_modeladmin(self.parent_model)
plugin_value = webapp_modeladmin.get_plugin_value(request)
plugin = AppType.get(plugin_value)
kwargs['choices'] = plugin.get_options_choices()
kwargs['choices'] = plugin.get_group_options_choices()
# Help text based on select widget
target = 'this.id.replace("name", "value")'
kwargs['widget'] = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT)

View File

@ -163,7 +163,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController):
super(PHPBackend, self).commit()
def get_fpm_config(self, webapp, context):
options = webapp.get_options(merge=self.MERGE)
options = webapp.type_instance.get_options()
context.update({
'init_vars': webapp.type_instance.get_php_init_vars(merge=self.MERGE),
'max_children': options.get('processes', settings.WEBAPPS_FPM_DEFAULT_MAX_CHILDREN),
@ -217,7 +217,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController):
exec %(php_binary_path)s%(php_init_vars)s""") % context
def get_fcgid_cmd_options(self, webapp, context):
options = webapp.get_options(merge=self.MERGE)
options = webapp.type_instance.get_options()
maps = OrderedDict(
MaxProcesses=options.get('processes', None),
IOTimeout=options.get('timeout', None),

View File

@ -55,17 +55,7 @@ class WebApp(models.Model):
a = apptype.clean_data()
self.data = apptype.clean_data()
@cached
def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
kwargs = {
'webapp_id': self.pk,
}
if merge:
kwargs = {
'webapp__account': self.account_id,
'webapp__type': self.type,
'webapp__data__contains': '"php_version":"%s"' % self.data['php_version'],
}
def get_options(self, **kwargs):
options = OrderedDict()
qs = WebAppOption.objects.filter(**kwargs)
for name, value in qs.values_list('name', 'value').order_by('name'):
@ -102,7 +92,7 @@ class WebApp(models.Model):
class WebAppOption(models.Model):
webapp = models.ForeignKey(WebApp, verbose_name=_("Web application"),
related_name='options')
name = models.CharField(_("name"), max_length=128, choices=AppType.get_options_choices())
name = models.CharField(_("name"), max_length=128, choices=AppType.get_group_options_choices())
value = models.CharField(_("value"), max_length=256)
class Meta:

View File

@ -39,7 +39,7 @@ class AppType(plugins.Plugin):
@classmethod
@cached
def get_options(cls):
def get_group_options(cls):
""" Get enabled options based on cls.option_groups """
groups = AppOption.get_option_groups()
options = []
@ -52,11 +52,11 @@ class AppType(plugins.Plugin):
return options
@classmethod
def get_options_choices(cls):
def get_group_options_choices(cls):
""" Generates grouped choices ready to use in Field.choices """
# generators can not be @cached
yield (None, '-------')
for group, options in cls.get_options():
for group, options in cls.get_group_options():
if group is None:
for option in options:
yield (option.name, option.verbose_name)

View File

@ -59,10 +59,24 @@ class PHPApp(AppType):
def get_detail(self):
return self.instance.data.get('php_version', '')
@cached
def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
""" adapter to webapp.get_options that performs merging of PHP options """
kwargs = {
'webapp_id': self.instance.pk,
}
if merge:
kwargs = {
# webapp__type is not used because wordpress != php != symlink...
'webapp__account': self.instance.account_id,
'webapp__data__contains': '"php_version":"%s"' % self.instance.data['php_version'],
}
return self.instance.get_options(**kwargs)
def get_php_init_vars(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
""" Prepares PHP options for inclusion on php.ini """
init_vars = OrderedDict()
options = self.instance.get_options(merge=merge)
options = self.get_options(merge=merge)
php_version_number = float(self.get_php_version_number())
timeout = None
for name, value in options.items():