|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZContentObjectPackageInstaller class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \ingroup package 00013 \class eZContentObjectPackageInstaller ezcontentobjectpackageinstaller.php 00014 \brief A package creator for content objects 00015 */ 00016 00017 class eZContentObjectPackageInstaller extends eZPackageInstallationHandler 00018 { 00019 00020 function eZContentObjectPackageInstaller( $package, $type, $installItem ) 00021 { 00022 $steps = array(); 00023 $steps[] = array( 'id' => 'site_access', 00024 'name' => ezpI18n::tr( 'kernel/package', 'Site access mapping' ), 00025 'methods' => array( 'initialize' => 'initializeSiteAccess', 00026 'validate' => 'validateSiteAccess' ), 00027 'template' => 'site_access.tpl' ); 00028 $steps[] = array( 'id' => 'top_nodes', 00029 'name' => ezpI18n::tr( 'kernel/package', 'Top node placements' ), 00030 'methods' => array( 'initialize' => 'initializeTopNodes', 00031 'validate' => 'validateTopNodes' ), 00032 'template' => 'top_nodes.tpl' ); 00033 $steps[] = array( 'id' => 'advanced_options', 00034 'name' => ezpI18n::tr( 'kernel/package', 'Advanced options' ), 00035 'methods' => array( 'initialize' => 'initializeAdvancedOptions', 00036 'validate' => 'validateAdvancedOptions' ), 00037 'template' => 'advanced_options.tpl' ); 00038 $this->eZPackageInstallationHandler( $package, 00039 $type, 00040 $installItem, 00041 ezpI18n::tr( 'kernel/package', 'Content object import' ), 00042 $steps ); 00043 } 00044 00045 /*! 00046 Returns \c 'stable', content class packages are always stable. 00047 */ 00048 function packageInitialState( $package, &$persistentData ) 00049 { 00050 return 'stable'; 00051 } 00052 00053 /*! 00054 \return \c 'contentobject'. 00055 */ 00056 function packageType( $package, &$persistentData ) 00057 { 00058 return 'contentobject'; 00059 } 00060 00061 function initializeSiteAccess( $package, $http, $step, &$persistentData, $tpl, $module ) 00062 { 00063 $ini = eZINI::instance(); 00064 $availableSiteAccessArray = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' ); 00065 00066 if ( !isset( $persistentData['site_access_map'] ) ) 00067 { 00068 $persistentData['site_access_map'] = array(); 00069 $persistentData['site_access_available'] = $availableSiteAccessArray; 00070 $rootDOMNode = $this->rootDOMNode(); 00071 $siteAccessListNode = $rootDOMNode->getElementsByTagName( 'site-access-list' )->item( 0 ); 00072 00073 foreach( $siteAccessListNode->getElementsByTagName( 'site-access' ) as $siteAccessNode ) 00074 { 00075 $originalSiteAccessName = $siteAccessNode->textContent; 00076 if ( in_array( $originalSiteAccessName, $availableSiteAccessArray ) ) 00077 { 00078 $persistentData['site_access_map'][$originalSiteAccessName] = $originalSiteAccessName; 00079 } 00080 else 00081 { 00082 $persistentData['site_access_map'][$originalSiteAccessName] = ''; 00083 } 00084 } 00085 } 00086 00087 $tpl->setVariable( 'site_access_map', $persistentData['site_access_map'] ); 00088 $tpl->setVariable( 'available_site_access_array', $availableSiteAccessArray ); 00089 } 00090 00091 function validateSiteAccess( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList ) 00092 { 00093 $validate = true; 00094 foreach( $persistentData['site_access_map'] as $originalSiteAccess => $newSiteAccess ) 00095 { 00096 $persistentData['site_access_map'][$originalSiteAccess] = $http->postVariable( 'SiteAccessMap_'.$originalSiteAccess ); 00097 if ( !in_array( $persistentData['site_access_map'][$originalSiteAccess], $persistentData['site_access_available'] ) ) 00098 { 00099 $validate = false; 00100 } 00101 } 00102 00103 return $validate; 00104 } 00105 00106 function initializeTopNodes( $package, $http, $step, &$persistentData, $tpl, $module ) 00107 { 00108 if ( !isset( $persistentData['top_nodes_map'] ) ) 00109 { 00110 $persistentData['top_nodes_map'] = array(); 00111 $rootDOMNode = $this->rootDOMNode(); 00112 $topNodeListNode = $rootDOMNode->getElementsByTagName( 'top-node-list' )->item( 0 ); 00113 00114 $ini = eZINI::instance( 'content.ini' ); 00115 $defaultPlacementNodeID = $ini->variable( 'NodeSettings', 'RootNode' ); 00116 $defaultPlacementNode = eZContentObjectTreeNode::fetch( $defaultPlacementNodeID ); 00117 $defaultPlacementName = $defaultPlacementNode->attribute( 'name' ); 00118 foreach ( $topNodeListNode->getElementsByTagName( 'top-node' ) as $topNodeDOMNode ) 00119 { 00120 $persistentData['top_nodes_map'][(string)$topNodeDOMNode->getAttribute( 'node-id' )] = array( 'old_node_id' => $topNodeDOMNode->getAttribute( 'node-id' ), 00121 'name' => $topNodeDOMNode->textContent, 00122 'new_node_id' => $defaultPlacementNodeID, 00123 'new_parent_name' => $defaultPlacementName ); 00124 } 00125 } 00126 00127 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey ) 00128 { 00129 if ( $http->hasPostVariable( 'BrowseNode_' . $topNodeArrayKey ) ) 00130 { 00131 eZContentBrowse::browse( array( 'action_name' => 'SelectObjectRelationNode', 00132 'description_template' => 'design:package/installers/ezcontentobject/browse_topnode.tpl', 00133 'from_page' => '/package/install', 00134 'persistent_data' => array( 'PackageStep' => $http->postVariable( 'PackageStep' ), 00135 'InstallerType' => $http->postVariable( 'InstallerType' ), 00136 'InstallStepID' => $http->postVariable( 'InstallStepID' ), 00137 'ReturnBrowse_' . $topNodeArrayKey => 1 ) ), 00138 $module ); 00139 } 00140 else if ( $http->hasPostVariable( 'ReturnBrowse_' . $topNodeArrayKey ) && !$http->hasPostVariable( 'BrowseCancelButton' ) ) 00141 { 00142 $nodeIDArray = $http->postVariable( 'SelectedNodeIDArray' ); 00143 if ( $nodeIDArray != null ) 00144 { 00145 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] = $nodeIDArray[0]; 00146 $contentNode = eZContentObjectTreeNode::fetch( $nodeIDArray[0] ); 00147 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_parent_name'] = $contentNode->attribute( 'name' ); 00148 } 00149 } 00150 } 00151 00152 $tpl->setVariable( 'top_nodes_map', $persistentData['top_nodes_map'] ); 00153 } 00154 00155 function validateTopNodes( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList ) 00156 { 00157 $validate = true; 00158 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey ) 00159 { 00160 if ( $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] === false ) 00161 { 00162 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'Select parent nodes' ), 00163 'description' => ezpI18n::tr( 'kernel/package', 'You must assign all nodes to new parent nodes.' ) ); 00164 $validate = false; 00165 break; 00166 } 00167 } 00168 00169 return $validate; 00170 } 00171 00172 function initializeAdvancedOptions( $package, $http, $step, &$persistentData, $tpl, $module ) 00173 { 00174 if ( !isset( $persistentData['use_dates_from_package'] ) ) 00175 { 00176 $persistentData['use_dates_from_package'] = 0; 00177 } 00178 00179 $tpl->setVariable( 'use_dates_from_package', (bool)$persistentData['use_dates_from_package'] ); 00180 } 00181 00182 function validateAdvancedOptions( $package, $http, $currentStepId, &$stepMap, &$persistentData, &$errorList ) 00183 { 00184 $persistentData['use_dates_from_package'] = $http->postVariable( 'UseDatesFromPackage', 0 ); 00185 return true; 00186 } 00187 00188 function finalize( $package, $http, &$persistentData ) 00189 { 00190 eZDebug::writeDebug( 'finalize is called', __METHOD__ ); 00191 $package->installItem( $this->InstallItem, $persistentData ); 00192 } 00193 00194 } 00195 ?>