This class can take care of handling upgrades that can not be achieved by a simple db patch. For example adding an extra attribute to all token tables in LimeSurvey needs a simple loop.

As these classes may need setting of values this subclass implements the checkRegistryRequestsAnswers() easy access to resources.

package Gems
subpackage Upgrades
copyright Copyright (c) 2011 Erasmus MC
license New BSD License
since Class available since version 1.5
inherited_from \Gems_Loader_TargetLoaderAbstract

 Methods

__construct()

__construct() 

__construct()

__construct(mixed $container, array $dirs) 
Inherited

Parameters

$container

mixed

A container acting as source for \MUtil_Registry_Source

$dirs

array

The directories where to look for requested classes

__get()

__get($name) 
Inherited

Parameters

$name

Add prefixed paths to the registry of paths

addPrefixPath(string $prefix, $path, boolean $prepend = true) : \Gems_Loader_LoaderAbstract
Inherited

Parameters

$prefix

string

$path

$prepend

boolean

Put path at the beginning of the stack (has no effect when prefix / dir already set)

Returns

\Gems_Loader_LoaderAbstract(continuation pattern)

Called after the check that all required registry values have been set correctly has run.

afterRegistry() : void
Inherited

Allows the loader to set resources.

answerRegistryRequest(string $name, mixed $resource) : boolean
Inherited

Parameters

$name

string

Name of resource to set

$resource

mixed

The resource.

Returns

booleanTrue if $resource was OK

Should be called after answering the request to allow the Target to check if all required registry values have been set correctly.

checkRegistryRequestsAnswers() : boolean
Inherited

Returns

booleanFalse if required values are missing.

Execute upgrades for the given $context

execute(string $context, integer|null $to = null, integer|null $from = null) : false | integer

When no $to or $from are given, the given $context will be upgraded from the current level to the max level. Otherwise the $from and/or $to will be used to determine what upgrades to execute.

Parameters

$context

string

The context to execute the upgrades for

$to

integernull

The level to upgrade to

$from

integernull

The level to start the upgrade on

Returns

falseintegerThe achieved upgrade level or false on failure

Retrieve the current context

getContext() : string

Returns

string

Get the current upgrade level for the given $context

getLevel(string $context) : integer

Parameters

$context

string

Returns

integer

Get the highest level for the given $context

getMaxLevel(string|null $context = null) : integer

Parameters

$context

stringnull

Returns

integer

Get all messages that were recorded during the upgrade process

getMessages() : array

Returns

array

Get the next level for a given level and context

getNextLevel(\type $context = null, \type $level = null) : \type

When context is null, it will get the current context When level is null, it will get the current level

Parameters

$context

\type

$level

\type

Returns

\type

Allows the loader to know the resources to set.

getRegistryRequests() : array
Inherited

Returns those object variables defined by the subclass but not at the level of this definition.

Can be overruled.

Returns

arrayof string names

Retrieve the upgrades for a certain context, will return an empty array when nothing present.

getUpgrades(string $context = null) : array

Parameters

$context

string

Returns

array

Retrieve info about the $requestedContext or all contexts when omitted

getUpgradesInfo(string $requestedContext = null) : array

Parameters

$requestedContext

string

Returns

array

Register an upgrade in the stack, it can be executed by using $this->execute

register(array|string $callback, string $info = null, integer $index = null, string $context = null) : boolean

Index and context are optional and will be generated when omitted. For the user interface to be clear $info should provide a good description of what the upgrade does.

Parameters

$callback

arraystring

A valid callback, either string for a method of the current class or array otherwise

$info

string

A descriptive message about what this upgrade does

$index

integer

The number of the upgrade

$context

string

The context to which this upgrade applies

Returns

boolean

Set the batch to use

setBatch(\Gems_Task_TaskRunnerBatch $batch) 

Parameters

$batch

\Gems_Task_TaskRunnerBatch

Change the active context

setContext(string $context) 

Usefull when adding upgrades in the construct to save typing

Parameters

$context

string

Proxy to the translate object

_(string $messageId, \type $locale = null) : string

Parameters

$messageId

string

$locale

\type

Returns

string

Add a subdirectory / sub name to a list of class load paths

_cascadedDirs(array $dirs, string $cascade, boolean $fullClassnameFallback = true) : array
Inherited

Parameters

$dirs

array

prefix => path

$cascade

string

The sub directories to cascade to

$fullClassnameFallback

boolean

Allows full class name specification instead of just plugin name part

Returns

arrayprefix => path

Returns $this->$name, creating the item if it does not yet exist.

_getClass(string $name, string $className = null, array $arguments = array()) : mixed
Inherited

Parameters

$name

string

The $name of the variable to store this object in.

$className

string

Class name or null if the same as $name, prepending $this->_dirs.

$arguments

array

Class initialization arguments.

Returns

mixedInstance of $className

Create or loads the class. When only loading, this function returns a StaticCall object that can be invoked lazely.

_loadClass(string $name, boolean $create = false, array $arguments = array()) : mixed
Inherited
see
see

Parameters

$name

string

The class name, minus the part in $this->_dirs.

$create

boolean

Create the object, or only when an \MUtil_Registry_TargetInterface instance.

$arguments

array

Class initialization arguments.

Returns

mixedA class instance or a \MUtil_Lazy_StaticCall object

Add a message to the stack

addMessage(string $message) 

Parameters

$message

string

Reset the message stack

clearMessages() 

Filters the names that should not be requested.

filterRequestNames(string $name) : boolean
Inherited

Can be overriden.

Parameters

$name

string

Returns

boolean

Set the upgrade level for the given $context to a certain level

setLevel(string $context, integer $level = null, boolean $force = false

Will only update when the $level is higher than the achieved level, unless when $force = true when it will always update.

Parameters

$context

string

$level

integer

$force

boolean

 Properties

 

$db

$db : \Zend_Db_Adapter_Abstract

Default

 

$loader

$loader : \Gems_Loader

Default

 

$project

$project : \Gems_Project_ProjectSettings

Default

 

$translate

$translate : \Zend_Translate_Adapter

Default

 

$_batch

$_batch : \Gems_Task_TaskRunnerBatch

Default

 

$_context

$_context 

Default

null
 

The prefix/path location to look for classes.

$_dirs : array

Default

The standard value is

  • => application/classes
  • Gems => library/Gems/classes

But an alternative could be:

  • Demopulse => application/classes
  • Pulse => application/classes
  • Gems => library/Gems/classes
 

$_info

$_info : \Zend_Config_Ini

Default

 

$_loader

$_loader : \MUtil_Loader_PluginLoader

Default

 

$_messages

$_messages 

Default

array()
 

$_upgradeStack

$_upgradeStack 

Default

array()
 

Allows sub classes of \Gems_Loader_LoaderAbstract to specify the subdirectory where to look for.

$cascade : string

Default

null
 

Holds the inital config file

$originalFile : \Zend_Config

Default

 

Holds the config file specific to this environment

$upgradeFile : \Zend_Config

Default