00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class eZPackageInstallationHandler
00042 {
00043
00044
00045
00046 function eZPackageInstallationHandler( &$package, $type, $installItem, $name = null, $steps = null )
00047 {
00048 $this->Package = $package;
00049 $this->Attributes = array( 'type' => $type,
00050 'name' => $name,
00051 'steps' => $steps,
00052 'step_map' => false,
00053 'current_steps' => $steps );
00054 $this->InitializeStepMethodMap = array();
00055 $this->ValidateStepMethodMap = array();
00056 $this->CommitStepMethodMap = array();
00057 $this->InstallItem = $installItem;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067 function generateStepMap( &$package, &$persistentData )
00068 {
00069 $steps = $this->attribute( 'steps' );
00070 $map = array();
00071 $lastStep = false;
00072 $currentSteps = array();
00073 for ( $i = 0; $i < count( $steps ); ++$i )
00074 {
00075 $step =& $steps[$i];
00076 if ( !isset( $step['previous_step'] ) )
00077 {
00078 if ( $lastStep )
00079 $step['previous_step'] = $lastStep['id'];
00080 else
00081 $step['previous_step'] = false;
00082 }
00083 if ( !isset( $step['next_step'] ) )
00084 {
00085 if ( $i + 1 < count( $steps ) )
00086 $step['next_step'] = $steps[$i+1]['id'];
00087 else
00088 $step['next_step'] = false;
00089 }
00090 if ( isset( $step['methods']['initialize'] ) )
00091 $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
00092 if ( isset( $step['methods']['validate'] ) )
00093 $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
00094 if ( isset( $step['methods']['commit'] ) )
00095 $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
00096 $isStepIncluded = true;
00097 if ( isset( $step['methods']['check'] ) )
00098 {
00099 $checkMethod = $step['methods']['check'];
00100 $isStepIncluded = $this->$checkMethod( $package, $persistentData );
00101 }
00102 if ( $isStepIncluded )
00103 {
00104 $map[$step['id']] =& $step;
00105 $lastStep =& $step;
00106 $currentSteps[] =& $step;
00107 }
00108 }
00109 $this->StepMap = array( 'first' => &$steps[0],
00110 'map' => &$map,
00111 'steps' => &$steps );
00112 $this->Attributes['step_map'] =& $this->StepMap;
00113 $this->Attributes['current_steps'] = $currentSteps;
00114 }
00115
00116 function attributes()
00117 {
00118 return array_keys( $this->Attributes );
00119 }
00120
00121 function hasAttribute( $name )
00122 {
00123 return array_key_exists( $name, $this->Attributes );
00124 }
00125
00126 function &attribute( $name )
00127 {
00128 if ( array_key_exists( $name, $this->Attributes ) )
00129 return $this->Attributes[$name];
00130 {
00131 eZDebug::writeError( "Attribute '$name' does not exist", 'eZPackageInstallationHandler::attribute' );
00132 $retValue = null;
00133 return $retValue;
00134 }
00135 }
00136
00137 function initializeStepMethodMap()
00138 {
00139 return $this->InitializeStepMethodMap;
00140 }
00141
00142 function validateStepMethodMap()
00143 {
00144 return $this->ValidateStepMethodMap;
00145 }
00146
00147 function commitStepMethodMap()
00148 {
00149 return $this->CommitStepMethodMap;
00150 }
00151
00152
00153
00154
00155
00156 function &stepMap()
00157 {
00158 return $this->StepMap;
00159 }
00160
00161
00162
00163
00164 function stepTemplate( $package, $installItem, $step )
00165 {
00166 $stepTemplatePath = 'design:package/';
00167 $stepTemplateName = $step['template'];
00168 if ( isset( $step['use_standard_template'] ) and
00169 $step['use_standard_template'] )
00170 $stepTemplatePath .= "create";
00171 else
00172 $stepTemplatePath .= "installers/" . $this->attribute( 'type' );
00173 return array( 'name' => $stepTemplateName,
00174 'path' => $stepTemplatePath );
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 function initializeStep( &$package, &$http, $step, &$persistentData, &$tpl, &$module )
00184 {
00185 $methodMap = $this->initializeStepMethodMap();
00186 if ( count( $methodMap ) > 0 )
00187 {
00188 if ( isset( $methodMap[$step['id']] ) )
00189 {
00190 $method = $methodMap[$step['id']];
00191 return $this->$method( $package, $http, $step, $persistentData, $tpl, $module );
00192 }
00193 }
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 function validateStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00205 {
00206 $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
00207 if ( $nextStep === true )
00208 {
00209 if ( !isset( $stepMap['map'][$currentStepID] ) )
00210 {
00211 $nextStep = $stepMap['first']['id'];
00212 }
00213 else
00214 {
00215 $currentStep =& $stepMap['map'][$currentStepID];
00216 $nextStep = $currentStep['next_step'];
00217 }
00218 }
00219 else if ( $nextStep === false )
00220 $nextStep = $currentStepID;
00221 return $nextStep;
00222 }
00223
00224
00225
00226
00227 function validateAndAdvanceStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00228 {
00229 $methodMap = $this->validateStepMethodMap();
00230 if ( count( $methodMap ) > 0 )
00231 {
00232 if ( isset( $methodMap[$currentStepID] ) )
00233 {
00234 $method = $methodMap[$currentStepID];
00235 return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
00236 }
00237 }
00238 return true;
00239 }
00240
00241
00242
00243
00244
00245
00246 function commitStep( &$package, &$http, $step, &$persistentData, &$tpl )
00247 {
00248 $methodMap = $this->commitStepMethodMap();
00249 if ( count( $methodMap ) > 0 )
00250 {
00251 if ( isset( $methodMap[$step['id']] ) )
00252 {
00253 $method = $methodMap[$step['id']];
00254 return $this->$method( $package, $http, $step, $persistentData, $tpl );
00255 }
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264
00265 function finalize( &$package, &$http, &$persistentData )
00266 {
00267 }
00268
00269
00270
00271
00272
00273
00274
00275 function &instance( &$package, $handlerName, $installItem )
00276 {
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 $handlers =& $GLOBALS['eZPackageCreationInstallers'];
00287 if ( !isset( $handlers ) )
00288 $handlers = array();
00289 $handler = false;
00290 include_once( 'lib/ezutils/classes/ezextension.php' );
00291 if ( eZExtension::findExtensionType( array( 'ini-name' => 'package.ini',
00292 'repository-group' => 'PackageSettings',
00293 'repository-variable' => 'RepositoryDirectories',
00294 'extension-group' => 'PackageSettings',
00295 'extension-variable' => 'ExtensionDirectories',
00296 'subdir' => 'packageinstallers',
00297 'extension-subdir' => 'packageinstallers',
00298 'suffix-name' => 'packageinstaller.php',
00299 'type-directory' => true,
00300 'type' => $handlerName,
00301 'alias-group' => 'InstallerSettings',
00302 'alias-variable' => 'HandlerAlias' ),
00303 $result ) )
00304 {
00305 $handlerFile = $result['found-file-path'];
00306 if ( file_exists( $handlerFile ) )
00307 {
00308 include_once( $handlerFile );
00309 $handlerClassName = $result['type'] . 'PackageInstaller';
00310
00311 if ( isset( $handlers[$result['type']] ) )
00312 {
00313 $handler =& $handlers[$result['type']];
00314 $handler->reset();
00315 }
00316 else
00317 {
00318 $handler =& new $handlerClassName( $package, $handlerName, $installItem );
00319 $handlers[$result['type']] =& $handler;
00320 }
00321
00322
00323 $customInstallHandler = $handler->customInstallHandlerInfo( $package, $installItem );
00324 if ( $customInstallHandler )
00325 {
00326 unset( $handler );
00327 $handlerClassName = $customInstallHandler['classname'];
00328 $handlerFile = $customInstallHandler['file-path'];
00329
00330 include_once( $handlerFile );
00331 $handler =& new $handlerClassName( $package, $handlerName, $installItem );
00332 }
00333 }
00334 }
00335 return $handler;
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 function packageType( &$package, &$persistentData )
00348 {
00349 if ( get_class( $package ) == 'ezpackage' )
00350 {
00351 return $package->attribute( 'type' );
00352 }
00353 return false;
00354 }
00355
00356
00357
00358
00359
00360 function rootDOMNode()
00361 {
00362 if ( !isset( $this->InstallItem['content'] ) || !$this->InstallItem['content'] )
00363 {
00364 $filename = $this->InstallItem['filename'];
00365 $subdirectory = $this->InstallItem['sub-directory'];
00366 if ( $subdirectory )
00367 $filepath = $subdirectory . '/' . $filename . '.xml';
00368 else
00369 $filepath = $filename . '.xml';
00370
00371 $filepath = $this->Package->path() . '/' . $filepath;
00372
00373 $dom =& $this->Package->fetchDOMFromFile( $filepath );
00374 if ( $dom )
00375 {
00376 $this->InstallItem['content'] =& $dom->root();
00377 }
00378 else
00379 {
00380 eZDebug::writeError( 'Failed fetching dom from file ' . $filepath,
00381 'eZPackageInstallationHandler::rootDOMNode()' );
00382 exit(0);
00383 }
00384 }
00385
00386 return $this->InstallItem['content'];
00387 }
00388
00389
00390
00391
00392
00393 function customInstallHandlerInfo( $package, $installItem )
00394 {
00395 return false;
00396 }
00397
00398 }
00399 ?>