Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezextensionpackagehandler.php
Go to the documentation of this file.
1 <?php
17 class eZExtensionPackageHandler extends eZPackageHandler
18 {
19 public $HandlerType;
20 const ERROR_EXISTS = 1;
21
22 const ACTION_REPLACE = 1;
23 const ACTION_SKIP = 2;
24
25 public function __construct()
26 {
27 parent::__construct( 'ezextension', array( 'extract-install-content' => true ) );
28 }
29
33 function explainInstallItem( $package, $installItem, $requestedInfo = array() )
34 {
35 if ( $installItem['filename'] )
36 {
37 $filename = $installItem['filename'];
38 $subdirectory = $installItem['sub-directory'];
39 if ( $subdirectory )
40 $filepath = $subdirectory . '/' . $filename . '.xml';
41 else
42 $filepath = $filename . '.xml';
43
44 $filepath = $package->path() . '/' . $filepath;
45
46 $dom = $package->fetchDOMFromFile( $filepath );
47 if ( $dom )
48 {
49 $root = $dom->documentElement;
50 $extensionName = $root->getAttribute( 'name' );
51 return array( 'description' => ezpI18n::tr( 'kernel/package', 'Extension \'%extensionname\'', false,
52 array( '%extensionname' => $extensionName ) ) );
53 }
54 }
55 }
56
60 function uninstall( $package, $installType, $parameters,
61 $name, $os, $filename, $subdirectory,
62 $content, &$installParameters,
63 &$installData )
64 {
65 $extensionName = $content->getAttribute( 'name' );
66
67 $siteINI = eZINI::instance();
68 $extensionDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' ) . '/' . $extensionName;
69
70 // TODO: don't delete modified files?
71
72 if ( file_exists( $extensionDir ) )
73 eZDir::recursiveDelete( $extensionDir );
74
75 // Deactivate extension
76 $siteINI = eZINI::instance( 'site.ini', 'settings/override', null, null, false, true );
77 $selectedExtensions = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
78
79 if ( in_array( $extensionName, $selectedExtensions ) )
80 {
81 $extensionsFlipped = array_flip( $selectedExtensions );
82
83 $extKey = $extensionsFlipped[$extensionName];
84 unset( $selectedExtensions[$extKey] );
85
86 $siteINI->setVariable( "ExtensionSettings", "ActiveExtensions", $selectedExtensions );
87 $siteINI->save( 'site.ini.append', '.php', false, false );
88 }
89
90 // Regenerate the autoloads to remove of no longer existing classes
91 ezpAutoloader::updateExtensionAutoloadArray();
92
93 return true;
94 }
95
99 function install( $package, $installType, $parameters,
100 $name, $os, $filename, $subdirectory,
101 $content, &$installParameters,
102 &$installData )
103 {
104 //$this->Package =& $package;
105
106 $trans = eZCharTransform::instance();
107 $name = $content->getAttribute( 'name' );
108 $extensionName = $trans->transformByGroup( $name, 'urlalias' );
109 if ( strcmp( $name, $extensionName ) !== 0 )
110 {
111 $description = ezpI18n::tr( 'kernel/package', 'Package contains an invalid extension name: %extensionname', false, array( '%extensionname' => $name ) );
112 $installParameters['error'] = array( 'error_code' => false,
113 'element_id' => $name,
114 'description' => $description );
115 return false;
116 }
117
118 $siteINI = eZINI::instance();
119 $extensionRootDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' );
120 $extensionDir = $extensionRootDir . '/' . $extensionName;
121 $packageExtensionDir = $package->path() . '/' . $parameters['sub-directory'] . '/' . $extensionName;
122
123 // Error: extension already exists.
124 if ( file_exists( $extensionDir ) )
125 {
126 $description = ezpI18n::tr( 'kernel/package', "Extension '%extensionname' already exists.",
127 false, array( '%extensionname' => $extensionName ) );
128 $choosenAction = $this->errorChoosenAction( self::ERROR_EXISTS,
129 $installParameters, $description, $this->HandlerType );
130 switch( $choosenAction )
131 {
132 case self::ACTION_SKIP:
133 return true;
134
135 case eZPackage::NON_INTERACTIVE:
136 case self::ACTION_REPLACE:
137 eZDir::recursiveDelete( $extensionDir );
138 break;
139
140 default:
141 $installParameters['error'] = array( 'error_code' => self::ERROR_EXISTS,
142 'element_id' => $extensionName,
143 'description' => $description,
144 'actions' => array( self::ACTION_REPLACE => ezpI18n::tr( 'kernel/package', "Replace extension" ),
145 self::ACTION_SKIP => ezpI18n::tr( 'kernel/package', 'Skip' ) ) );
146 return false;
147 }
148 }
149
150 eZDir::mkdir( $extensionDir, false, true );
151 eZDir::copy( $packageExtensionDir, $extensionRootDir );
152
153 // Regenerate autoloads for extensions to pick up the newly created extension
154 ezpAutoloader::updateExtensionAutoloadArray();
155
156 // Activate extension
157 $siteINI = eZINI::instance( 'site.ini', 'settings/override', null, null, false, true );
158
159 if ( $siteINI->hasVariable( 'ExtensionSettings', "ActiveExtensions" ) )
160 {
161 $selectedExtensions = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
162 }
163 else
164 {
165 $selectedExtensions = array();
166 }
167
168 if ( !in_array( $extensionName, $selectedExtensions ) )
169 {
170 $selectedExtensions[] = $extensionName;
171 $siteINI->setVariable( "ExtensionSettings", "ActiveExtensions", $selectedExtensions );
172 $siteINI->save( 'site.ini.append', '.php', false, false );
173 }
174 return true;
175 }
176
177 function add( $packageType, $package, $cli, $parameters )
178 {
179 foreach ( $parameters as $extensionName )
180 {
181 $cli->output( 'adding extension ' . $cli->stylize( 'dir', $extensionName ) );
182 $this->addExtension( $package, $extensionName );
183 }
184 }
185
186 static function addExtension( $package, $extensionName )
187 {
188 $siteINI = eZINI::instance();
189 $extensionDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' );
190
191 $fileList = array();
192 $sourceDir = $extensionDir . '/' . $extensionName;
193 $targetDir = $package->path() . '/ezextension';
194
195 eZDir::mkdir( $targetDir, false, true );
196 eZDir::copy( $sourceDir, $targetDir );
197
198 eZDir::recursiveList( $targetDir, '', $fileList );
199
200 $doc = new DOMDocument;
201
202 $packageRoot = $doc->createElement( 'extension' );
203 $packageRoot->setAttribute( 'name', $extensionName );
204
205 foreach( $fileList as $file )
206 {
207 $fileNode = $doc->createElement( 'file' );
208 $fileNode->setAttribute( 'name', $file['name'] );
209
210 if ( $file['path'] )
211 $fileNode->setAttribute( 'path', $file['path'] );
212
213 $fullPath = $targetDir . $file['path'] . '/' . $file['name'];
214 $fileNode->setAttribute( 'md5sum', $package->md5sum( $fullPath ) );
215
216 if ( $file['type'] == 'dir' )
217 $fileNode->setAttribute( 'type', 'dir' );
218
219 $packageRoot->appendChild( $fileNode );
220 unset( $fileNode );
221 }
222
223 $filename = 'extension-' . $extensionName;
224
225 $package->appendInstall( 'ezextension', false, false, true,
226 $filename, 'ezextension',
227 array( 'content' => $packageRoot ) );
228 $package->appendInstall( 'ezextension', false, false, false,
229 $filename, 'ezextension',
230 array( 'content' => false ) );
231 }
232
233 function handleAddParameters( $packageType, $package, $cli, $arguments )
234 {
235 $arguments = array_unique( $arguments );
236 $extensionsToAdd = array();
237
238 $extensionList = eZDir::findSubItems( eZExtension::baseDirectory(), 'dl' );
239
240 foreach ( $arguments as $argument )
241 {
242 if ( in_array( $argument, $extensionList ) )
243 {
244 $extensionsToAdd[] = $argument;
245 }
246 else
247 {
248 $cli->error( 'Extension ' . $cli->style( 'dir' ) . $argument . $cli->style( 'dir-end' ) . ' not found.' );
249 return false;
250 }
251 }
252
253 return $extensionsToAdd;
254 }
255
256 public $Package = null;
257 }
258
259 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\recursiveList
static recursiveList( $dir, $path, &$fileList)
Definition: ezdir.php:332
eZDir\copy
static copy( $sourceDirectory, &$destinationDirectory, $asChild=true, $recursive=true, $includeHidden=false, $excludeItems=false)
Definition: ezdir.php:577
eZDir\recursiveDelete
static recursiveDelete( $dir, $rootCheck=true)
Definition: ezdir.php:264
eZExtensionPackageHandler
Handles extenstions in the package system.
Definition: ezextensionpackagehandler.php:18
eZExtensionPackageHandler\ACTION_REPLACE
const ACTION_REPLACE
Definition: ezextensionpackagehandler.php:22
eZExtensionPackageHandler\$HandlerType
$HandlerType
Definition: ezextensionpackagehandler.php:19
eZExtensionPackageHandler\install
install( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
Definition: ezextensionpackagehandler.php:99
eZExtensionPackageHandler\explainInstallItem
explainInstallItem( $package, $installItem, $requestedInfo=array())
Definition: ezextensionpackagehandler.php:33
eZExtensionPackageHandler\add
add( $packageType, $package, $cli, $parameters)
Definition: ezextensionpackagehandler.php:177
eZExtensionPackageHandler\uninstall
uninstall( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
Definition: ezextensionpackagehandler.php:60
eZExtensionPackageHandler\handleAddParameters
handleAddParameters( $packageType, $package, $cli, $arguments)
Definition: ezextensionpackagehandler.php:233
eZExtensionPackageHandler\__construct
__construct()
Definition: ezextensionpackagehandler.php:25
eZExtensionPackageHandler\addExtension
static addExtension( $package, $extensionName)
Definition: ezextensionpackagehandler.php:186
eZExtensionPackageHandler\ERROR_EXISTS
const ERROR_EXISTS
Definition: ezextensionpackagehandler.php:20
eZExtensionPackageHandler\ACTION_SKIP
const ACTION_SKIP
Definition: ezextensionpackagehandler.php:23
eZExtensionPackageHandler\$Package
$Package
Definition: ezextensionpackagehandler.php:256
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZPackageHandler
The class eZPackageHandler does.
Definition: ezpackagehandler.php:18
eZPackageHandler\errorChoosenAction
static errorChoosenAction( $errorCode, &$installParameters, $description, $handlerType, $resetError=true)
Definition: ezpackagehandler.php:213
eZPackage\NON_INTERACTIVE
const NON_INTERACTIVE
Definition: ezpackage.php:33
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.