Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eziniaddonpackagehandler.php
Go to the documentation of this file.
1 <?php
17 class eZINIAddonPackageHandler extends eZPackageHandler
18 {
19 public function __construct()
20 {
21 parent::__construct( 'eziniaddon', array( 'extract-install-content' => true ) );
22 }
23
30 function install( $package, $installType, $parameters,
31 $name, $os, $filename, $subdirectory,
32 $content, &$installParameters,
33 &$installData )
34 {
35 $db = eZDB::instance();
36
37 $siteAccess = $content->getAttribute( 'site-access' );
38 if ( isset( $installParameters['site_access_map'] ) &&
39 isset( $installParameters['site_access_map'][$siteAccess] ) )
40 {
41 $siteAccess = $installParameters['site_access_map'][$siteAccess];
42 }
43
44 $filename = $content->getAttribute( 'filename' );
45
46 $ini = eZINI::instance( $filename, 'settings', null, null, true );
47 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
48 $ini->loadCache();
49
50 $blocks =& $content->elementByName( 'blocks' );
51 $blockArray =& $blocks->getElementsByTagName( 'block' );
52
53 foreach ( $blockArray as $block )
54 {
55 $blockname = $block->getAttribute( 'name' );
56
57 $blockVariableArray = $block->getElementsByTagName( 'block-variable' );
58 foreach( $blockVariableArray as $blockVariable )
59 {
60 $variableName = $blockVariable->getAttribute( 'name' );
61 $variableValues = $blockVariable->getElementsByTagName( 'value' );
62
63 if ( count( $variableValues ) == 1 )
64 {
65 $value = eZINIAddonPackageHandler::currentID( $variableValues[0], $db );
66 $ini->setVariable( $blockname, $variableName, $value );
67 }
68 else
69 {
70 $valueArray = array();
71 foreach( $variableValues as $variableNode )
72 {
73 $valueName = $variableNode->getAttribute( 'name' );
74 $value = eZINIAddonPackageHandler::currentID( $variableNode, $db );
75 $valueArray[$valueName] = $value;
76 }
77 $ini->setVariable( $blockname, $variableName, $valueArray );
78 }
79 }
80 }
81
82 $ini->save();
83
84 return true;
85 }
86
93 static function currentID( $valueNode, $db )
94 {
95 $remoteIDType = $valueNode->getAttribute( 'remote-id' );
96 $value = $valueNode->textContent;
97
98 if ( $remoteIDType !== false )
99 {
100 switch( $remoteIDType )
101 {
102 case 'class':
103 {
104 $result = $db->arrayQuery( 'SELECT id FROM ezcontentclass WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' );
105 } break;
106
107 case 'node':
108 {
109 $result = $db->arrayQuery( 'SELECT node_id FROM ezcontentobject_tree WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' );
110 } break;
111
112 case 'object':
113 {
114 $result = $db->arrayQuery( 'SELECT id FROM ezcontentobject WHERE remote_id=\'' . $db->escapeString( $value ) . '\'' );
115 } break;
116
117 default:
118 {
119 eZDebug::writeError( 'Unknown remote id type ' . $remoteIDType, __METHOD__ );
120 } break;
121 }
122
123 if ( count( $result ) != 1 )
124 {
125 eZDebug::writeError( 'Invalid result fetching id from ' . $remoteIDType . ', remote_id: ' . $value, __METHOD__ );
126 }
127 else
128 {
129 $value = $result[0][0];
130 }
131 }
132
133 return $value;
134 }
135
145 function addOverrideAddon( $package, $filename, &$iniOverrideArray, $remoteIDArray )
146 {
147 foreach( array_keys( $iniOverrideArray ) as $siteAccess )
148 {
149 $iniNode = eZINIAddonPackageHandler::iniDOMTree( $filename, $siteAccess, $iniOverrideArray[$siteAccess], $remoteIDArray );
150 if ( !$iniNode )
151 {
152 continue;
153 }
154
155 $package->appendInstall( 'eziniaddon', false, false, true,
156 $siteAccess . '-' . $filename, 'eziniaddon',
157 array( 'content' => $iniNode ) );
158 $package->appendInstall( 'eziniaddon', false, false, false,
159 $siteAccess . '-' . $filename, 'eziniaddon',
160 array( 'content' => false ) );
161 }
162 }
163
176 function iniDOMTree( $filename, $siteAccess, &$blockArray, $remoteIDArray )
177 {
178 if ( !$filename || !$siteAccess || !$blockArray )
179 {
180 return false;
181 }
182
183 $iniNode = eZDOMDocument::createElementNode( 'ini-addon', array( 'site-access' => $siteAccess,
184 'filename' => $filename ) );
185
186 $blocksNode = eZDOMDocument::createElementNode( 'blocks' );
187 $iniNode->appendChild( $blocksNode );
188 foreach( array_keys( $blockArray ) as $blockName )
189 {
190 $block =& $blockArray[$blockName];
191 unset( $blockNode );
192 $blockNode = eZDOMDocument::createElementNode( 'block', array( 'name' => $blockName ) );
193 $blocksNode->appendChild( $blockNode );
194
195 foreach( array_keys( $block ) as $blockVariable )
196 {
197 $variableValue =& $block[$blockVariable];
198 unset( $variableNode );
199 $variableNode = eZDomDocument::createElementNode( 'block-variable', array( 'name' => $blockVariable ) );
200 $blockNode->appendChild( $variableNode );
201
202 if ( is_array( $variableValue ) )
203 {
204 foreach( array_keys( $variableValue) as $valueName )
205 {
206 $value = $variableValue[$valueName];
207 unset( $valueNode );
208 $valueNode = eZDomDocument::createElementNode( 'value', array( 'name' => $valueName ) );
209 $variableNode->appendChild( $valueNode );
210 $remoteID = false;
211 if ( is_int( $value ) )
212 {
213 if ( strpos( $valueName, 'class' ) !== false )
214 {
215 $value = $remoteIDArray['class'][(string)$value];
216 $remoteID = 'class';
217 }
218 else if( strpos( $valueName, 'node' ) !== false )
219 {
220 $value = $remoteIDArray['node'][(string)$value];
221 $remoteID = 'node';
222 }
223 else if ( strpos( $valueName, 'object' ) !== false )
224 {
225 $value = $remoteIDArray['class'][(string)$value];
226 $remoteID = 'object';
227 }
228 else
229 {
230 eZDebug::writeNotice( 'Could not interpret ' . $valueName . ': ' . $value, __METHOD__ );
231 }
232 }
233 if ( $remoteID )
234 {
235 $valueNode->appendAttribute( eZDomDocument::createAttributeNode( 'remote-id', $remoteID ) );
236 }
237 $valueNode->appendChild( eZDomDocument::createTextNode( $value ) );
238 }
239 }
240 else
241 {
242 $remoteID = false;
243 if ( is_int( $variableValue ) )
244 {
245 if ( strpos( $blockVariable, 'class' ) !== false )
246 {
247 $variableValue = $remoteIDArray['class'][(string)$value];
248 $remoteID = 'class';
249 }
250 else if( strpos( $blockVariable, 'node' ) !== false )
251 {
252 $variableValue = $remoteIDArray['node'][(string)$value];
253 $remoteID = 'node';
254 }
255 else if ( strpos( $blockVariable, 'object' ) !== false )
256 {
257 $variableValue = $remoteIDArray['class'][(string)$value];
258 $remoteID = 'object';
259 }
260 else
261 {
262 eZDebug::writeNotice( 'Could not interpret ' . $blockVariable . ': ' . $variableValue, __METHOD__ );
263 }
264 }
265 unset( $valueNode );
266 $valueNode = eZDomDocument::createElementNode( 'value' );
267 $variableNode->appendChild( $valueNode );
268 if ( $remoteID )
269 {
270 $valueNode->appendAttribute( eZDomDocument::createAttributeNode( 'remote-id', $remoteID ) );
271 }
272 $valueNode->appendChild( eZDomDocument::createTextNode( $variableValue ) );
273 }
274 }
275 }
276 return $iniNode;
277 }
278 }
279 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZINIAddonPackageHandler
Handles content classes in the package system.
Definition: eziniaddonpackagehandler.php:18
eZINIAddonPackageHandler\install
install( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
Definition: eziniaddonpackagehandler.php:30
eZINIAddonPackageHandler\addOverrideAddon
addOverrideAddon( $package, $filename, &$iniOverrideArray, $remoteIDArray)
Definition: eziniaddonpackagehandler.php:145
eZINIAddonPackageHandler\iniDOMTree
iniDOMTree( $filename, $siteAccess, &$blockArray, $remoteIDArray)
Definition: eziniaddonpackagehandler.php:176
eZINIAddonPackageHandler\currentID
static currentID( $valueNode, $db)
Definition: eziniaddonpackagehandler.php:93
eZINIAddonPackageHandler\__construct
__construct()
Definition: eziniaddonpackagehandler.php:19
eZPackageHandler
The class eZPackageHandler does.
Definition: ezpackagehandler.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.