|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZContentObjectPackageInstaller class 00004 // 00005 // Created on: <01-Apr-2004 12:39:59 kk> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezcontentobjectpackageinstaller.php 00032 */ 00033 00034 /*! 00035 \ingroup package 00036 \class eZContentObjectPackageInstaller ezcontentobjectpackageinstaller.php 00037 \brief A package creator for content objects 00038 */ 00039 00040 //include_once( 'kernel/classes/ezpackageinstallationhandler.php' ); 00041 00042 class eZContentObjectPackageInstaller extends eZPackageInstallationHandler 00043 { 00044 00045 /*! 00046 \reimp 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 $steps[] = array( 'id' => 'advanced_options', 00062 'name' => ezi18n( 'kernel/package', 'Advanced options' ), 00063 'methods' => array( 'initialize' => 'initializeAdvancedOptions', 00064 'validate' => 'validateAdvancedOptions' ), 00065 'template' => 'advanced_options.tpl' ); 00066 $this->eZPackageInstallationHandler( $package, 00067 $type, 00068 $installItem, 00069 ezi18n( 'kernel/package', 'Content object import' ), 00070 $steps ); 00071 } 00072 00073 /*! 00074 \reimp 00075 Returns \c 'stable', content class packages are always stable. 00076 */ 00077 function packageInitialState( $package, &$persistentData ) 00078 { 00079 return 'stable'; 00080 } 00081 00082 /*! 00083 \return \c 'contentobject'. 00084 */ 00085 function packageType( $package, &$persistentData ) 00086 { 00087 return 'contentobject'; 00088 } 00089 00090 /*! 00091 \reimp 00092 */ 00093 function initializeSiteAccess( $package, $http, $step, &$persistentData, $tpl, $module ) 00094 { 00095 //include_once( 'lib/ezutils/classes/ezini.php' ); 00096 $ini = eZINI::instance(); 00097 $availableSiteAccessArray = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' ); 00098 00099 if ( !isset( $persistentData['site_access_map'] ) ) 00100 { 00101 $persistentData['site_access_map'] = array(); 00102 $persistentData['site_access_available'] = $availableSiteAccessArray; 00103 $rootDOMNode = $this->rootDOMNode(); 00104 $siteAccessListNode = $rootDOMNode->getElementsByTagName( 'site-access-list' )->item( 0 ); 00105 00106 foreach( $siteAccessListNode->getElementsByTagName( 'site-access' ) as $siteAccessNode ) 00107 { 00108 $originalSiteAccessName = $siteAccessNode->textContent; 00109 if ( in_array( $originalSiteAccessName, $availableSiteAccessArray ) ) 00110 { 00111 $persistentData['site_access_map'][$originalSiteAccessName] = $originalSiteAccessName; 00112 } 00113 else 00114 { 00115 $persistentData['site_access_map'][$originalSiteAccessName] = ''; 00116 } 00117 } 00118 } 00119 00120 $tpl->setVariable( 'site_access_map', $persistentData['site_access_map'] ); 00121 $tpl->setVariable( 'available_site_access_array', $availableSiteAccessArray ); 00122 } 00123 00124 /*! 00125 \reimp 00126 */ 00127 function validateSiteAccess( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList ) 00128 { 00129 $validate = true; 00130 foreach( $persistentData['site_access_map'] as $originalSiteAccess => $newSiteAccess ) 00131 { 00132 $persistentData['site_access_map'][$originalSiteAccess] = $http->postVariable( 'SiteAccessMap_'.$originalSiteAccess ); 00133 if ( !in_array( $persistentData['site_access_map'][$originalSiteAccess], $persistentData['site_access_available'] ) ) 00134 { 00135 $validate = false; 00136 } 00137 } 00138 00139 return $validate; 00140 } 00141 00142 /*! 00143 \reimp 00144 */ 00145 function initializeTopNodes( $package, $http, $step, &$persistentData, $tpl, $module ) 00146 { 00147 if ( !isset( $persistentData['top_nodes_map'] ) ) 00148 { 00149 $persistentData['top_nodes_map'] = array(); 00150 $rootDOMNode = $this->rootDOMNode(); 00151 $topNodeListNode = $rootDOMNode->getElementsByTagName( 'top-node-list' )->item( 0 ); 00152 00153 $ini = eZINI::instance( 'content.ini' ); 00154 $defaultPlacementNodeID = $ini->variable( 'NodeSettings', 'RootNode' ); 00155 $defaultPlacementNode = eZContentObjectTreeNode::fetch( $defaultPlacementNodeID ); 00156 $defaultPlacementName = $defaultPlacementNode->attribute( 'name' ); 00157 foreach ( $topNodeListNode->getElementsByTagName( 'top-node' ) as $topNodeDOMNode ) 00158 { 00159 $persistentData['top_nodes_map'][(string)$topNodeDOMNode->getAttribute( 'node-id' )] = array( 'old_node_id' => $topNodeDOMNode->getAttribute( 'node-id' ), 00160 'name' => $topNodeDOMNode->textContent, 00161 'new_node_id' => $defaultPlacementNodeID, 00162 'new_parent_name' => $defaultPlacementName ); 00163 } 00164 } 00165 00166 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey ) 00167 { 00168 if ( $http->hasPostVariable( 'BrowseNode_' . $topNodeArrayKey ) ) 00169 { 00170 //include_once( 'kernel/classes/ezcontentbrowse.php' ); 00171 eZContentBrowse::browse( array( 'action_name' => 'SelectObjectRelationNode', 00172 'description_template' => 'design:package/installers/ezcontentobject/browse_topnode.tpl', 00173 'from_page' => '/package/install', 00174 'persistent_data' => array( 'PackageStep' => $http->postVariable( 'PackageStep' ), 00175 'InstallerType' => $http->postVariable( 'InstallerType' ), 00176 'InstallStepID' => $http->postVariable( 'InstallStepID' ), 00177 'ReturnBrowse_' . $topNodeArrayKey => 1 ) ), 00178 $module ); 00179 } 00180 else if ( $http->hasPostVariable( 'ReturnBrowse_' . $topNodeArrayKey ) && !$http->hasPostVariable( 'BrowseCancelButton' ) ) 00181 { 00182 $nodeIDArray = $http->postVariable( 'SelectedNodeIDArray' ); 00183 if ( $nodeIDArray != null ) 00184 { 00185 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] = $nodeIDArray[0]; 00186 $contentNode = eZContentObjectTreeNode::fetch( $nodeIDArray[0] ); 00187 $persistentData['top_nodes_map'][$topNodeArrayKey]['new_parent_name'] = $contentNode->attribute( 'name' ); 00188 } 00189 } 00190 } 00191 00192 $tpl->setVariable( 'top_nodes_map', $persistentData['top_nodes_map'] ); 00193 } 00194 00195 /*! 00196 \reimp 00197 */ 00198 function validateTopNodes( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList ) 00199 { 00200 $validate = true; 00201 foreach( array_keys( $persistentData['top_nodes_map'] ) as $topNodeArrayKey ) 00202 { 00203 if ( $persistentData['top_nodes_map'][$topNodeArrayKey]['new_node_id'] === false ) 00204 { 00205 $errorList[] = array( 'field' => ezi18n( 'kernel/package', 'Select parent nodes' ), 00206 'description' => ezi18n( 'kernel/package', 'You must assign all nodes to new parent nodes.' ) ); 00207 $validate = false; 00208 break; 00209 } 00210 } 00211 00212 return $validate; 00213 } 00214 00215 function initializeAdvancedOptions( $package, $http, $step, &$persistentData, $tpl, $module ) 00216 { 00217 if ( !isset( $persistentData['use_dates_from_package'] ) ) 00218 { 00219 $persistentData['use_dates_from_package'] = 0; 00220 } 00221 00222 $tpl->setVariable( 'use_dates_from_package', (bool)$persistentData['use_dates_from_package'] ); 00223 } 00224 00225 function validateAdvancedOptions( $package, $http, $currentStepId, &$stepMap, &$persistentData, &$errorList ) 00226 { 00227 $persistentData['use_dates_from_package'] = $http->postVariable( 'UseDatesFromPackage', 0 ); 00228 return true; 00229 } 00230 00231 /*! 00232 \reimp 00233 */ 00234 function finalize( $package, $http, &$persistentData ) 00235 { 00236 eZDebug::writeDebug( 'finalize is called', __METHOD__ ); 00237 $package->installItem( $this->InstallItem, $persistentData ); 00238 } 00239 00240 } 00241 ?>