eZ Publish  [4.0]
ezwebininstall.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <26-Jun-2007 15:00:00 dl>
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 // eZWebin install Script
00031 // file  bin/php/ezwebininstall.php
00032 
00033 
00034 /*!
00035  define constans
00036 */
00037 
00038 /*!
00039  define global vars
00040 */
00041 
00042 
00043 /*!
00044  includes
00045 */
00046 include_once( 'bin/php/ezwebincommon.php' );
00047 //include_once( 'kernel/classes/ezcontentlanguage.php' );
00048 
00049 require 'autoload.php';
00050 
00051 // script initializing
00052 $cli = eZCLI::instance();
00053 $script = eZScript::instance( array( 'description' => ( "\n" .
00054                                                         "Install eZWebin package\n" ),
00055                                      'use-session' => false,
00056                                      'use-modules' => true,
00057                                      'use-extensions' => false,
00058                                      'user' => true ) );
00059 $script->startup();
00060 
00061 $scriptOptions = $script->getOptions( "[repository:][package:][package-dir:][url:][admin-siteaccess:][user-siteaccess:][auto-mode:]",
00062                                       "",
00063                                       array( 'repository' => "Path to repository where unpacked(unarchived) packages are \n" .
00064                                                          "placed. it's relative to 'var/[site.ini].[FileSettings].[StorageDir]/[package.ini].[RepositorySettings].[RepositoryDirectory]' \n".
00065                                                          "(default is 'var/storage/packages/ez_systems')",
00066                                              'package-dir' => "Path to directory with packed(ezpkg) packages(default is '/tmp/ezwebin') ",
00067                                              'url' => "URL to download packages, f.e. 'http://packages.ez.no/ezpublish/3.9'.\n" .
00068                                                       "'package-dir' can be specified to store uploaded packages on local computer.\n" .
00069                                                       "if 'package-dir' is not specified then default dir('/tmp/ezwebin') will be used.",
00070                                              'admin-siteaccess' => 'Will be used as base for eZWebin admin siteaccess',
00071                                              'user-siteaccess' => 'Will be used as base for eZWebin user siteaccesses',
00072                                              'auto-mode' => "[on/off]. Do not ask what to do in case of confilicts. By default is 'on'"
00073                                            ),
00074                                       false,
00075                                       array( 'user' => true )
00076                                      );
00077 
00078 
00079 if( !$scriptOptions['admin-siteaccess'] )
00080 {
00081     showError( "No admin siteaccess provided" );
00082 }
00083 
00084 if( !$scriptOptions['user-siteaccess'] )
00085 {
00086     showError( "No user siteaccess provided" );
00087 }
00088 
00089 $adminSiteaccess = $scriptOptions['admin-siteaccess'];
00090 $userSiteaccess = $scriptOptions['user-siteaccess'];
00091 
00092 checkSiteaccess( $adminSiteaccess, true );
00093 checkSiteaccess( $userSiteaccess, true );
00094 
00095 showNotice( "Using siteaccess '" . $adminSiteaccess . "'" );
00096 $script->setUseSiteAccess( $adminSiteaccess );
00097 
00098 $script->initialize();
00099 
00100 /**************************************************************
00101 * process options                                             *
00102 ***************************************************************/
00103 
00104 //
00105 // 'repository' option
00106 //
00107 $packageRepository = $scriptOptions['repository'];
00108 if ( !$packageRepository )
00109 {
00110     $packageRepository = repositoryByVendor( defaultVendor() );
00111 }
00112 
00113 
00114 //
00115 // 'package' option
00116 //
00117 $packageList = array(   'ezwebin_classes'
00118                       , 'ezwebin_extension'
00119                       , 'ezwebin_banners'
00120                       , 'ezwebin_democontent'
00121                       , 'ezwebin_design'
00122                       , 'ezwebin_site'
00123                     );
00124 
00125 //
00126 // 'package-dir' option
00127 //
00128 $packageDir = $scriptOptions['package-dir'] ? $scriptOptions['package-dir'] : "/tmp/ezwebin";
00129 
00130 //
00131 // 'url' option
00132 //
00133 $packageURL = $scriptOptions['url'];
00134 if ( !$packageURL )
00135 {
00136     $packageINI = eZINI::instance( 'package.ini' );
00137     $packageURL = $packageINI->variable( 'RepositorySettings', 'RemotePackagesIndexURL' );
00138 }
00139 
00140 //
00141 // 'auto-mode' option
00142 //
00143 global $autoMode;
00144 $autoMode = $scriptOptions['auto-mode'];
00145 if( $autoMode != 'off' )
00146 {
00147     $autoMode = 'on';
00148     $importDir = eZPackage::repositoryPath() . "/$packageRepository";
00149     showWarning( "Processing in auto-mode: \n".
00150                  "- packages will be downloaded to '$packageDir';\n" .
00151                  "- packages will be imported to '$importDir';\n" .
00152                  "- installing of existing classes will be skipped;\n" .
00153                  "- all files(extesion, design, downloaded and imported packages) will be overwritten;" );
00154     $action = getUserInput( "Continue? [y/n]: ");
00155     if( strpos( $action, 'y' ) !== 0 )
00156         $script->shutdown( 0, 'Done' );
00157 }
00158 
00159 /**************************************************************
00160 * do the work                                                 *
00161 ***************************************************************/
00162 
00163 if( downloadPackages( $packageList, $packageURL, $packageDir, $packageRepository ) )
00164 {
00165     if( file_exists( installScriptDir( $packageRepository ) ) )
00166     {
00167         //
00168         // Prepare siteaccesses access info.
00169         //
00170         $locales = eZContentLanguage::fetchLocaleList();
00171         $primaryLanguage = eZContentLanguage::topPriorityLanguage();
00172 
00173         $siteINI = eZINI::instance();
00174         $matchOrder = $siteINI->variableArray( 'SiteAccessSettings', 'MatchOrder' );
00175         $accessType = $matchOrder[0];
00176         $accessTypeValue = 'ezwebin_site';
00177         $adminAccessTypeValue = 'ezwebin_site_admin';
00178 
00179         $package = eZPackage::fetch( 'ezwebin_site' );
00180 
00181         if( $accessType == 'port' )
00182         {
00183             $portAccessList = $siteINI->group( 'PortAccessSettings' );
00184             $usedPorts = array_keys( $portAccessList );
00185             foreach( $portAccessList as $port => $siteaccess )
00186             {
00187                 if( $siteaccess == $userSiteaccess )
00188                 {
00189                     while( in_array( $port, $usedPorts ) )
00190                     {
00191                         // $port is used => get next port
00192                         ++$port;
00193                     }
00194 
00195                     $accessTypeValue = $port;
00196                     $usedPorts[] = $port;
00197                 }
00198                 else if( $siteaccess == $adminSiteaccess )
00199                 {
00200                     while( in_array( $port, $usedPorts ) )
00201                     {
00202                         // $port is used => get next port
00203                         ++$port;
00204                     }
00205 
00206                     $adminAccessTypeValue = $port;
00207                     $usedPorts[] = $port;
00208                 }
00209             }
00210         }
00211 
00212         //
00213         // Prepare install params.
00214         //
00215         $params = array( 'object_remote_map' => array( '1bb4fe25487f05527efa8bfd394cecc7' => 14,
00216                                                        '5f7f0bdb3381d6a461d8c29ff53d908f' => 11,
00217                                                        '15b256dbea2ae72418ff5facc999e8f9' => 42 ),
00218                          'package_object' => $package,
00219                          'design_list' => array( 'ezwebin_site',
00220                                                  'admin' ),
00221                          'user_siteaccess' => 'ezwebin_site',
00222                          'admin_siteaccess' => 'ezwebin_site_admin',
00223                          'site_type' => array( 'access_type' => $accessType,
00224                                                'access_type_value' => $accessTypeValue,
00225                                                'admin_access_type_value' => $adminAccessTypeValue ),
00226                          'all_language_codes' => $locales,
00227                          'primary_language' => $primaryLanguage->attribute( 'locale' ),
00228                          'host' => $siteINI->variable( 'SiteSettings', 'SiteURL' ) );
00229 
00230         $user = eZUser::currentUser();
00231 
00232         $installParameters = array( 'site_access_map' => array( '*' => $userSiteaccess ),
00233                                     'top_nodes_map' => array( '*' => 2 ),
00234                                     'design_map' => array( '*' => 'ezwebin_site' ),
00235                                     'language_map' => array( 'eng-GB' => $primaryLanguage->attribute( 'locale' ) ),
00236                                     'restore_dates' => true,
00237                                     'user_id' => $user->attribute( 'contentobject_id' ),
00238                                     'non-interactive' => true );
00239 
00240         //
00241         // Do the job
00242         //
00243         include_once( installScriptDir( $packageRepository ) . "/settings/ezwebininstaller.php" );
00244         $webinInstaller = new eZWebinInstaller( $params );
00245 
00246         if( defined( 'EZWEBIN_INSTALLER_MAJOR_VERSION' ) && EZWEBIN_INSTALLER_MAJOR_VERSION >= "1.3" )
00247         {
00248 
00249             $webinInstaller->createSiteAccess( array( 'src' => array( 'siteaccess' => $adminSiteaccess ),
00250                                                       'dst' => array( 'siteaccess' => 'ezwebin_site_admin' ) ) );
00251             $webinInstaller->createSiteAccess( array( 'src' => array( 'siteaccess' => $userSiteaccess ),
00252                                                       'dst' => array( 'siteaccess' => 'ezwebin_site' ) ) );
00253 
00254             $webinInstaller->preInstall();
00255 
00256             installPackages( $packageList, $installParameters );
00257 
00258             $webinInstaller->install();
00259 
00260             $siteaccessUrls = $webinInstaller->setting( 'siteaccess_urls' );
00261         }
00262         else
00263         {
00264             //
00265             // BC for eZWebin < 1.3
00266             //
00267 
00268             //include_once( 'kernel/classes/ezsiteinstaller.php' );
00269 
00270             $siteInstaller = new eZSiteInstaller();
00271 
00272             $params['locales'] = $params['all_language_codes'];
00273 
00274             // extra siteaccess based on languages info, like 'eng', 'rus', ...
00275             $params['language_based_siteaccess_list'] = $siteInstaller->languageNameListFromLocaleList( $params['locales'] );
00276 
00277             $params['user_siteaccess_list'] = array_merge( array( $params['user_siteaccess'] ),
00278                                                            $params['language_based_siteaccess_list'] );
00279             $params['all_siteaccess_list'] = array_merge( $params['user_siteaccess_list'],
00280                                                           $params['admin_siteaccess'] );
00281             $params['main_site_design'] = 'ezwebin';
00282 
00283 
00284             // Create siteaccesses URLs
00285             $siteaccessUrls = array( 'admin'       => $siteInstaller->createSiteaccessUrls( array( 'siteaccess_list' => array( $params['admin_siteaccess'] ),
00286                                                                                                    'access_type' => $accessType,
00287                                                                                                    'port' => $adminAccessTypeValue,
00288                                                                                                    'host' => $params['host'] ) ),
00289                                      'user'        => $siteInstaller->createSiteaccessUrls( array( 'siteaccess_list' => array( $params['user_siteaccess'] ),
00290                                                                                                    'access_type' => $accessType,
00291                                                                                                    'port' => $accessTypeValue,
00292                                                                                                    'host' => $params['host'] ) ),
00293                                      'translation' => $siteInstaller->createSiteaccessUrls( array( 'siteaccess_list' => $params['language_based_siteaccess_list'],
00294                                                                                                    'access_type' => $accessType,
00295                                                                                                    'port' => $accessTypeValue + 1, // $accessTypeValue is for 'ezwein_site_user', so take next port number.
00296                                                                                                    'host' => $params['host'],
00297                                                                                                    'exclude_port_list' => array( $adminAccessTypeValue,
00298                                                                                                                                  $accessTypeValue ) ) ) );
00299             $params['siteaccess_urls'] = $siteaccessUrls;
00300 
00301             // prepare 'admin_url' for 'eZSiteINISettings'. Will unset it later.
00302             $params['siteaccess_urls']['admin_url'] = $siteaccessUrls['admin']['ezwebin_site_admin']['url'];
00303 
00304             // Include setting files
00305             $settingsFiles = $package->attribute( 'settings-files' );
00306             foreach( $settingsFiles as $settingsFileName )
00307                 include_once( installScriptDir( $packageRepository ) . '/settings/' . $settingsFileName );
00308 
00309             $siteInstaller->createSiteAccess( array( 'src' => array( 'siteaccess' => $adminSiteaccess ),
00310                                                      'dst' => array( 'siteaccess' => 'ezwebin_site_admin' ) ) );
00311             $siteInstaller->createSiteAccess( array( 'src' => array( 'siteaccess' => $userSiteaccess ),
00312                                                      'dst' => array( 'siteaccess' => 'ezwebin_site' ) ) );
00313 
00314             // Call user function for additional setup tasks.
00315             if ( function_exists( 'eZSitePreInstall' ) )
00316                 eZSitePreInstall();
00317 
00318             installPackages( $packageList, $installParameters );
00319 
00320             $settings = array();
00321             $settings[] = array( 'settings_dir' => 'settings/siteaccess/' . $params['user_siteaccess'],
00322                                  'groups' => eZSiteINISettings( $params ) );
00323             $settings[] = array( 'settings_dir' => 'settings/siteaccess/' . $params['admin_siteaccess'],
00324                                  'groups' => eZSiteAdminINISettings( $params ) );
00325             $settings[] = array( 'settings_dir' => 'settings/override',
00326                                  'groups' => eZSiteCommonINISettings( $params ) );
00327 
00328 
00329             foreach( $settings as $settingsGroup )
00330             {
00331                 resetINI( $settingsGroup, 'override.ini' );
00332                 $siteInstaller->updateINIFiles( $settingsGroup );
00333             }
00334 
00335             // 'admin_url' is not needed anymore.
00336             unset( $params['siteaccess_urls']['admin_url'] );
00337 
00338             updateINIAccessType( $accessType, $params );
00339 
00340             $siteInstaller->updateRoles( array( 'roles' => eZSiteRoles( $params ) ) );
00341             $siteInstaller->updatePreferences( array( 'prefs' => eZSitePreferences( $params ) ) );
00342 
00343             setVersion( 'ezwebin', '1.2.0' );
00344 
00345             postInstallAdminSiteaccessINIUpdate( $params );
00346             postInstallUserSiteaccessINIUpdate( $params );
00347             createTranslationSiteAccesses( $params );
00348 
00349             // updateTemplateLookClassAttributes() and updateTemplateLookObjectAttributes();
00350             $classIdentifier = 'template_look';
00351             $newAttributeIdArr = expandClass( $classIdentifier );
00352             foreach( $newAttributeIdArr as $id )
00353             {
00354                 updateObject( $classIdentifier, $id );
00355             }
00356             $templateLookData = templateLookObjectData( $params );
00357             $siteInstaller->updateContentObjectAttributes( array( 'object_id' => $webinInstaller->setting( 'template_look_object_id' ),
00358                                                                   'attributes_data' => $templateLookData ) );
00359 
00360 
00361             $siteInstaller->swapNodes( array( 'src_node' => array( 'name' => "eZ Publish" ),
00362                                               'dst_node' => array( 'name' => "Home" ) ) );
00363             $siteInstaller->removeContentObject( array( 'name' => 'eZ Publish' ) );
00364 
00365             $webinInstaller->postInstall();
00366         }
00367 
00368         //
00369         // Output installation status.
00370         //
00371         showMessage2( 'Installation complete.' );
00372 
00373         showMessage( 'URLs to access eZWebin sites:' );
00374 
00375         foreach( $siteaccessUrls as $siteaccessType => $siteaccessInfo )
00376         {
00377             showMessage( "  $siteaccessType:" );
00378             foreach( $siteaccessInfo as $siteaccessName => $urlInfo )
00379             {
00380                 showMessage( "    $siteaccessName: " . $urlInfo['url'] );
00381             }
00382         }
00383     }
00384     else
00385     {
00386         showWarning( "Unable to find installtion script dir." );
00387     }
00388 }
00389 
00390 
00391 $script->shutdown( 0, 'Done' );
00392 
00393 ?>