Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpackagecreationhandler.php
Go to the documentation of this file.
1 <?php
18 class eZPackageCreationHandler
19 {
20 public $Attributes;
21 public $InitializeStepMethodMap;
22 public $ValidateStepMethodMap;
23 public $CommitStepMethodMap;
24 public $LoadStepMethodMap;
25 public $StepMap;
33 public function __construct( $id, $name, $steps )
34 {
35 $this->Attributes = array( 'id' => $id,
36 'name' => $name,
37 'steps' => $steps,
38 'step_map' => false,
39 'current_steps' => $steps );
40 $this->InitializeStepMethodMap = array();
41 $this->ValidateStepMethodMap = array();
42 $this->CommitStepMethodMap = array();
43 $this->LoadStepMethodMap = array();
44 }
45
53 function generateStepMap( $package, &$persistentData )
54 {
55 $steps = $this->attribute( 'steps' );
56 $map = array();
57 $lastStep = false;
58 $currentSteps = array();
59 for ( $i = 0; $i < count( $steps ); ++$i )
60 {
61 $step =& $steps[$i];
62 if ( !isset( $step['previous_step'] ) )
63 {
64 if ( $lastStep )
65 $step['previous_step'] = $lastStep['id'];
66 else
67 $step['previous_step'] = false;
68 }
69 if ( !isset( $step['next_step'] ) )
70 {
71 if ( $i + 1 < count( $steps ) )
72 $step['next_step'] = $steps[$i+1]['id'];
73 else
74 $step['next_step'] = false;
75 }
76 if ( isset( $step['methods']['initialize'] ) )
77 $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
78 if( isset( $step['methods']['load'] ) )
79 $this->LoadStepMethodMap[$step['id']] = $step['methods']['load'];
80 if ( isset( $step['methods']['validate'] ) )
81 $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
82 if ( isset( $step['methods']['commit'] ) )
83 $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
84 $isStepIncluded = true;
85 if ( isset( $step['methods']['check'] ) )
86 {
87 $checkMethod = $step['methods']['check'];
88 $isStepIncluded = $this->$checkMethod( $package, $persistentData );
89 }
90 if ( $isStepIncluded )
91 {
92 $map[$step['id']] =& $step;
93 $lastStep =& $step;
94 $currentSteps[] =& $step;
95 }
96 }
97 $this->StepMap = array( 'first' => &$steps[0],
98 'map' => &$map,
99 'steps' => &$steps );
100 $this->Attributes['step_map'] =& $this->StepMap;
101 $this->Attributes['current_steps'] = $currentSteps;
102 }
103
104 function attributes()
105 {
106 return array_keys( $this->Attributes );
107 }
108
109 function hasAttribute( $name )
110 {
111 return array_key_exists( $name, $this->Attributes );
112 }
113
114 function attribute( $name )
115 {
116 if ( array_key_exists( $name, $this->Attributes ) )
117 {
118 return $this->Attributes[$name];
119 }
120
121 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
122 return null;
123 }
124
125 function initializeStepMethodMap()
126 {
127 return $this->InitializeStepMethodMap;
128 }
129
130 function loadStepMethodMap()
131 {
132 return $this->LoadStepMethodMap;
133 }
134
135 function validateStepMethodMap()
136 {
137 return $this->ValidateStepMethodMap;
138 }
139
140 function commitStepMethodMap()
141 {
142 return $this->CommitStepMethodMap;
143 }
144
149 function &stepMap()
150 {
151 return $this->StepMap;
152 }
153
154 function stepTemplate( $step )
155 {
156 $stepTemplateName = $step['template'];
157 if ( isset( $step['use_standard_template'] ) and
158 $step['use_standard_template'] )
159 $stepTemplateDir = "create";
160 else
161 $stepTemplateDir = "creators/" . $this->attribute( 'id' );
162 return array( 'name' => $stepTemplateName,
163 'dir' => $stepTemplateDir );
164 }
165
171 function initializeStep( $package, $http, $step, &$persistentData, $tpl )
172 {
173 $methodMap = $this->initializeStepMethodMap();
174 if ( count( $methodMap ) > 0 )
175 {
176 if ( isset( $methodMap[$step['id']] ) )
177 {
178 $method = $methodMap[$step['id']];
179 return $this->$method( $package, $http, $step, $persistentData, $tpl );
180 }
181 }
182 }
183
187 function loadStep( $package, $http, $currentStepID, &$persistentData, $tpl, &$module )
188 {
189 $methodMap = $this->loadStepMethodMap();
190 if ( count( $methodMap ) > 0 )
191 {
192 if ( isset( $methodMap[$currentStepID] ) )
193 {
194 $method = $methodMap[$currentStepID];
195 return $this->$method( $package, $http, $currentStepID, $persistentData, $tpl, $module );
196 }
197 }
198 }
199
208 function validateStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
209 {
210 $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
211 if ( $nextStep === true )
212 {
213 if ( !isset( $stepMap['map'][$currentStepID] ) )
214 {
215 return $stepMap['first']['id'];
216 }
217 else
218 {
219 return $stepMap['map'][$currentStepID]['next_step'];
220 }
221 }
222 else if ( $nextStep === false )
223 {
224 return $currentStepID;
225 }
226 return $nextStep;
227 }
228
229 function validateAndAdvanceStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
230 {
231 $methodMap = $this->validateStepMethodMap();
232 if ( count( $methodMap ) > 0 )
233 {
234 if ( isset( $methodMap[$currentStepID] ) )
235 {
236 $method = $methodMap[$currentStepID];
237 return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
238 }
239 }
240 return true;
241 }
242
247 function commitStep( $package, $http, $step, &$persistentData, $tpl )
248 {
249 $methodMap = $this->commitStepMethodMap();
250 if ( count( $methodMap ) > 0 )
251 {
252 if ( isset( $methodMap[$step['id']] ) )
253 {
254 $method = $methodMap[$step['id']];
255 return $this->$method( $package, $http, $step, $persistentData, $tpl );
256 }
257 }
258 }
259
265 function finalize( &$package, $http, &$persistentData )
266 {
267 }
268
273 static function creatorLimitationList()
274 {
275 $creators =& eZPackageCreationHandler::creatorList();
276 $list = array();
277 foreach ( $creators as $creator )
278 {
279 $list[] = array( 'name' => $creator->attribute( 'name' ),
280 'id' => $creator->attribute( 'id' ) );
281 }
282 return $list;
283 }
284
289 static function &creatorList( $checkRoles = false )
290 {
291 $allowedCreators = false;
292
293 $currentUser = eZUser::currentUser();
294 $accessResult = $currentUser->hasAccessTo( 'package', 'create' );
295 $limitationList = array();
296 $canCreate = false;
297 if ( $accessResult['accessWord'] == 'no' )
298 {
299 $creators = array();
300 return $creators;
301 }
302
303 if ( $accessResult['accessWord'] == 'limited' )
304 {
305 $limitationList = $accessResult['policies'];
306 foreach( $limitationList as $limitationArray ) // TODO : fix this
307 {
308 foreach ( $limitationArray as $key => $limitation )
309 {
310 if ( $key == 'CreatorType' )
311 {
312 if ( !is_array( $allowedCreators ) )
313 $allowedCreators = array();
314 $list = $limitation;
315 $allowedCreators = array_merge( $allowedCreators, $list );
316 }
317 }
318 }
319 }
320
321 $creators =& $GLOBALS['eZPackageCreatorList'];
322 if ( !isset( $creators ) )
323 {
324 $creators = array();
325 $ini = eZINI::instance( 'package.ini' );
326 $list = $ini->variable( 'CreationSettings', 'HandlerList' );
327 foreach ( $list as $name )
328 {
329 if ( is_array( $allowedCreators ) and
330 !in_array( $name, $allowedCreators ) )
331 continue;
332 $handler = eZPackageCreationHandler::instance( $name );
333 $creators[] = $handler;
334 }
335 }
336 return $creators;
337 }
338
346 static function instance( $handlerName )
347 {
348 $handlers =& $GLOBALS['eZPackageCreationHandlers'];
349 if ( !isset( $handlers ) )
350 $handlers = array();
351 $handler = false;
352
353 if( isset( $handlers[$handlerName] ) )
354 {
355 $handler = $handlers[$handlerName];
356 $handler->reset();
357 }
358 else
359 {
360 $optionArray = array( 'iniFile' => 'package.ini',
361 'iniSection' => 'CreationSettings',
362 'iniVariable' => 'HandlerAlias',
363 'handlerIndex' => $handlerName,
364 'handlerParams' => array( $handlerName ) );
365
366 $options = new ezpExtensionOptions( $optionArray );
367
368 $handler = eZExtension::getHandlerClass( $options );
369 $handlers[$handlerName] = $handler;
370 }
371 return $handler;
372 }
373
378 function packageInformationStep()
379 {
380 return array( 'id' => 'packageinfo',
381 'name' => ezpI18n::tr( 'kernel/package', 'Package information' ),
382 'methods' => array( 'initialize' => 'initializePackageInformation',
383 'validate' => 'validatePackageInformation',
384 'commit' => 'commitPackageInformation' ),
385 'use_standard_template' => true,
386 'template' => 'info.tpl' );
387 }
388
393 function packageMaintainerStep()
394 {
395 return array( 'id' => 'packagemaintainer',
396 'name' => ezpI18n::tr( 'kernel/package', 'Package maintainer' ),
397 'methods' => array( 'initialize' => 'initializePackageMaintainer',
398 'validate' => 'validatePackageMaintainer',
399 'commit' => 'commitPackageMaintainer',
400 'check' => 'checkPackageMaintainer' ),
401 'use_standard_template' => true,
402 'template' => 'maintainer.tpl' );
403 }
404
409 function packageChangelogStep()
410 {
411 return array( 'id' => 'packagechangelog',
412 'name' => ezpI18n::tr( 'kernel/package', 'Package changelog' ),
413 'methods' => array( 'initialize' => 'initializePackageChangelog',
414 'validate' => 'validatePackageChangelog',
415 'commit' => 'commitPackageChangelog' ),
416 'use_standard_template' => true,
417 'template' => 'changelog.tpl' );
418 }
419
424 function packageThumbnailStep()
425 {
426 return array( 'id' => 'packagethumbnail',
427 'name' => ezpI18n::tr( 'kernel/package', 'Package thumbnail' ),
428 'methods' => array( 'initialize' => 'initializePackageThumbnail',
429 'validate' => 'validatePackageThumbnail',
430 'commit' => 'commitPackageThumbnail' ),
431 'use_standard_template' => true,
432 'template' => 'thumbnail.tpl' );
433 }
434
441 function packageInstallType( $package, &$persistentData )
442 {
443 return 'install';
444 }
445
453 function packageInitialState( $package, &$persistentData )
454 {
455 return 'alpha';
456 }
457
464 function initialChangelogEntry( $package, $http, $step, &$persistentData, $tpl )
465 {
466 return '- Creation of package.';
467 }
468
477 function packageType( $package, &$persistentData )
478 {
479 if ( $package instanceof eZPackage )
480 {
481 return $package->attribute( 'type' );
482 }
483 return false;
484 }
485
493 function createPackage( &$package, $http, &$persistentData, &$cleanupFiles, $storePackage = true )
494 {
495 $createdPackage = false;
496 if ( !( $package instanceof eZPackage ) )
497 {
498 $package = eZPackage::create( $persistentData['name'],
499 array( 'summary' => $persistentData['summary'] ) );
500 $createdPackage = true;
501 }
502 else
503 $package->setAttribute( 'summary', $persistentData['summary'] );
504
505 $package->setAttribute( 'is_active', false );
506 $package->setAttribute( 'type', $this->packageType( $package, $persistentData ) );
507
508 $package->setRelease( $persistentData['version'], '1', false,
509 $persistentData['licence'], $this->packageInitialState( $package, $persistentData ) );
510
511 $package->setAttribute( 'description', $persistentData['description'] );
512 $package->setAttribute( 'install_type', $this->packageInstallType( $package, $persistentData ) );
513
514 $package->setAttribute( 'packaging-host', $persistentData['host'] );
515 $package->setAttribute( 'packaging-packager', $persistentData['packager'] );
516
517 $changelogPerson = $persistentData['changelog_person'];
518 $changelogEmail = $persistentData['changelog_email'];
519 $changelogEntries = $persistentData['changelog_entries'];
520
521 $maintainerPerson = $persistentData['maintainer_person'];
522 $maintainerEmail = $persistentData['maintainer_email'];
523 $maintainerRole = $persistentData['maintainer_role'];
524
525 if ( $maintainerPerson )
526 {
527 $package->appendMaintainer( $maintainerPerson, $maintainerEmail, $maintainerRole );
528 }
529
530 if ( $changelogPerson )
531 {
532 $package->appendChange( $changelogPerson, $changelogEmail, $changelogEntries );
533 }
534
535 if ( $persistentData['licence'] == 'GPL' )
536 {
537 eZPackageCreationHandler::appendLicence( $package );
538 }
539
540
541 $collections = array();
542 $cleanupFiles = array();
543
544 if ( isset( $persistentData['thumbnail'] ) and
545 $persistentData['thumbnail'] )
546 {
547 $thumbnail = $persistentData['thumbnail'];
548 $fileItem = array( 'file' => $thumbnail['filename'],
549 'type' => 'thumbnail',
550 'role' => false,
551 'design' => false,
552 'path' => $thumbnail['url'],
553 'collection' => 'default',
554 'file-type' => false,
555 'role-value' => false,
556 'variable-name' => 'thumbnail' );
557
558 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
559 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
560 null, null, true, null,
561 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
562 $cleanupFiles[] = $fileItem['path'];
563
564 if ( !in_array( $fileItem['collection'], $collections ) )
565 $collections[] = $fileItem['collection'];
566 }
567
568 foreach ( $collections as $collection )
569 {
570 $installItems = $package->installItemsList( 'ezfile', false, $collection, true );
571 if ( count( $installItems ) == 0 )
572 $package->appendInstall( 'ezfile', false, false, true,
573 false, false,
574 array( 'collection' => $collection ) );
575 $dependencyItems = $package->dependencyItems( 'provides',
576 array( 'type' => 'ezfile',
577 'name' => 'collection',
578 'valiue' => $collection ) );
579 if ( count( $dependencyItems ) == 0 )
580 $package->appendDependency( 'provides',
581 array( 'type' => 'ezfile',
582 'name' => 'collection',
583 'value' => $collection ) );
584 $installItems = $package->installItemsList( 'ezfile', false, $collection, false );
585 if ( count( $installItems ) == 0 )
586 $package->appendInstall( 'ezfile', false, false, false,
587 false, false,
588 array( 'collection' => $collection ) );
589 }
590
591 $package->setAttribute( 'is_active', true );
592 if ( $storePackage )
593 $package->store();
594
595 return $createdPackage;
596 }
597
603 function generatePackageInformation( &$packageInformation, $package, $http, $step, &$persistentData )
604 {
605 }
606
611 function initializePackageInformation( $package, $http, $step, &$persistentData, $tpl )
612 {
613 $persistentData['name'] = false;
614 $persistentData['summary'] = false;
615 $persistentData['description'] = false;
616 $persistentData['licence'] = 'GPL';
617 $persistentData['version'] = '1.0';
618 if ( isset( $_SERVER['HOSTNAME'] ) )
619 $host = $_SERVER['HOSTNAME'];
620 else
621 $host = $_SERVER['HTTP_HOST'];
622 $persistentData['host'] = $host;
623 $user = eZUser::currentUser();
624 $userObject = $user->attribute( 'contentobject' );
625 $packager = false;
626 if ( $userObject )
627 $packager = $userObject->attribute( 'name' );
628 $persistentData['packager'] = $packager;
629 $this->generatePackageInformation( $persistentData, $package, $http, $step, $persistentData );
630
631 // Make sure the package name contains only valid characters
632 $trans = eZCharTransform::instance();
633 $persistentData['name'] = $trans->transformByGroup( $persistentData['name'], 'identifier' );
634 }
635
641 function validatePackageInformation( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
642 {
643 $packageName = false;
644 $packageSummary = false;
645 $packageVersion = false;
646 $packageDescription = false;
647 $packageLicence = 'GPL';
648 $packageHost = false;
649 $packagePackager = false;
650 if ( $http->hasPostVariable( 'PackageName' ) )
651 {
652 $packageName = trim( $http->postVariable( 'PackageName' ) );
653 }
654 if ( $http->hasPostVariable( 'PackageSummary' ) )
655 $packageSummary = $http->postVariable( 'PackageSummary' );
656 if ( $http->hasPostVariable( 'PackageDescription' ) )
657 $packageDescription = $http->postVariable( 'PackageDescription' );
658 if ( $http->hasPostVariable( 'PackageVersion' ) )
659 $packageVersion = trim( $http->postVariable( 'PackageVersion' ) );
660 if ( $http->hasPostVariable( 'PackageLicence' ) )
661 $packageLicence = $http->postVariable( 'PackageLicence' );
662 if ( $http->hasPostVariable( 'PackageHost' ) )
663 $packageHost = $http->postVariable( 'PackageHost' );
664 if ( $http->hasPostVariable( 'PackagePackager' ) )
665 $packagePackager = $http->postVariable( 'PackagePackager' );
666
667 $persistentData['name'] = $packageName;
668 $persistentData['summary'] = $packageSummary;
669 $persistentData['description'] = $packageDescription;
670 $persistentData['version'] = $packageVersion;
671 $persistentData['licence'] = $packageLicence;
672 $persistentData['host'] = $packageHost;
673 $persistentData['packager'] = $packagePackager;
674
675 $result = true;
676 if ( $packageName == '' )
677 {
678 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Package name' ),
679 'description' => ezpI18n::tr( 'kernel/package', 'Package name is missing' ) );
680 $result = false;
681 }
682 else
683 {
684 $existingPackage = eZPackage::fetch( $packageName, false, true );
685 if ( $existingPackage )
686 {
687 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Package name' ),
688 'description' => ezpI18n::tr( 'kernel/package', 'A package named %packagename already exists, please give another name', false, array( '%packagename' => $packageName ) ) );
689 $result = false;
690 }
691 else
692 {
693 // Make sure the package name contains only valid characters
694 $trans = eZCharTransform::instance();
695 $validPackageName = $trans->transformByGroup( $packageName, 'identifier' );
696 if ( strcmp( $validPackageName, $packageName ) != 0 )
697 {
698 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Package name' ),
699 'description' => ezpI18n::tr( 'kernel/package', "The package name %packagename is not valid, it can only contain characters in the range a-z, 0-9 and underscore.", false, array( '%packagename' => $packageName ) ) );
700 $result = false;
701 }
702 }
703 }
704 if ( !$packageSummary )
705 {
706 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Summary' ),
707 'description' => ezpI18n::tr( 'kernel/package', 'Summary is missing' ) );
708 $result = false;
709 }
710 if ( !preg_match( "#^[0-9](\.[0-9]([a-zA-Z]+[0-9]*)?)*$#", $packageVersion ) )
711 {
712 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Version' ),
713 'description' => ezpI18n::tr( 'kernel/package', 'The version must only contain numbers (optionally followed by text) and must be delimited by dots (.), e.g. 1.0, 3.4.0beta1' ) );
714 $result = false;
715 }
716 return $result;
717 }
718
722 function commitPackageInformation( $package, $http, $step, &$persistentData, $tpl )
723 {
724 }
725
730 function initializePackageChangelog( $package, $http, $step, &$persistentData, $tpl )
731 {
732 $user = eZUser::currentUser();
733 $userObject = $user->attribute( 'contentobject' );
734 if ( $userObject )
735 $changelogPerson = $userObject->attribute( 'name' );
736 $changelogEmail = $user->attribute( 'email' );
737 $changelogText = '';
738
739 $persistentData['changelog_person'] = $changelogPerson;
740 $persistentData['changelog_email'] = $changelogEmail;
741 if ( !( $package instanceof eZPackage ) )
742 {
743 $changelogText = $this->initialChangelogEntry( $package, $http, $step, $persistentData, $tpl );
744 }
745 $persistentData['changelog_text'] = $changelogText;
746 $persistentData['changelog_entries'] = array();
747 }
748
753 function validatePackageChangelog( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
754 {
755 $changelogPerson = false;
756 $changelogEmail = false;
757 $changelogText = false;
758 if ( $http->hasPostVariable( 'PackageChangelogPerson' ) )
759 $changelogPerson = trim( $http->postVariable( 'PackageChangelogPerson' ) );
760 if ( $http->hasPostVariable( 'PackageChangelogEmail' ) )
761 $changelogEmail = $http->postVariable( 'PackageChangelogEmail' );
762 if ( $http->hasPostVariable( 'PackageChangelogText' ) )
763 $changelogText = $http->postVariable( 'PackageChangelogText' );
764
765 $persistentData['changelog_person'] = $changelogPerson;
766 $persistentData['changelog_email'] = $changelogEmail;
767 $persistentData['changelog_text'] = $changelogText;
768
769 $result = true;
770 if ( trim( $changelogPerson ) == '' )
771 {
772 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Name' ),
773 'description' => ezpI18n::tr( 'kernel/package', 'You must enter a name for the changelog' ) );
774 $result = false;
775 }
776 if ( trim( $changelogEmail ) == '' )
777 {
778 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Email' ),
779 'description' => ezpI18n::tr( 'kernel/package', 'You must enter an email for the changelog' ) );
780 $result = false;
781 }
782 if ( trim( $changelogText ) == '' )
783 {
784 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Changelog' ),
785 'description' => ezpI18n::tr( 'kernel/package', 'You must supply some text for the changelog entry' ) );
786 $result = false;
787 }
788 return $result;
789 }
790
794 function commitPackageChangelog( $package, $http, $step, &$persistentData, $tpl )
795 {
796 $changelogEntries = array();
797 $changelogText = $persistentData['changelog_text'];
798 $lines = preg_split( "#\r\n|\n|\r#", $changelogText );
799 $currentEntries = false;
800 foreach ( $lines as $line )
801 {
802 if ( strlen( $line ) > 0 and
803 ( $line[0] == '-' or $line[0] == '*' ) )
804 {
805 if ( $currentEntries !== false )
806 {
807 $changelogEntries[] = implode( ' ', $currentEntries );
808 }
809 $currentEntries = array();
810 $currentEntries[] = trim( substr( $line, 1 ) );
811 }
812 else
813 {
814 if ( $currentEntries === false )
815 {
816 $changelogEntries = array();
817 }
818 $currentEntries[] = trim( $line );
819 }
820 }
821 if ( $currentEntries !== false )
822 {
823 $changelogEntries[] = implode( ' ', $currentEntries );
824 }
825 $persistentData['changelog_entries'] = $changelogEntries;
826 }
827
831 function initializePackageMaintainer( $package, $http, $step, &$persistentData, $tpl )
832 {
833 $maintainerPerson = false;
834 $maintainerEmail = false;
835 $user = eZUser::currentUser();
836 $userObject = $user->attribute( 'contentobject' );
837 if ( $userObject )
838 $maintainerPerson = $userObject->attribute( 'name' );
839 $maintainerEmail = $user->attribute( 'email' );
840 $persistentData['maintainer_person'] = $maintainerPerson;
841 $persistentData['maintainer_email'] = $maintainerEmail;
842 $persistentData['maintainer_role'] = false;
843 }
844
848 function validatePackageMaintainer( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
849 {
850 $maintainerPerson = false;
851 $maintainerEmail = false;
852 $maintainerRole = false;
853 if ( $http->hasPostVariable( 'PackageMaintainerPerson' ) )
854 $maintainerPerson = trim( $http->postVariable( 'PackageMaintainerPerson' ) );
855 if ( $http->hasPostVariable( 'PackageMaintainerEmail' ) )
856 $maintainerEmail = $http->postVariable( 'PackageMaintainerEmail' );
857 if ( $http->hasPostVariable( 'PackageMaintainerRole' ) )
858 $maintainerRole = $http->postVariable( 'PackageMaintainerRole' );
859
860 $persistentData['maintainer_person'] = $maintainerPerson;
861 $persistentData['maintainer_email'] = $maintainerEmail;
862 $persistentData['maintainer_role'] = $maintainerRole;
863
864 $result = true;
865 if ( trim( $maintainerPerson ) == '' )
866 {
867 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Name' ),
868 'description' => ezpI18n::tr( 'kernel/package', 'You must enter a name of the maintainer' ) );
869 $result = false;
870 }
871 if ( trim( $maintainerEmail ) == '' )
872 {
873 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Email' ),
874 'description' => ezpI18n::tr( 'kernel/package', 'You must enter an email address of the maintainer' ) );
875 $result = false;
876 }
877 return $result;
878 }
879
883 function commitPackageMaintainer( $package, $http, $step, &$persistentData, $tpl )
884 {
885 }
886
893 function checkPackageMaintainer( $package, &$persistentData )
894 {
895 $roleList = eZPackage::fetchMaintainerRoleIDList( $this->packageType( $package, $persistentData ), true );
896 if ( count( $roleList ) > 0 )
897 {
898 if ( $package instanceof eZPackage )
899 {
900 $maintainerPerson = false;
901 $user = eZUser::currentUser();
902 $userObject = $user->attribute( 'contentobject' );
903 if ( $userObject )
904 $maintainerPerson = $userObject->attribute( 'name' );
905
906 $maintainers = $package->attribute( 'maintainers' );
907 foreach ( $maintainers as $maintainer )
908 {
909 if ( $maintainer['person'] == $maintainerPerson )
910 {
911 return false;
912 }
913 }
914 }
915 return true;
916 }
917 return false;
918 }
919
923 function initializePackageThumbnail( $package, $http, $step, &$persistentData, $tpl )
924 {
925 $persistentData['thumbnail'] = false;
926 }
927
931 function validatePackageThumbnail( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
932 {
933 // If we don't have an image we continue as normal
934 if ( !eZHTTPFile::canFetch( 'PackageThumbnail' ) )
935 return true;
936
937 if ( !self::httpFileIsImage( ezpI18n::tr( 'kernel/package', 'PackageThumbnail' ), $errorList ) )
938 {
939 return false;
940 }
941
942 $file = eZHTTPFile::fetch( 'PackageThumbnail' );
943
944 $result = true;
945 if ( $file )
946 {
947 $mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
948 $dir = eZSys::storageDirectory() . '/temp';
949 eZMimeType::changeDirectoryPath( $mimeData, $dir );
950 $file->store( false, false, $mimeData );
951 $persistentData['thumbnail'] = $mimeData;
952 }
953 return $result;
954 }
955
959 static function httpFileIsImage( $httpFileName, &$errorList )
960 {
961 if ( !isset( $_FILES[$httpFileName] ) || $_FILES[$httpFileName]["tmp_name"] === "" )
962 {
963 $errorList[] = array( 'field' => $httpFileName,
964 'description' => ezpI18n::tr( 'kernel/package', 'The file does not exist.' ) );
965 return false;
966 }
967
968 $imagefile = $_FILES[$httpFileName]['tmp_name'];
969 if ( !$_FILES[$httpFileName]["size"] )
970 {
971 $errorList[] = array( 'field' => $httpFileName,
972 'description' => ezpI18n::tr( 'kernel/package', 'The image file must have non-zero size.' ) );
973 return false;
974 }
975
976 $mimeType = eZMimeType::findByURL( $_FILES[$httpFileName]['name'] );
977 $nameMimeType = $mimeType['name'];
978 $nameMimeTypes = explode("/", $nameMimeType);
979 if ( $nameMimeTypes[0] != 'image' )
980 {
981 $errorList[] = array( 'field' => $httpFileName,
982 'description' => ezpI18n::tr( 'kernel/package', 'A valid image file is required.' ) );
983 return false;
984 }
985
986 return true;
987 }
988
992 function commitPackageThumbnail( $package, $http, $step, &$persistentData, $tpl )
993 {
994 }
995
1000 static function appendLicence( $package )
1001 {
1002 $package->appendDocument( 'LICENCE', false, false, false, true,
1003 "This file is part of the package " . $package->attribute( 'name' ) . ".\n" .
1004 "\n" .
1005 "This package is free software; you can redistribute it and/or modify\n" .
1006 "it under the terms of the GNU General Public License as published by\n" .
1007 "the Free Software Foundation; either version 2 of the License, or\n" .
1008 "(at your option) any later version.\n" .
1009 "\n" .
1010 "This package is distributed in the hope that it will be useful,\n" .
1011 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" .
1012 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" .
1013 "GNU General Public License for more details.\n" .
1014 "\n" .
1015 "You should have received a copy of the GNU General Public License\n" .
1016 "along with this package; if not, write to the Free Software\n" .
1017 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" );
1018 }
1019 }
1020
1021 ?>
eZCharTransform\instance
static instance()
Definition: ezchartransform.php:434
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExtension\getHandlerClass
static getHandlerClass(ezpExtensionOptions $options)
Definition: ezextension.php:531
eZHTTPFile\canFetch
static canFetch( $httpName, $maxSize=false)
Definition: ezhttpfile.php:203
eZHTTPFile\fetch
static fetch( $http_name)
Definition: ezhttpfile.php:269
eZMimeType\changeDirectoryPath
static changeDirectoryPath(&$mimeInfo, $dirpath)
Definition: ezmimetype.php:155
eZMimeType\findByFileContents
static findByFileContents( $url, $returnDefault=true)
Definition: ezmimetype.php:308
eZMimeType\findByURL
static findByURL( $url, $returnDefault=true)
Definition: ezmimetype.php:227
eZPackageCreationHandler
The class eZPackageCreationHandler does.
Definition: ezpackagecreationhandler.php:19
eZPackageCreationHandler\$CommitStepMethodMap
$CommitStepMethodMap
Definition: ezpackagecreationhandler.php:23
eZPackageCreationHandler\commitPackageChangelog
commitPackageChangelog( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:794
eZPackageCreationHandler\initializeStepMethodMap
initializeStepMethodMap()
Definition: ezpackagecreationhandler.php:125
eZPackageCreationHandler\validatePackageInformation
validatePackageInformation( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:641
eZPackageCreationHandler\validateStep
validateStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:208
eZPackageCreationHandler\creatorLimitationList
static creatorLimitationList()
Definition: ezpackagecreationhandler.php:273
eZPackageCreationHandler\initializeStep
initializeStep( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:171
eZPackageCreationHandler\packageType
packageType( $package, &$persistentData)
Definition: ezpackagecreationhandler.php:477
eZPackageCreationHandler\$ValidateStepMethodMap
$ValidateStepMethodMap
Definition: ezpackagecreationhandler.php:22
eZPackageCreationHandler\$LoadStepMethodMap
$LoadStepMethodMap
Definition: ezpackagecreationhandler.php:24
eZPackageCreationHandler\commitPackageMaintainer
commitPackageMaintainer( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:883
eZPackageCreationHandler\validatePackageMaintainer
validatePackageMaintainer( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:848
eZPackageCreationHandler\validatePackageThumbnail
validatePackageThumbnail( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:931
eZPackageCreationHandler\packageInformationStep
packageInformationStep()
Definition: ezpackagecreationhandler.php:378
eZPackageCreationHandler\httpFileIsImage
static httpFileIsImage( $httpFileName, &$errorList)
Definition: ezpackagecreationhandler.php:959
eZPackageCreationHandler\packageThumbnailStep
packageThumbnailStep()
Definition: ezpackagecreationhandler.php:424
eZPackageCreationHandler\packageInstallType
packageInstallType( $package, &$persistentData)
Definition: ezpackagecreationhandler.php:441
eZPackageCreationHandler\__construct
__construct( $id, $name, $steps)
Definition: ezpackagecreationhandler.php:33
eZPackageCreationHandler\initializePackageThumbnail
initializePackageThumbnail( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:923
eZPackageCreationHandler\commitStep
commitStep( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:247
eZPackageCreationHandler\stepTemplate
stepTemplate( $step)
Definition: ezpackagecreationhandler.php:154
eZPackageCreationHandler\packageChangelogStep
packageChangelogStep()
Definition: ezpackagecreationhandler.php:409
eZPackageCreationHandler\initializePackageInformation
initializePackageInformation( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:611
eZPackageCreationHandler\generatePackageInformation
generatePackageInformation(&$packageInformation, $package, $http, $step, &$persistentData)
Definition: ezpackagecreationhandler.php:603
eZPackageCreationHandler\stepMap
& stepMap()
Definition: ezpackagecreationhandler.php:149
eZPackageCreationHandler\validatePackageChangelog
validatePackageChangelog( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:753
eZPackageCreationHandler\validateStepMethodMap
validateStepMethodMap()
Definition: ezpackagecreationhandler.php:135
eZPackageCreationHandler\generateStepMap
generateStepMap( $package, &$persistentData)
Definition: ezpackagecreationhandler.php:53
eZPackageCreationHandler\appendLicence
static appendLicence( $package)
Definition: ezpackagecreationhandler.php:1000
eZPackageCreationHandler\validateAndAdvanceStep
validateAndAdvanceStep( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezpackagecreationhandler.php:229
eZPackageCreationHandler\creatorList
static & creatorList( $checkRoles=false)
Definition: ezpackagecreationhandler.php:289
eZPackageCreationHandler\hasAttribute
hasAttribute( $name)
Definition: ezpackagecreationhandler.php:109
eZPackageCreationHandler\createPackage
createPackage(&$package, $http, &$persistentData, &$cleanupFiles, $storePackage=true)
Definition: ezpackagecreationhandler.php:493
eZPackageCreationHandler\packageMaintainerStep
packageMaintainerStep()
Definition: ezpackagecreationhandler.php:393
eZPackageCreationHandler\initializePackageMaintainer
initializePackageMaintainer( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:831
eZPackageCreationHandler\loadStepMethodMap
loadStepMethodMap()
Definition: ezpackagecreationhandler.php:130
eZPackageCreationHandler\attribute
attribute( $name)
Definition: ezpackagecreationhandler.php:114
eZPackageCreationHandler\commitPackageThumbnail
commitPackageThumbnail( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:992
eZPackageCreationHandler\$Attributes
$Attributes
Definition: ezpackagecreationhandler.php:20
eZPackageCreationHandler\finalize
finalize(&$package, $http, &$persistentData)
Definition: ezpackagecreationhandler.php:265
eZPackageCreationHandler\$StepMap
$StepMap
Definition: ezpackagecreationhandler.php:25
eZPackageCreationHandler\checkPackageMaintainer
checkPackageMaintainer( $package, &$persistentData)
Definition: ezpackagecreationhandler.php:893
eZPackageCreationHandler\packageInitialState
packageInitialState( $package, &$persistentData)
Definition: ezpackagecreationhandler.php:453
eZPackageCreationHandler\commitStepMethodMap
commitStepMethodMap()
Definition: ezpackagecreationhandler.php:140
eZPackageCreationHandler\instance
static instance( $handlerName)
Definition: ezpackagecreationhandler.php:346
eZPackageCreationHandler\initializePackageChangelog
initializePackageChangelog( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:730
eZPackageCreationHandler\loadStep
loadStep( $package, $http, $currentStepID, &$persistentData, $tpl, &$module)
Definition: ezpackagecreationhandler.php:187
eZPackageCreationHandler\commitPackageInformation
commitPackageInformation( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:722
eZPackageCreationHandler\$InitializeStepMethodMap
$InitializeStepMethodMap
Definition: ezpackagecreationhandler.php:21
eZPackageCreationHandler\attributes
attributes()
Definition: ezpackagecreationhandler.php:104
eZPackageCreationHandler\initialChangelogEntry
initialChangelogEntry( $package, $http, $step, &$persistentData, $tpl)
Definition: ezpackagecreationhandler.php:464
eZPackage
Maintains eZ Publish packages.
Definition: ezpackage.php:20
eZPackage\fetch
static fetch( $packageName, $packagePath=false, $repositoryID=false, $dbAvailable=true)
Definition: ezpackage.php:1358
eZPackage\create
static create( $name, $parameters=array(), $repositoryPath=false, $repositoryID=false)
Definition: ezpackage.php:165
eZPackage\fetchMaintainerRoleIDList
static fetchMaintainerRoleIDList( $packageType=false, $checkRoles=false)
Definition: ezpackage.php:371
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
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+.