Skip to content

BaseUpdaterController ​

Type
Abstract Class
Namespace
craft\controllers
Inherits
craft\controllers\BaseUpdaterController » craft\web\Controller » yii\web\Controller » yii\base\Controller » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable, yii\base\ViewContextInterface
Extended by
craft\controllers\ConfigSyncController, craft\controllers\UpdaterController, craft\controllers\pluginstore\InstallController, craft\controllers\pluginstore\RemoveController
Since
3.0.0

BaseUpdaterController provides the base class for Craft/plugin installation/updating/removal.

View source

Public Properties ​

PropertyDescription
actionyii\base\Action, null – The action that is currently being executed.
actionParamsarray – The parameters bound to the current action.
behaviorsyii\base\Behavior – List of behaviors attached to this component.
defaultActionstring – The ID of the action that is used when the action ID is not specified in the request.
enableCsrfValidationboolean – Whether to enable CSRF validation for the actions in this controller.
idstring – The ID of this controller.
layoutstring, null, false – The name of the layout to be applied to this controller's views.
moduleyii\base\Module – The module that this controller belongs to.
modulesyii\base\Module – All ancestor modules that this controller is located within.
requestcraft\web\Request
responsecraft\web\Response
routestring – The route (module ID, controller ID and action ID) of the current request.
uniqueIdstring – The controller ID that is prefixed with the module ID (if any).
viewcraft\web\View – The view object that can be used to render views or view files
viewPathstring – The directory containing the view files for this controller.

Protected Properties ​

PropertyDescription
allowAnonymousinteger, boolean, integer[], string[] – Whether this controller’s actions can be accessed anonymously.
dataarray – The data associated with the current update

allowAnonymous ​

Type
integer, boolean, integer[], string[]
Default value
self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE

Whether this controller’s actions can be accessed anonymously.

This can be set to any of the following:

  • false or self::ALLOW_ANONYMOUS_NEVER (default) – indicates that all controller actions should never be accessed anonymously
  • true or self::ALLOW_ANONYMOUS_LIVE – indicates that all controller actions can be accessed anonymously when the system is live
  • self::ALLOW_ANONYMOUS_OFFLINE – indicates that all controller actions can be accessed anonymously when the system is offline
  • self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE – indicates that all controller actions can be accessed anonymously when the system is live or offline
  • An array of action IDs (e.g. ['save-guest-entry', 'edit-guest-entry']) – indicates that the listed action IDs can be accessed anonymously when the system is live
  • An array of action ID/bitwise pairs (e.g. ['save-guest-entry' => self::ALLOW_ANONYMOUS_OFFLINE] – indicates that the listed action IDs can be accessed anonymously per the bitwise int assigned to it.

View source

data ​

Type
array
Default value
[]

The data associated with the current update

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
actionComposerInstall()Installs Composer dependencies.
actionComposerRemove()Removes Composer dependencies.
actionFinish()Finishes the update process.
actionIndex()Kicks off the update.
actionPrecheck()Ensures that PHP’s memory_limit and max_execution_time settings are high enough to run Composer.
actionRecheckComposer()Rechecks for composer.json, if it couldn't be found in the initial state.
actions()Declares external actions for the controller.
afterAction()This method is invoked right after an action is executed.
asCpModal()Sends a control panel modal response.
asCpScreen()Sends a control panel screen response.
asErrorJson()Responds to the request with a JSON error message.
asFailure()Sends a failure response.
asJson()Send data formatted as JSON.
asJsonP()Sets the response format of the given data as JSONP.
asModelFailure()Sends a failure response for a model.
asModelSuccess()Sends a success response for a model.
asRaw()Sets the response format of the given data as RAW.
asSuccess()Sends a success response.
asXml()Send data formatted as XML.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
beforeAction()This method is invoked right before an action is executed.
behaviors()Returns a list of behaviors that this component should behave as.
bindActionParams()Binds the parameters to the action.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
createAction()Creates an action based on the given action ID.
currentUser()Returns the currently logged-in user.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
findLayoutFile()Finds the applicable layout file.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getModules()Returns all ancestor modules of this controller.
getRoute()Returns the route of the current request.
getUniqueId()Returns the unique ID of the controller.
getView()Returns the view object that can be used to render views or view files
getViewPath()Returns the directory containing view files for this controller.
goBack()Redirects the browser to the last visited page.
goHome()Redirects the browser to the home page.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
redirect()Redirects the browser to the specified URL.
redirectToPostedUrl()Redirects to the URI specified in the POST.
refresh()Refreshes the current page.
render()Renders a view and applies layout if available.
renderAjax()Renders a view in response to an AJAX request.
renderContent()Renders a static string by applying a layout.
renderFile()Renders a view file.
renderPartial()Renders a view without applying layout.
renderTemplate()Sends a rendered template response.
requireAcceptsJson()Throws a 400 error if the request doesn't accept JSON.
requireAdmin()Throws a 403 error if the current user is not an admin.
requireAuthorization()Checks whether the current user can perform a given action, and ends the request with a 403 error if they don’t.
requireCpRequest()Throws a 400 error if the current request isn’t a control panel request.
requireElevatedSession()Requires that the user has an elevated session.
requireGuest()Redirects the user to the account template if they are logged in.
requireLogin()Redirects the user to the login template if they're not logged in.
requirePermission()Checks whether the current user has a given permission, and ends the request with a 403 error if they don’t.
requirePostRequest()Throws a 400 error if this isn’t a POST request
requireSiteRequest()Throws a 400 error if the current request isn’t a site request.
requireToken()Throws a 400 error if the current request doesn’t have a valid Craft token.
run()Runs a request specified in terms of a route.
runAction()Runs an action within this controller with the specified action ID and parameters.
setFailFlash()Sets an error flash message on the user session.
setSuccessFlash()Sets a success flash message on the user session.
setView()Sets the view object to be used by this controller.
setViewPath()Sets the directory that contains the view files.
trigger()Triggers an event.

actionComposerInstall() ​

Installs Composer dependencies.

View source

Returns ​

yii\web\Response

actionComposerRemove() ​

Removes Composer dependencies.

View source

Returns ​

yii\web\Response

actionFinish() ​

Finishes the update process.

View source

Returns ​

yii\web\Response

actionIndex() ​

Kicks off the update.

View source

Returns ​

yii\web\Response

Throws ​

actionPrecheck() ​

Ensures that PHP’s memory_limit and max_execution_time settings are high enough to run Composer.

View source

Returns ​

yii\web\Response

actionRecheckComposer() ​

Rechecks for composer.json, if it couldn't be found in the initial state.

View source

Returns ​

yii\web\Response

beforeAction() ​

This method is invoked right before an action is executed.

The method will trigger the EVENT_BEFORE_ACTION event. The return value of the method will determine whether the action should continue to run.

In case the action should not run, the request should be handled inside of the beforeAction code by either providing the necessary output or redirecting the request. Otherwise the response will be empty.

If you override this method, your code should look like the following:

php
public function beforeAction($action): bool
{
    // your custom code here, if you want the code to run before action filters,
    // which are triggered on the [EVENT_BEFORE_ACTION](https://www.yiiframework.com/doc/api/2.0/yii-base-controller#EVENT_BEFORE_ACTION-detail) event, e.g. PageCache or AccessControl

    if (!parent::beforeAction($action)) {
        return false;
    }

    // other custom code here

    return true; // or false to not run the action
}

View source

Arguments ​

Returns ​

boolean – Whether the action should continue to run.

Throws ​

Protected Methods ​

MethodDescription
actionOption()Returns an option definition that kicks off a new action.
actionState()Sets the state info for the given next action.
actionStatus()Returns the status message for the given action.
bindInjectedParams()Fills parameters based on types and names in action method signature.
defineBehaviors()Returns the behaviors to attach to this class.
ensureComposerJson()Ensures that composer.json can be found.
findReturnUrl()Returns the return URL provided by the return body param, if it’s a valid URL.
finishedState()Sets the state info for when the job is done.
getPostedRedirectUrl()Gets the redirect param specified in the POST data.
initialData()Returns the initial data.
initialState()Returns the initial state for the updater JS.
installPlugin()Attempts to install a plugin by its handle.
noComposerJsonState()Returns the initial state if composer.json couldn't be found.
pageTitle()Returns the page title
postComposerInstallState()Returns the state data for after actionComposerInstall() is done.
realInitialState()Returns the real initial state for the updater JS.
returnUrl()Returns the return URL that should be passed with a finished state.
runMigrations()Runs the migrations for a given list of handles.
send()Sends a state response.
sendComposerError()Sends an "error" state response for a Composer error
sendFinished()Sends a "finished" state response.
sendNextAction()Sends a "next action" state response.

actionOption() ​

Returns an option definition that kicks off a new action.

View source

Arguments ​

Returns ​

array

actionState() ​

Sets the state info for the given next action.

View source

Arguments ​

Returns ​

array

actionStatus() ​

Returns the status message for the given action.

View source

Arguments ​

Returns ​

string

Throws ​

ensureComposerJson() ​

Ensures that composer.json can be found.

View source

Returns ​

boolean – Whether composer.json can be found

findReturnUrl() ​

Since
3.7.17

Returns the return URL provided by the return body param, if it’s a valid URL.

View source

Returns ​

string, null

Throws ​

finishedState() ​

Sets the state info for when the job is done.

View source

Arguments ​

Returns ​

array

initialData() ​

Returns the initial data.

View source

Returns ​

array

initialState() ​

Returns the initial state for the updater JS.

View source

Arguments ​

  • $force (boolean) – Whether to go through with the update even if Maintenance Mode is enabled

Returns ​

array

installPlugin() ​

Attempts to install a plugin by its handle.

View source

Arguments ​

Returns ​

array – Array with installation results

noComposerJsonState() ​

Returns the initial state if composer.json couldn't be found.

See also ensureComposerJson()View source

Returns ​

array

pageTitle() ​

Returns the page title

View source

Returns ​

string

postComposerInstallState() ​

Returns the state data for after actionComposerInstall() is done.

View source

Returns ​

array

realInitialState() ​

Returns the real initial state for the updater JS.

View source

Arguments ​

  • $force (boolean) – Whether to go through with the update even if Maintenance Mode is enabled

Returns ​

array

returnUrl() ​

Returns the return URL that should be passed with a finished state.

View source

Returns ​

string

runMigrations() ​

Runs the migrations for a given list of handles.

View source

Arguments ​

Returns ​

yii\web\Response, null

send() ​

Sends a state response.

View source

Arguments ​

Returns ​

yii\web\Response

sendComposerError() ​

Sends an "error" state response for a Composer error

View source

Arguments ​

  • $error (string) – The status message to show
  • $e (Throwable) – The exception that was thrown
  • $output (string) – The Composer output
  • $state (array)

Returns ​

yii\web\Response

sendFinished() ​

Sends a "finished" state response.

View source

Arguments ​

Returns ​

yii\web\Response

sendNextAction() ​

Sends a "next action" state response.

View source

Arguments ​

  • $nextAction (string) – The next action that should be run
  • $state (array)

Returns ​

yii\web\Response

Constants ​

ConstantDescription
ACTION_COMPOSER_INSTALL
ACTION_COMPOSER_REMOVE
ACTION_FINISH
ACTION_PRECHECK
ACTION_RECHECK_COMPOSER
ALLOW_ANONYMOUS_LIVE
ALLOW_ANONYMOUS_NEVER
ALLOW_ANONYMOUS_OFFLINE