Class UpdaterBehavior
Behavior class with application updater/upgrader utilities.
Note to all future developers: it is important to bear in mind that if you need to make changes to the updates system or the updater in general, they must be backwards-compatible with all earlier versions of the software (or as far back as possible).
- CComponent
- CBehavior implements IBehavior
- ResponseBehavior
- UpdaterBehavior
Author: Demitri Morgan <demitri@x2engine.com>
Located at x2engine/protected/components/UpdaterBehavior.php
public static
|
#
classAliasPath( array $alias )
Converts an array formatted like a behavior or controller actions array entry and returns the path (relative to X2WebApplication.basePath to the class file. Yii::getPathOfAlias() is unsafe to use, because in cases where this function is to be used, the files may not exist yet. |
public
|
#
applyFiles( array $dir = null )
In the case of a failed update or other event, restore files from a backup location. |
public
boolean
|
#
backCompatHooks( mixed $latestUpdaterVersion )
Backwards compatibility hacks - I mean, hooks - to run after self-updating. |
public
|
|
public
|
#
checkFiles( )
Checks for the existence of an unpacked update package folder, and if present, whether all files are present and complete. |
public
|
|
public
boolean
|
#
checkIfCanSpawnChildren( type $throw = true )
Checks whether it is possible to run system commands using PHP's proc_open() function. |
public
boolean
|
#
checkIfChecksumsAvail( type $throw = true )
Checks if the package content digests file is present and not empty. |
public
|
#
checkIfDatabaseBackupExists( type $throw = true )
Checks to see if a file exists and isn't very old.. |
public
boolean|string
|
|
public
|
#
checkIfPackageApplies( mixed $throw = true )
Ensures that the package actually applies to the current version and edition. |
public
boolean
|
#
checkIfPackageExists( boolean $throw = true )
Check to see if there is an update package present in the filesystem. |
public
|
|
public
|
|
public
|
|
public
|
#
downloadPackage( type $version = null, type $uniqueId = null, type $edition = null )
Obtains update/upgrade data package from the server. |
public
boolean
|
#
downloadSourceFile( string $file, string $route = null, integer $maxAttempts = 5 )
Retrieves a file from the update server. It will be stored in a temporary directory, "tmp", in the web root. To copy it into the live install, use restoreBackup on target "tmp". |
public
|
#
enactChanges( array $autoRestore = false )
Finalizes an update/upgrade by applying file, database and configuration changes. |
public
|
#
handleSqlFailure( string $sql, boolean $sqlRun, mixed $sqlErr, mixed $backup, mixed $throw = true )
Handle database backups in the event of failure |
public
|
#
finalizeUpdate( mixed $scenario, mixed $unique_id, mixed $version, mixed $edition )
Notify the server that the update has finished |
public
type
|
|
public
string
|
|
public
array
|
#
getChecksums( )
Parse output formatted according to that of md5sum into an array of hashes indexed by filename. If no output is specified, the update package's content digest will be used as input. |
public
|
|
public
array
|
#
getCompatibilityStatus( )
Checks the current X2Engine installation for compatibility issues with the current package as defined in the manifest and requirements check script. |
public
array
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
array
|
|
public
string
|
#
getEdition( )
Backwards-compatible function for obtaining the edition of the installation. Attempts to not fail and return a valid value even if the application singleton doesn't store the information. |
public
array
|
#
getFiles( )
Obtains the list of files and their statuses (essentially a wrapper function
for |
public
array
|
#
getFilesByStatus( )
Return an array of arrays of files each indexed by the status (present, corrupt or missing) of those sets of files. |
public
array
|
|
public
string
|
|
public
|
|
public
|
|
public
boolean
|
|
public
type
|
|
public
|
|
public
|
|
public
string
|
|
public
string
|
#
getSourceFileRoute( type $edition = null, type $uniqueId = null )
Auto-construct a relative base URL on the updates server from which to retrieve source files. |
public
string
|
|
public
type
|
#
getUniqueId( )
Backwards-compatible function for obtaining the unique id. Very similar to getEdition in regard to its backwards compatibility. |
public
array
|
#
getUpdateData( string $version = null, string $uniqueId = null, string $edition = null )
Retrieves update data from the server. For previewing an update before downloading it; this essentially retrieves the manifest without retrieving the full package. |
public
string
|
#
getUpdateDataRoute( string $version = null, string $uniqueId = null, string $edition = null )
Gets a relative URL on the update server from which to obtain update data |
public
|
|
public
|
|
public
|
|
public
|
|
public
string
|
|
public
array
|
#
getWebUpdaterActions( boolean $getter = true )
Returns the actions associated with the web-based updater. |
public
boolean
|
|
public
boolean
|
#
regenerateConfig( type $newversion = Null, type $newupdaterVersion = Null, type $newbuildDate = null, string $newAppName = null )
Rebuilds the configuration file and performs the final few little update tasks. |
public
|
|
public
|
|
public
|
#
renderCompatibilityMessages( string $h = "h3", string $htmlOptions = array() )
Generates user-friendly messages for letting users know about update compatibility issues. |
public
|
#
requireDependencies( )
Checks whether all dependencies of the updater exist on the server, and downloads any that don't. |
public
|
|
public
boolean
|
|
public
|
|
public
|
#
setChecksums( string $value )
Set the checksum contents to a specific value. Resets _checksumsContent; it no longer is applicable. |
public
|
|
public
|
#
setConfigPermissions( type $value )
Magic setter that changes the file permissions of sensitive files in protected/config |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
array
|
detach(),
events(),
getEnabled(),
getOwner(),
setEnabled()
|
__call(),
__get(),
__isset(),
__set(),
__unset(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
hasProperty(),
raiseEvent()
|
string |
BAKFILE
|
'update_backup.sql' |
#
SQL backup dump file |
string |
LOCKFILE
|
'app_update.lock' |
#
Defines a file that (for extra security) prevents race conditions in the unlikely event that multiple requests to the web updater to enact file/database changes are made. |
string |
PKGFILE
|
'update.zip' |
|
string |
TMP_DIR
|
'tmp' |
|
string |
ERRFILE
|
'update_db_restore.err' |
|
string |
LOGFILE
|
'update_db_restore.log' |
|
string |
BCOFILE
|
'backcompat.run' |
|
string |
UPDATE_DIR
|
'update' |
|
string |
SECURITY_IMG
|
'cG93ZXJlZF9ieV94MmVuZ2luZS5wbmc=' |
|
integer |
ERR_ISLOCKED
|
1 |
|
integer |
ERR_CHECKSUM
|
2 |
|
integer |
ERR_MANIFEST
|
3 |
|
integer |
ERR_NOUPDATE
|
4 |
|
integer |
ERR_FILELIST
|
5 |
|
integer |
ERR_NOTAPPLY
|
6 |
|
integer |
ERR_UPSERVER
|
7 |
|
integer |
ERR_DBNOBACK
|
8 |
|
integer |
ERR_DBOLDBAK
|
9 |
|
integer |
ERR_SCENARIO
|
10 |
|
integer |
ERR_NOPROCOP
|
11 |
|
integer |
ERR_DATABASE
|
12 |
|
integer |
FILE_PRESENT
|
0 |
|
integer |
FILE_CORRUPT
|
1 |
|
integer |
FILE_MISSING
|
2 |
public static
string
|
$configFilename | 'X2Config.php' |
#
Core configuration file name. |
public static
array
|
$_configVarNames | array(
'appName',
'email',
'host',
'user',
'pass',
'dbname',
'version',
'buildDate',
'updaterVersion',
'language',
) |
#
Configuration file variables as [variable name] => [value quote wrap] as can be found in the file protected/config/X2Config.php |
public static
string
|
$_logCategory | 'application.updater' |
#
Explicit override of default ResponseBehavior::$_logCategory |
public
array
|
$updaterFiles | array(
"views/admin/updater.php",
"components/UpdaterBehavior.php",
"components/util/FileUtil.php",
"components/util/EncryptUtil.php",
"components/util/ResponseUtil.php",
"components/ResponseBehavior.php",
"components/views/requirements.php",
"commands/UpdateCommand.php"
) |
#
List of files used by the behavior |
$handleErrors,
$handleExceptions
|
public
string
|
$backCompatFile |
#
Path to the backwards compatibility flag file. |
public
array
|
$checksums |
#
When running an update, this is a list of all MD5 hashes of files to be applied, with filenames their keys and checksums their values. |
public
string
|
$checksumsContent |
#
The contents of the package contents digest file. |
public
array
|
$compatibilityStatus |
#
An array specifying compatibility issues. |
public
array
|
$configVars |
#
(read-only) variables imported from the configuration |
public
string
|
$dbBackupCommand |
#
(read-only) command to be used for backing up the database |
public
string
|
$dbBackupPath |
#
(read-only) Full path to the database backup file. |
public
string
|
$dbCommand |
#
(read-only) command to be used for running SQL from files |
public
array
|
$dbParams |
#
(read-only) Database information retrieved from CDbConnection |
public
string
|
$edition |
#
(read-only) The edition of the installation of X2Engine. |
public
array
|
$files |
#
(read-only) A list of files and their statuses (present, missing or corrupt). |
public
array
|
$filesByStatus |
#
(read-only) An array of files in each status category |
public
array
|
$filesStatus |
#
(read-only) A summary (showing counts) of all files' statuses. |
public
string
|
$latestUpdaterVersion |
#
(read-only) The latest version of the updater utility according to the updates server |
public
string
|
$lockFile |
#
Path to the file to use for locking when applying changes |
public
array
|
$manifest |
#
When running an update, this is the change manifest as retrieved from the update package |
public
boolean
|
$noHalt |
#
Whether to terminate the PHP process if errors occur |
public
PDO
|
$pdo |
#
(read-only) The app's PDO instance |
public
array
|
$requirements |
#
(read-only) Requirements script output. |
public
string
|
$scenario |
#
Usage scenario, i.e. update/upgrade |
public
string
|
$sourceDir |
#
(read-only) Absolute path to the base directory of source files to be applied in the update/upgrade |
public
string
|
$sourceFileRoute |
#
(read-only) Route (relative URL on the updates server) from which to download source files in a pinch |
public
string
|
$thisPath |
#
(read-only) Absolute path to the current working directory |
public
string
|
$uniqueId |
#
(read-only) Unique ID of the installation |
public
string
|
$updateDataRoute |
#
(read-only) Relative URL (to the base URL of the update server) from which to get update manifests. |
public
string
|
$updateDir |
#
(read-only) the directory of updates. |
public
string
|
$updatePackage |
#
(read-only) destination path for the update package. |
public
string
|
$updateServer |
#
Base URL of the web server from which to fetch data and files |
public
string
|
$version |
#
Version of X2Engine |
public
string
|
$webRoot |
#
(read-only) Absolute path to the web root, even if not in a web request |
public
array
|
$webUpdaterActions |
#
(read-only) array of actions in the web-based updater utility. |
$exitNonFatal,
$isConsole,
$logCategory,
$longErrorTrace,
$response,
$shutdown
|
$enabled,
$owner
|