00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( 'kernel/classes/ezpackageinstallationhandler.php' );
00041
00042 class eZContentObjectPackageInstaller extends eZPackageInstallationHandler
00043 {
00044
00045
00046
00047
00048 function eZContentObjectPackageInstaller( &$package, $type, $installItem )
00049 {
00050 $steps = array();
00051 $steps[] = array( 'id' => 'site_access',
00052 'name' => ezi18n( 'kernel/package', 'Site access mapping' ),
00053 'methods' => array( 'initialize' => 'initializeSiteAccess',
00054 'validate' => 'validateSiteAccess' ),
00055 'template' => 'site_access.tpl' );
00056 $steps[] = array( 'id' => 'top_nodes',
00057 'name' => ezi18n( 'kernel/package', 'Top node placements' ),
00058 'methods' => array( 'initialize' => 'initializeTopNodes',
00059 'validate' => 'validateTopNodes' ),
00060 'template' => 'top_nodes.tpl' );
00061 $this->eZPackageInstallationHandler( $package,
00062 $type,
00063 $installItem,
00064 ezi18n( 'kernel/package', 'Content object import' ),
00065 $steps );
00066 }
00067
00068
00069
00070
00071
00072 function packageInitialState( &$package, &$persistentData )
00073 {
00074 return 'stable';
00075 }
00076
00077
00078
00079
00080 function packageType( &$package, &$persistentData )
00081 {
00082 return 'contentobject';
00083 }
00084
00085
00086
00087
00088 function initializeSiteAccess( &$package, &$http, $step, &$persistentData, &$tpl )
00089 {
00090 include_once( 'lib/ezutils/classes/ezini.php' );
00091 $ini =& eZINI::instance();
00092 $availableSiteAccessArray = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' );
00093
00094 if ( !isset( $persistentData['site_access_map'] ) )
00095 {
00096 $persistentData['site_access_map'] = array();
00097 $persistentData['site_access_available'] = $availableSiteAccessArray;
00098 $rootDOMNode = $this->rootDOMNode();
00099 $siteAccessListNode = $rootDOMNode->elementByName( 'site-access-list' );
00100
00101 foreach( $siteAccessListNode->elementsByName( 'site-access' ) as $siteAccessNode )
00102 {
00103 $originalSiteAccessName = $siteAccessNode->textContent();
00104 if ( in_array( $originalSiteAccessName, $availableSiteAccessArray ) )
00105 {
00106 $persistentData['site_access_map'][$originalSiteAccessName] = $originalSiteAccessName;
00107 }
00108 else
00109 {
00110 $persistentData['site_access_map'][$originalSiteAccessName] = '';
00111 }
00112 }
00113 }
00114
00115 $tpl->setVariable( 'site_access_map', $persistentData['site_access_map'] );
00116 $tpl->setVariable( 'available_site_access_array', $availableSiteAccessArray );
00117 }
00118
00119
00120
00121
00122 function validateSiteAccess( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00123 {
00124 $validate = true;
00125 foreach( $persistentData['site_access_map'] as $originalSiteAccess => $newSiteAccess )
00126 {
00127 $persistentData['site_access_map'][$originalSiteAccess] = $http->postVariable( 'SiteAccessMap_'.$originalSiteAccess );
00128 if ( !in_array( $persistentData['site_access_map'][$originalSiteAccess], $persistentData['site_access_available'] ) )
00129 {
00130 $validate = false;
00131 }
00132 }
00133
00134 return $validate;
00135 }
00136
00137
00138
00139
00140 function initializeTopNodes( &$package, &$http, $step, &$persistentData, &$tpl, &$module )
00141 {
00142 if ( !isset( $persistentData['top_nodes_map'] ) )
00143 {
00144 $persistentData['top_nodes_map'] = array();
00145 $rootDOMNode = $this->rootDOMNode();
00146 $topNodeListNode = $rootDOMNode->elementByName( 'top-node-list' );
00147
00148 $ini =& eZINI::instance( 'content.ini' );
00149 $defaultPlacementNodeID = $ini->variable( 'NodeSettings', 'RootNode' );
00150 $defaultPlacementNode = eZContentObjectTreeNode::fetch( $defaultPlacementNodeID );
00151 $defaultPlacementName = $defaultPlacementNode->attribute( 'name' );
00152 foreach ( $topNodeListNode->elementsByName( 'top-node' ) as $topNodeDOMNode )
00153 {
00154 $persistentData['top_nodes_map'][(string)$topNodeDOMNode->attributeValue( 'node-id' )] = array( 'old_node_id' => $topNodeDOMNode->attributeValue( 'node-id' ),
00155 'name' => $topNodeDOMNode->textContent(),
00156 'new_node_id' => $defaultPlacementNodeID,
00157 'new_parent_name' => $defaultPlacementName );
00158 }
00159 }
00160
00161 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey )
00162 {
00163 if ( $http->hasPostVariable( 'BrowseNode_' . $topNodeArrayKey ) )
00164 {
00165 include_once( 'kernel/classes/ezcontentbrowse.php' );
00166 eZContentBrowse::browse( array( 'action_name' => 'SelectObjectRelationNode',
00167 'description_template' => 'design:package/installers/ezcontentobject/browse_topnode.tpl',
00168 'from_page' => '/package/install',
00169 'persistent_data' => array( 'PackageStep' => $http->postVariable( 'PackageStep' ),
00170 'InstallerType' => $http->postVariable( 'InstallerType' ),
00171 'InstallStepID' => $http->postVariable( 'InstallStepID' ),
00172 'ReturnBrowse_' . $topNodeArrayKey => 1 ) ),
00173 $module );
00174 }
00175 else if ( $http->hasPostVariable( 'ReturnBrowse_' . $topNodeArrayKey ) && !$http->hasPostVariable( 'BrowseCancelButton' ) )
00176 {
00177 $nodeIDArray = $http->postVariable( 'SelectedNodeIDArray' );
00178 if ( $nodeIDArray != null )
00179 {
00180 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] = $nodeIDArray[0];
00181 $contentNode = eZContentObjectTreeNode::fetch( $nodeIDArray[0] );
00182 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_parent_name'] = $contentNode->attribute( 'name' );
00183 }
00184 }
00185 }
00186
00187 $tpl->setVariable( 'top_nodes_map', $persistentData['top_nodes_map'] );
00188 }
00189
00190
00191
00192
00193 function validateTopNodes( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
00194 {
00195 $validate = true;
00196 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey )
00197 {
00198 if ( $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] === false )
00199 {
00200 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Select parent nodes' ),
00201 'description' => ezi18n( 'kernel/package', 'You must assign all nodes to new parent nodes.' ) );
00202 $validate = false;
00203 break;
00204 }
00205 }
00206
00207 return $validate;
00208 }
00209
00210
00211
00212
00213 function finalize( &$package, &$http, &$persistentData )
00214 {
00215 $package->installItem( $this->InstallItem, $persistentData );
00216 }
00217
00218 }
00219 ?>