silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
719 stars 820 forks source link

Unable to disable dev tasks via static configuration #11103

Closed mfendeksilverstripe closed 6 months ago

mfendeksilverstripe commented 6 months ago

Unable to disable dev tasks via static configuration

Affected Version

4.13

Description

There is currently no option to disable a dev task via static configuration. The only option on how to disable a dev task is to use the $enabled which requires a code change to be made directly to the dev task. This is all good for the dev tasks within the project code but this approach isn't suitable for dev tasks that are provided by modules. Disabling such dev tasks is important to minimise errors as some module dev tasks can be quite dangerous if executed by accident.

Suggestion

Make this property static with the option of runtime override.

Before

/**
 * @var bool $enabled If set to FALSE, keep it from showing in the list
 * and from being executable through URL or CLI.
 */
protected $enabled = true;

/**
 * @return bool
 */
public function isEnabled()
{
    return $this->enabled;
}

After

/**
 * @var bool $enabled If set to FALSE, keep it from showing in the list
 * and from being executable through URL or CLI.
 */
private static bool $enabled = true;

public function isEnabled(): bool
{
    return $this->config()->get('enabled');
}

Workaround

One way hot to do this currently is to subclass every dev task that you want to disable and then disable it in your overriding task class.

GuySartorelli commented 6 months ago

This configuration option has been added in Silverstripe CMS 5.1.0.

Configuration properties are public API, so we can't introduce them in patch releases - and we're not doing any new minor releases for Silverstripe CMS 4, so this functionality won't be available in Silverstripe CMS 4.

mfendeksilverstripe commented 6 months ago

Nice, good to know :)