Skip to content

ResaveController ​

Type
Class
Namespace
craft\console\controllers
Inherits
craft\console\controllers\ResaveController » craft\console\Controller » yii\console\Controller » yii\base\Controller » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable, yii\base\ViewContextInterface
Uses traits
craft\console\ControllerTrait
Since
3.1.15

Allows you to bulk-save elements.

See Bulk-Resaving Elements for examples.

View source

Public Properties ​

PropertyDescription
actionyii\base\Action, null – The action that is currently being executed.
behaviorsyii\base\Behavior – List of behaviors attached to this component.
colorboolean, null – Whether to enable ANSI color in the output.
defaultActionstring – The ID of the action that is used when the action ID is not specified in the request.
draftsboolean – Whether to resave element drafts.
elementIdinteger, string – The ID(s) of the elements to resave.
fieldstring, null – The field handle to save Matrix blocks for.
groupstring, null – The group handle(s) to save categories/tags/users from.
helpboolean – Whether to display help information about current command.
helpSummarystring
idstring – The ID of this controller.
ifEmptyboolean – Whether the --set attribute should only be set if it doesn’t have a value.
interactiveboolean – Whether to run the command interactively.
layoutstring, null, false – The name of the layout to be applied to this controller's views.
limitinteger, null – The number of elements to resave.
moduleyii\base\Module – The module that this controller belongs to.
modulesyii\base\Module – All ancestor modules that this controller is located within.
offsetinteger, null – The number of elements to skip.
passedOptionValuesarray – The properties corresponding to the passed options.
passedOptionsarray – The names of the options passed during execution.
provisionalDraftsboolean – Whether to resave provisional element drafts.
queueboolean – Whether the elements should be resaved via a queue job.
requestcraft\console\Request
responseyii\base\Response, array, string – The response.
revisionsboolean – Whether to resave element revisions.
routestring – The route (module ID, controller ID and action ID) of the current request.
sectionstring, null – The section handle(s) to save entries from.
setstring, null – An attribute name that should be set for each of the elements.
silentExitOnExceptionboolean, null – If true - script finish with ExitCode::OK in case of exception.
sitestring, null – The site handle to save elements from.
statusstring – The status(es) of elements to resave.
tostring, null – The value that should be set on the --set attribute.
touchboolean – Whether to update the dateUpdated timestamp for the elements.
typestring, null – The type handle(s) of the elements to resave.
uidstring – The UUID(s) of the elements to resave.
uniqueIdstring – The controller ID that is prefixed with the module ID (if any).
updateSearchIndexboolean – Whether to update the search indexes for the resaved elements.
viewyii\base\View, yii\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.
volumestring, null – The volume handle(s) to save assets from.

drafts ​

Type
boolean
Default value
false
Since
3.6.5

Whether to resave element drafts.

View source

elementId ​

Type
integer, string
Default value
null

The ID(s) of the elements to resave.

View source

field ​

Type
string, null
Default value
null

The field handle to save Matrix blocks for.

View source

group ​

Type
string, null
Default value
null

The group handle(s) to save categories/tags/users from. Can be set to multiple comma-separated groups.

View source

ifEmpty ​

Type
boolean
Default value
false
Since
3.7.29

Whether the --set attribute should only be set if it doesn’t have a value.

View source

limit ​

Type
integer, null
Default value
null

The number of elements to resave.

View source

offset ​

Type
integer, null
Default value
null

The number of elements to skip.

View source

provisionalDrafts ​

Type
boolean
Default value
false
Since
3.7.0

Whether to resave provisional element drafts.

View source

queue ​

Type
boolean
Default value
false
Since
3.7.0

Whether the elements should be resaved via a queue job.

View source

revisions ​

Type
boolean
Default value
false
Since
3.7.35

Whether to resave element revisions.

View source

section ​

Type
string, null
Default value
null

The section handle(s) to save entries from. Can be set to multiple comma-separated sections.

View source

set ​

Type
string, null
Default value
null
Since
3.7.29

An attribute name that should be set for each of the elements. The value will be determined by --to.

View source

site ​

Type
string, null
Default value
null

The site handle to save elements from.

View source

status ​

Type
string
Default value
'any'

The status(es) of elements to resave. Can be set to multiple comma-separated statuses.

View source

to ​

Type
string, null
Default value
null
Since
3.7.29

The value that should be set on the --set attribute.

The following value types are supported:

  • An attribute name: --to myCustomField
  • An object template: --to "={myCustomField|lower}"
  • A raw value: --to "=foo bar"
  • A PHP arrow function: --to "fn(\$element) => \$element->callSomething()"
  • An empty value: --to :empty:

View source

touch ​

Type
boolean
Default value
false
Since
3.7.54

Whether to update the dateUpdated timestamp for the elements.

View source

type ​

Type
string, null
Default value
null
Since
3.1.16

The type handle(s) of the elements to resave.

View source

uid ​

Type
string
Default value
null

The UUID(s) of the elements to resave.

View source

updateSearchIndex ​

Type
boolean
Default value
false

Whether to update the search indexes for the resaved elements.

View source

volume ​

Type
string, null
Default value
null

The volume handle(s) to save assets from. Can be set to multiple comma-separated volumes.

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.
actionAssets()Re-saves assets.
actionCategories()Re-saves categories.
actionEntries()Re-saves entries.
actionMatrixBlocks()Re-saves Matrix blocks.
actionTags()Re-saves tags.
actionUsers()Re-saves users.
actions()Declares external actions for the controller.
afterAction()This method is invoked right after an action is executed.
ansiFormat()Formats a string with ANSI codes.
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.
confirm()Asks user to confirm by typing y or n.
createAction()Creates an action based on the given action ID.
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.
getActionArgsHelp()Returns the help information for the anonymous arguments for the action.
getActionHelp()Returns the detailed help information for the specified action.
getActionHelpSummary()Returns a one-line short summary describing the specified action.
getActionOptionsHelp()Returns the help information for the options for the action.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getHelp()Returns help information for this controller.
getHelpSummary()Returns one-line short summary describing this controller.
getModules()Returns all ancestor modules of this controller.
getOptionValues()Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties.
getPassedOptionValues()Returns the properties corresponding to the passed options.
getPassedOptions()Returns the names of valid options passed during execution.
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.
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.
isColorEnabled()Returns a value indicating whether ANSI color is enabled.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
optionAliases()Returns option alias names.
options()Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.
passwordPrompt()Prompts the user for a password and validates it.
prompt()Prompts the user for input and validates it.
render()Renders a view and applies layout if available.
renderContent()Renders a static string by applying a layout.
renderFile()Renders a view file.
renderPartial()Renders a view without applying layout.
resaveElements()
run()Runs a request specified in terms of a route.
runAction()Runs an action with the specified action ID and parameters.
saveElements()
select()Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
setView()Sets the view object to be used by this controller.
setViewPath()Sets the directory that contains the view files.
stderr()Prints a string to STDERR.
stdout()Prints a string to STDOUT.
table()Outputs a table via craft\helpers\Console::table().
trigger()Triggers an event.

actionAssets() ​

Re-saves assets.

View source

Returns ​

integer

actionCategories() ​

Re-saves categories.

View source

Returns ​

integer

actionEntries() ​

Re-saves entries.

View source

Returns ​

integer

actionMatrixBlocks() ​

Since
3.2.0

Re-saves Matrix blocks.

You must supply the --field or --element-id argument for this to work properly.

View source

Returns ​

integer

actionTags() ​

Re-saves tags.

View source

Returns ​

integer

actionUsers() ​

Re-saves users.

View source

Returns ​

integer

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)
{
    // 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.

options() ​

Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available until beforeAction() is being called.

View source

Arguments ​

  • $actionID (string) – The action id of the current request

Returns ​

string[] – The names of the options valid for the action

resaveElements() ​

Since
3.7.0

View source

Arguments ​

  • $elementType (string, craft\base\ElementInterface) – The element type that should be resaved
  • $criteria (array) – The element criteria that determines which elements should be resaved

Returns ​

integer

saveElements() ​

DEPRECATED

Deprecated in 3.7.0. Use resaveElements() instead.

Since
3.2.0

View source

Arguments ​

Returns ​

integer

Protected Methods ​

MethodDescription
bindInjectedParams()Fills parameters based on types and names in action method signature.
checkRootUser()Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.
checkTty()Sets yii\console\Controller::$interactive to false if this isn’t a TTY shell.
createAttributeValidator()Creates a function for the validator option of Controller::prompt.
defineActions()Returns an array of custom actions that should be available on the controller.
getActionMethodReflection()
outputCommand()
parseDocCommentDetail()Returns full description from the docblock.
parseDocCommentSummary()Returns the first line of docblock.
parseDocCommentTags()Parses the comment block into tags.

Constants ​

ConstantDescription
EXIT_CODE_ERROR
EXIT_CODE_NORMAL