Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpackageinstallationhandler.php
Go to the documentation of this file.
1 <?php
18 class eZPackageInstallationHandler
19 {
20 public $Package;
21 public $Attributes;
22 public $InitializeStepMethodMap;
23 public $ValidateStepMethodMap;
24 public $CommitStepMethodMap;
25 public $InstallItem;
26 public $StepMap;
36 public function __construct( $package, $type, $installItem, $name = null, $steps = null )
37 {
38 $this->Package = $package;
39 $this->Attributes = array( 'type' => $type,
40 'name' => $name,
41 'steps' => $steps,
42 'step_map' => false,
43 'current_steps' => $steps );
44 $this->InitializeStepMethodMap = array();
45 $this->ValidateStepMethodMap = array();
46 $this->CommitStepMethodMap = array();
47 $this->InstallItem = $installItem;
48 }
49
57 function generateStepMap( $package, &$persistentData )
58 {
59 $steps = $this->attribute( 'steps' );
60 $map = array();
61 $lastStep = false;
62 $currentSteps = array();
63 for ( $i = 0; $i < count( $steps ); ++$i )
64 {
65 $step =& $steps[$i];
66 if ( !isset( $step['previous_step'] ) )
67 {
68 if ( $lastStep )
69 $step['previous_step'] = $lastStep['id'];
70 else
71 $step['previous_step'] = false;
72 }
73 if ( !isset( $step['next_step'] ) )
74 {
75 if ( $i + 1 < count( $steps ) )
76 $step['next_step'] = $steps[$i+1]['id'];
77 else
78 $step['next_step'] = false;
79 }
80 if ( isset( $step['methods']['initialize'] ) )
81 $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
82 if ( isset( $step['methods']['validate'] ) )
83 $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
84 if ( isset( $step['methods']['commit'] ) )
85 $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
86 $isStepIncluded = true;
87 if ( isset( $step['methods']['check'] ) )
88 {
89 $checkMethod = $step['methods']['check'];
90 $isStepIncluded = $this->$checkMethod( $package, $persistentData );
91 }
92 if ( $isStepIncluded )
93 {
94 $map[$step['id']] =& $step;
95 $lastStep =& $step;
96 $currentSteps[] =& $step;
97 }
98 }
99 $this->StepMap = array( 'first' => &$steps[0],
100 'map' => &$map,
101 'steps' => &$steps );
102 $this->Attributes['step_map'] =& $this->StepMap;
103 $this->Attributes['current_steps'] = $currentSteps;
104 }
105
106 function attributes()
107 {
108 return array_keys( $this->Attributes );
109 }
110
111 function hasAttribute( $name )
112 {
113 return array_key_exists( $name, $this->Attributes );
114 }
115
116 function attribute( $name )
117 {
118 if ( array_key_exists( $name, $this->Attributes ) )
119 {
120 return $this->Attributes[$name];
121 }
122
123 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
124 return null;
125 }
126
127 function initializeStepMethodMap()
128 {
129 return $this->InitializeStepMethodMap;
130 }
131
132 function validateStepMethodMap()
133 {
134 return $this->ValidateStepMethodMap;
135 }
136
137 function commitStepMethodMap()
138 {
139 return $this->CommitStepMethodMap;
140 }
141
146 function &stepMap()
147 {
148 return $this->StepMap;
149 }
150
151 function stepTemplate( $package, $installItem, $step )
152 {
153 $stepTemplatePath = 'design:package/';
154 $stepTemplateName = $step['template'];
155 if ( isset( $step['use_standard_template'] ) and
156 $step['use_standard_template'] )
157 $stepTemplatePath .= "create";
158 else
159 $stepTemplatePath .= "installers/" . $this->attribute( 'type' );
160 return array( 'name' => $stepTemplateName,
161 'path' => $stepTemplatePath );
162 }
163
169 function initializeStep( $package, $http, $step, &$persistentData, $tpl, $module )
170 {
171 $methodMap = $this->initializeStepMethodMap();
172 if ( count( $methodMap ) > 0 )
173 {
174 if ( isset( $methodMap[$step['id']] ) )
175 {
176 $method = $methodMap[$step['id']];
177 return $this->$method( $package, $http, $step, $persistentData, $tpl, $module );
178 }
179 }
180 }
181
190 function validateStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
191 {
192 $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
193 if ( $nextStep === true )
194 {
195 if ( !isset( $stepMap['map'][$currentStepID] ) )
196 {
197 $nextStep = $stepMap['first']['id'];
198 }
199 else
200 {
201 $currentStep =& $stepMap['map'][$currentStepID];
202 $nextStep = $currentStep['next_step'];
203 }
204 }
205 else if ( $nextStep === false )
206 $nextStep = $currentStepID;
207 return $nextStep;
208 }
209
210 function validateAndAdvanceStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
211 {
212 $methodMap = $this->validateStepMethodMap();
213 if ( count( $methodMap ) > 0 )
214 {
215 if ( isset( $methodMap[$currentStepID] ) )
216 {
217 $method = $methodMap[$currentStepID];
218 return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
219 }
220 }
221 return true;
222 }
223
228 function commitStep( $package, $http, $step, &$persistentData, $tpl )
229 {
230 $methodMap = $this->commitStepMethodMap();
231 if ( count( $methodMap ) > 0 )
232 {
233 if ( isset( $methodMap[$step['id']] ) )
234 {
235 $method = $methodMap[$step['id']];
236 return $this->$method( $package, $http, $step, $persistentData, $tpl );
237 }
238 }
239 }
240
244 function reset( )
245 {
246 }
247
248
254 function finalize( $package, $http, &$persistentData )
255 {
256 }
257
264 static function instance( $package, $handlerName, $installItem )
265 {
266 // if no installItem is given, then this is the whole package installer
267 /*if ( $installItem == null )
268 {
269 include_once( $package->path() . '/' . $package->installerDirectory() . '/' . $package->installerFileName() );
270 $handlerClassName = $package->installerFileName();
271 $handler =& new $handlerClassName( $package, null, null );
272 return $handler;
273 }*/
274
275 $handlers =& $GLOBALS['eZPackageCreationInstallers'];
276 if ( !isset( $handlers ) )
277 $handlers = array();
278 $handler = false;
279
280 if( isset( $handlers[$handlerName] ) )
281 {
282 $handler =& $handlers[$handlerName];
283 $handler->reset();
284 }
285 else
286 {
287 $optionArray = array( 'iniFile' => 'package.ini',
288 'iniSection' => 'InstallerSettings',
289 'iniVariable' => 'HandlerAlias',
290 'handlerIndex' => $handlerName,
291 'handlerParams' => array( $package, $handlerName, $installItem ) );
292
293 $options = new ezpExtensionOptions( $optionArray );
294
295 $handler = eZExtension::getHandlerClass( $options );
296
297 if( $handler !== null and $handler !== false )
298 {
299 $handlers[$handlerName] =& $handler;
300 // if custom install handler is available in the package, we use it
301 $customInstallHandler = $handler->customInstallHandlerInfo( $package, $installItem );
302 if ( $customInstallHandler )
303 {
304 unset( $handler );
305 $handlerClassName = $customInstallHandler['classname'];
306 $handlerFile = $customInstallHandler['file-path'];
307
308 include_once( $handlerFile );
309 $handler = new $handlerClassName( $package, $handlerName, $installItem );
310 }
311 }
312 }
313
314 return $handler;
315 }
316
325 function packageType( $package, &$persistentData )
326 {
327 if ( $package instanceof eZPackage )
328 {
329 return $package->attribute( 'type' );
330 }
331 return false;
332 }
333
338 function rootDOMNode()
339 {
340 if ( !isset( $this->InstallItem['content'] ) || !$this->InstallItem['content'] )
341 {
342 $filename = $this->InstallItem['filename'];
343 $subdirectory = $this->InstallItem['sub-directory'];
344 if ( $subdirectory )
345 $filepath = $subdirectory . '/' . $filename . '.xml';
346 else
347 $filepath = $filename . '.xml';
348
349 $filepath = $this->Package->path() . '/' . $filepath;
350
351 $dom = $this->Package->fetchDOMFromFile( $filepath );
352 if ( $dom )
353 {
354 $this->InstallItem['content'] = $dom->documentElement;
355 }
356 else
357 {
358 eZDebug::writeError( 'Failed fetching dom from file ' . $filepath, __METHOD__ );
359 exit(0);
360 }
361 }
362
363 return $this->InstallItem['content'];
364 }
365
370 function customInstallHandlerInfo( $package, $installItem )
371 {
372 return false;
373 }
374
375 }
376 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\getHandlerClass
static getHandlerClass(ezpExtensionOptions $options)
Definition: ezextension.php:531
eZPackageInstallationHandler
The class eZPackageInstallationHandler does.
Definition: ezpackageinstallationhandler.php:19
eZPackageInstallationHandler\hasAttribute
hasAttribute( $name)
Definition: ezpackageinstallationhandler.php:111
eZPackageInstallationHandler\customInstallHandlerInfo
customInstallHandlerInfo( $package, $installItem)
Definition: ezpackageinstallationhandler.php:370
eZPackageInstallationHandler\stepMap
& stepMap()
Definition: ezpackageinstallationhandler.php:146
eZPackageInstallationHandler\$Attributes
$Attributes
Definition: ezpackageinstallationhandler.php:21
eZPackageInstallationHandler\commitStep
commitStep( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackageinstallationhandler.php:228
eZPackageInstallationHandler\$Package
$Package
Definition: ezpackageinstallationhandler.php:20
eZPackageInstallationHandler\initializeStepMethodMap
initializeStepMethodMap()
Definition: ezpackageinstallationhandler.php:127
eZPackageInstallationHandler\validateAndAdvanceStep
validateAndAdvanceStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackageinstallationhandler.php:210
eZPackageInstallationHandler\$ValidateStepMethodMap
$ValidateStepMethodMap
Definition: ezpackageinstallationhandler.php:23
eZPackageInstallationHandler\validateStepMethodMap
validateStepMethodMap()
Definition: ezpackageinstallationhandler.php:132
eZPackageInstallationHandler\initializeStep
initializeStep( $package, $http, $step, &$persistentData, $tpl, $module)
Definition: ezpackageinstallationhandler.php:169
eZPackageInstallationHandler\generateStepMap
generateStepMap( $package, &$persistentData)
Definition: ezpackageinstallationhandler.php:57
eZPackageInstallationHandler\stepTemplate
stepTemplate( $package, $installItem, $step)
Definition: ezpackageinstallationhandler.php:151
eZPackageInstallationHandler\finalize
finalize( $package, $http, &$persistentData)
Definition: ezpackageinstallationhandler.php:254
eZPackageInstallationHandler\$CommitStepMethodMap
$CommitStepMethodMap
Definition: ezpackageinstallationhandler.php:24
eZPackageInstallationHandler\attribute
attribute( $name)
Definition: ezpackageinstallationhandler.php:116
eZPackageInstallationHandler\$InstallItem
$InstallItem
Definition: ezpackageinstallationhandler.php:25
eZPackageInstallationHandler\rootDOMNode
rootDOMNode()
Definition: ezpackageinstallationhandler.php:338
eZPackageInstallationHandler\__construct
__construct( $package, $type, $installItem, $name=null, $steps=null)
Definition: ezpackageinstallationhandler.php:36
eZPackageInstallationHandler\commitStepMethodMap
commitStepMethodMap()
Definition: ezpackageinstallationhandler.php:137
eZPackageInstallationHandler\attributes
attributes()
Definition: ezpackageinstallationhandler.php:106
eZPackageInstallationHandler\$InitializeStepMethodMap
$InitializeStepMethodMap
Definition: ezpackageinstallationhandler.php:22
eZPackageInstallationHandler\$StepMap
$StepMap
Definition: ezpackageinstallationhandler.php:26
eZPackageInstallationHandler\reset
reset()
Definition: ezpackageinstallationhandler.php:244
eZPackageInstallationHandler\packageType
packageType( $package, &$persistentData)
Definition: ezpackageinstallationhandler.php:325
eZPackageInstallationHandler\validateStep
validateStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackageinstallationhandler.php:190
eZPackageInstallationHandler\instance
static instance( $package, $handlerName, $installItem)
Definition: ezpackageinstallationhandler.php:264
eZPackage
Maintains eZ Publish packages.
Definition: ezpackage.php:20
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.