PHP Class yii2tech\selfupdate\SelfUpdateController

You can configure available version control systems via [[versionControlSystems]]. Note: in order to work properly this command requires execution of VCS command without any prompt or user input. Usage: 1. Create a configuration file using the config action: yii self-update/config @app/config/selfupdate.php 2. Edit the created config file, adjusting it for your project needs. 3. Run the 'perform' action, using created config: yii self-update @app/config/selfupdate.php
Since: 1.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\console\Controller
Exibir arquivo Open project: yii2tech/selfupdate

Public Properties

Property Type Description
$afterUpdateCommands list of shell commands, which should be executed after project update. If command is a string it will be executed as shell command, otherwise as PHP callback. For example: php [ 'php /path/to/project/yii migrate/up --interactive=0' ],
$beforeUpdateCommands list of commands, which should be executed before project update begins. If command is a string it will be executed as shell command, otherwise as PHP callback. For example: php [ 'mysqldump -h localhost -u root myproject > /path/to/backup/myproject.sql' ],
$cache list of cache application components, for which [[Cache::flush()]] method should be invoked. Component ids, instances or array configurations can be used here.
$composerBinPath path to the 'composer' bin command. By default simple 'composer' is used, assuming it available as global shell command. Path alias can be used here. For example: '@app/composer.phar'.
$composerOptions composer command options.
$composerRootPaths list of composer install root paths (the ones containing 'composer.json'). Path aliases can be used here.
$configFile configuration file name. Settings from this file will be merged with the default ones. Such configuration file can be created, using action 'config'. Path alias can be used here, for example: '@app/config/self-update.php'.
$defaultAction controller default action ID.
$emails list of email addresses, which should be used to send execution reports.
$mailer the mailer object or the application component ID of the mailer. It will be used to send notification messages to [[emails]]. If not set or sending email via this component fails, the fallback to the plain PHP mail() function will be used instead.
$mutex the mutex object or the application component ID of the mutex. After the controller object is created, if you want to change this property, you should only assign it with a mutex connection object.
$projectRootPath path to project root directory, which means VCS root directory. Path aliases can be use here.
$shellResponseErrorKeywords list of keywords, which presence in the shell command output is considered as its execution error.
$tmpDirectories list of temporary directories, which should be cleared after project update. Path aliases can be used here. For example: php [ '@app/web/assets', '@runtime/URI', '@runtime/HTML', '@runtime/debug', ]
$versionControlSystems list of possible version control systems (VCS) in format: vcsFolderName => classConfig. VCS will be detected automatically based on which folder is available inside [[projectRootPath]]
$webPaths project web path stubs configuration. Each path configuration should have following keys: - 'path' - string - path to web root folder - 'link' - string - path for the symbolic link, which should point to the web root - 'stub' - string - path to folder, which contains stub for the web Yii aliases can be used for all these keys. For example: php [ [ 'path' => '@app/web', 'link' => '@app/httpdocs', 'stub' => '@app/webstub', ] ]

Public Methods

Method Description
actionConfig ( string $fileName ) : integer Creates a configuration file for the "perform" command.
actionPerform ( string | null $configFile = null ) : integer Performs project update from VCS.
getCurrentDate ( ) : string
getHostName ( ) : string
getReportFrom ( ) : string
setHostName ( string $hostName )
setReportFrom ( string $reportFrom )

Protected Methods

Method Description
acquireMutex ( ) : boolean Acquires current action lock.
clearDirectory ( string $dir ) Clears specified directory.
clearTmpDirectories ( ) Clears all directories specified via [[tmpDirectories]].
composeMutexName ( ) : string Composes the mutex name.
detectVersionControlSystem ( string $path ) : yii2tech\selfupdate\VersionControlSystemInterface Detects version control system used for the project.
execShellCommand ( string $command, array $placeholders = [] ) : string Executes shell command.
executeCommands ( array $commands ) Executes list of given commands.
flushCache ( ) Flushes cache for all components specified at [[cache]].
flushLog ( ) : array Flushes log lines, returning them.
linkWebPaths ( ) Links web roots to the actual web directories.
linkWebStubs ( ) Links web roots to the stub directories.
log ( string $message ) Logs the message
normalizeWebPaths ( ) Normalizes [[webPaths]] value.
releaseMutex ( ) : boolean Release current action lock.
reportFail ( ) Sends report about failure.
reportResult ( string $subjectPrefix ) Sends execution report.
reportSuccess ( ) Sends report about success.
sendEmail ( string $from, string $email, string $subject, string $message ) : boolean Sends an email.
sendEmailFallback ( string $from, string $email, string $subject, string $message ) : boolean Sends an email via plain PHP mail() function.
updateVendor ( ) Performs vendors update via Composer at all [[composerRootPaths]].

Method Details

acquireMutex() protected method

Acquires current action lock.
protected acquireMutex ( ) : boolean
return boolean lock acquiring result.

actionConfig() public method

The generated configuration file contains detailed instructions on how to customize it to fit for your needs. After customization, you may use this configuration file with the "perform" command.
public actionConfig ( string $fileName ) : integer
$fileName string output file name or alias.
return integer CLI exit code

actionPerform() public method

Performs project update from VCS.
public actionPerform ( string | null $configFile = null ) : integer
$configFile string | null the path or alias of the configuration file. You may use the "config" command to generate this file and then customize it for your needs.
return integer CLI exit code

clearDirectory() protected method

Clears specified directory.
protected clearDirectory ( string $dir )
$dir string directory to be cleared.

clearTmpDirectories() protected method

Clears all directories specified via [[tmpDirectories]].
protected clearTmpDirectories ( )

composeMutexName() protected method

Composes the mutex name.
protected composeMutexName ( ) : string
return string mutex name.

detectVersionControlSystem() protected method

Detects version control system used for the project.
protected detectVersionControlSystem ( string $path ) : yii2tech\selfupdate\VersionControlSystemInterface
$path string project root path.
return yii2tech\selfupdate\VersionControlSystemInterface version control system instance.

execShellCommand() protected method

Executes shell command.
protected execShellCommand ( string $command, array $placeholders = [] ) : string
$command string command text.
$placeholders array placeholders to be replaced using `escapeshellarg()` in format: placeholder => value.
return string command output.

executeCommands() protected method

Executes list of given commands.
protected executeCommands ( array $commands )
$commands array commands to be executed.

flushCache() protected method

Flushes cache for all components specified at [[cache]].
protected flushCache ( )

flushLog() protected method

Flushes log lines, returning them.
protected flushLog ( ) : array
return array log lines.

getCurrentDate() public method

public getCurrentDate ( ) : string
return string current date string.

getHostName() public method

public getHostName ( ) : string
return string server hostname.

getReportFrom() public method

public getReportFrom ( ) : string
return string email address, which should be used to send report email messages.

linkWebPaths() protected method

Links web roots to the actual web directories.
See also: webPaths
protected linkWebPaths ( )

linkWebStubs() protected method

Links web roots to the stub directories.
See also: webPaths
protected linkWebStubs ( )

log() protected method

Logs the message
protected log ( string $message )
$message string log message.

normalizeWebPaths() protected method

Normalizes [[webPaths]] value.
protected normalizeWebPaths ( )

releaseMutex() protected method

Release current action lock.
protected releaseMutex ( ) : boolean
return boolean lock release result.

reportFail() protected method

Sends report about failure.
protected reportFail ( )

reportResult() protected method

Report message content will be composed from log messages.
protected reportResult ( string $subjectPrefix )
$subjectPrefix string report message subject.

reportSuccess() protected method

Sends report about success.
protected reportSuccess ( )

sendEmail() protected method

Sends an email.
protected sendEmail ( string $from, string $email, string $subject, string $message ) : boolean
$from string sender email address
$email string single email address
$subject string email subject
$message string email content
return boolean success.

sendEmailFallback() protected method

Sends an email via plain PHP mail() function.
protected sendEmailFallback ( string $from, string $email, string $subject, string $message ) : boolean
$from string sender email address
$email string single email address
$subject string email subject
$message string email content
return boolean success.

setHostName() public method

public setHostName ( string $hostName )
$hostName string server hostname.

setReportFrom() public method

public setReportFrom ( string $reportFrom )
$reportFrom string email address, which should be used to send report email messages.

updateVendor() protected method

Performs vendors update via Composer at all [[composerRootPaths]].
protected updateVendor ( )

Property Details

$afterUpdateCommands public_oe property

list of shell commands, which should be executed after project update. If command is a string it will be executed as shell command, otherwise as PHP callback. For example: php [ 'php /path/to/project/yii migrate/up --interactive=0' ],
public $afterUpdateCommands

$beforeUpdateCommands public_oe property

list of commands, which should be executed before project update begins. If command is a string it will be executed as shell command, otherwise as PHP callback. For example: php [ 'mysqldump -h localhost -u root myproject > /path/to/backup/myproject.sql' ],
public $beforeUpdateCommands

$cache public_oe property

list of cache application components, for which [[Cache::flush()]] method should be invoked. Component ids, instances or array configurations can be used here.
public $cache

$composerBinPath public_oe property

path to the 'composer' bin command. By default simple 'composer' is used, assuming it available as global shell command. Path alias can be used here. For example: '@app/composer.phar'.
public $composerBinPath

$composerOptions public_oe property

composer command options.
See also: Shell::buildOptions() for valid syntax on specifying this value. For example: ```php [ 'prefer-dist', 'no-dev', ] ``` Note, that `no-interaction` option will be added automatically to the options list.
Since: 1.0.2
public $composerOptions

$composerRootPaths public_oe property

list of composer install root paths (the ones containing 'composer.json'). Path aliases can be used here.
public $composerRootPaths

$configFile public_oe property

configuration file name. Settings from this file will be merged with the default ones. Such configuration file can be created, using action 'config'. Path alias can be used here, for example: '@app/config/self-update.php'.
public $configFile

$defaultAction public_oe property

controller default action ID.
public $defaultAction

$emails public_oe property

list of email addresses, which should be used to send execution reports.
public $emails

$mailer public_oe property

the mailer object or the application component ID of the mailer. It will be used to send notification messages to [[emails]]. If not set or sending email via this component fails, the fallback to the plain PHP mail() function will be used instead.
public $mailer

$mutex public_oe property

the mutex object or the application component ID of the mutex. After the controller object is created, if you want to change this property, you should only assign it with a mutex connection object.
public $mutex

$projectRootPath public_oe property

path to project root directory, which means VCS root directory. Path aliases can be use here.
public $projectRootPath

$shellResponseErrorKeywords public_oe property

list of keywords, which presence in the shell command output is considered as its execution error.
public $shellResponseErrorKeywords

$tmpDirectories public_oe property

list of temporary directories, which should be cleared after project update. Path aliases can be used here. For example: php [ '@app/web/assets', '@runtime/URI', '@runtime/HTML', '@runtime/debug', ]
public $tmpDirectories

$versionControlSystems public_oe property

list of possible version control systems (VCS) in format: vcsFolderName => classConfig. VCS will be detected automatically based on which folder is available inside [[projectRootPath]]
public $versionControlSystems

$webPaths public_oe property

project web path stubs configuration. Each path configuration should have following keys: - 'path' - string - path to web root folder - 'link' - string - path for the symbolic link, which should point to the web root - 'stub' - string - path to folder, which contains stub for the web Yii aliases can be used for all these keys. For example: php [ [ 'path' => '@app/web', 'link' => '@app/httpdocs', 'stub' => '@app/webstub', ] ]
public $webPaths