eZ Publish  [4.0]
ezwebinupgrade.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <18-Apr-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 upgrade Script
00031 // file  bin/php/ezwebinupgrade.php
00032 
00033 
00034 /*!
00035  define constans
00036 */
00037 
00038 /*!
00039  define global vars
00040 */
00041 
00042 /*!
00043  includes
00044 */
00045 require 'autoload.php';
00046 include_once( 'bin/php/ezwebincommon.php' );
00047 
00048 
00049 function execUpdateFunction( $funcName, $toVersion )
00050 {
00051     $funcName = "$funcName" . "_" . preg_replace( "/[.-]/", "_", $toVersion );
00052 
00053     if ( function_exists( $funcName ) )
00054     {
00055         $funcName();
00056     }
00057 }
00058 
00059 function upgradePackageListByWebinVersion( $version )
00060 {
00061     $packageList = false;
00062 
00063     switch ( $version )
00064     {
00065         case '1.2-0':
00066             {
00067                 $packageList = array(   'ezwebin_classes'
00068                                       , 'ezwebin_extension'
00069                                       // skipping content for now
00070                                       //, 'ezwebin_banners'
00071                                       //, 'ezwebin_democontent'
00072                                       , 'ezwebin_design'
00073                                       , 'ezwebin_site' );
00074             } break;
00075         case '1.3-0':
00076             {
00077                 $packageList = array(   'ezwebin_classes'
00078                                       , 'ezwebin_extension'
00079                                       // skipping content for now
00080                                       //, 'ezwebin_banners'
00081                                       //, 'ezwebin_democontent'
00082                                       , 'ezwebin_design_blue'
00083                                       , 'ezwebin_design_gray'
00084                                       , 'ezwebin_site' );
00085             } break;
00086         default:
00087             break;
00088     }
00089 
00090     return $packageList;
00091 
00092 }
00093 
00094 /*!
00095  update content classes
00096 */
00097 function updateClasses_1_2_0()
00098 {
00099     $installer = new eZWebinInstaller();
00100 
00101     $installer->addClassAttributes( array( 'class' => array( 'identifier' => 'folder' ),
00102                                            'attributes' => array( array( 'identifier' => 'tags',
00103                                                                          'name' => 'Tags',
00104                                                                          'data_type_string' => 'ezkeyword' ),
00105                                                                   array( 'identifier' => 'publish_date',
00106                                                                          'name' => 'Publish date',
00107                                                                          'data_type_string' => 'ezdatetime',
00108                                                                          'default_value' => 0 ) ) ) );
00109 
00110     $installer->addClassAttributes( array( 'class' => array( 'identifier' => 'template_look' ),
00111                                            'attributes' => array( array( 'data_type_string' => 'ezurl',
00112                                                                          'name' => 'Tag Cloud URL',
00113                                                                          'identifier' => 'tag_cloud_url' ) ) ) );
00114 
00115     $installer->updateClassAttributes( array( 'class' => array( 'identifier' => 'folder' ),
00116                                               'attributes' => array( array( 'identifier' => 'show_children',
00117                                                                             'new_name' => 'Display sub items' ) ) ) );
00118 
00119     $installer->setRSSExport( array( 'creator' => '14',
00120                                      'access_url' => 'my_feed',
00121                                      'main_node_only' => '1',
00122                                      'number_of_objects' => '10',
00123                                      'rss_version' => '2.0',
00124                                      'status' => '1',
00125                                      'title' => 'My RSS Feed',
00126                                      'rss_export_itmes' => array( 0 => array( 'class_id' => '16',
00127                                                                               'description' => 'intro',
00128                                                                               'source_node_id' => '153',
00129                                                                               'status' => '1',
00130                                                                               'title' => 'title' ) ) ) );
00131 }
00132 
00133 /*!
00134  update content objects
00135 */
00136 function updateObjects_1_2_0()
00137 {
00138     $installer = new eZWebinInstaller();
00139 
00140     $templateLookData = array( "tag_cloud_url" => array( "DataText" => "Tag cloud",
00141                                                          "Content" => "/content/view/tagcloud/2" ),
00142                                "footer_text" => array( "DataText" => "Copyright &#169; 2007 eZ Systems AS. All rights reserved." ) );
00143 
00144     $installer->updateContentObjectAttributes( array( 'object_id' => $installer->setting( 'template_look_object_id' ),
00145                                                       'attributes_data' => $templateLookData ) );
00146 }
00147 
00148 
00149 /*!
00150 */
00151 function updateINI_1_2_0()
00152 {
00153     showMessage2( "Updating INI-files..." );
00154 
00155     $siteaccessList = getUserInput( "Please specify the eZ webin siteaccesses on your site (separated with space, for example eng nor): ");
00156     $siteaccessList = explode( ' ', $siteaccessList );
00157 
00158     $ezWebinSiteacceses = siteAccessMap( $siteaccessList );
00159 
00160     $parameters = array();
00161 
00162     $extraSettings = array();
00163     $extraSettings[] = eZSiteOverrideINISettings();
00164     $extraSettings[] = eZSiteImageINISettings();
00165     $extraSettings[] = eZSiteContentINISettings( $parameters );
00166     $extraSettings[] = eZSiteDesignINISettings( $parameters );
00167     $extraSettings[] = eZSiteBrowseINISettings( $parameters );
00168     $extraSettings[] = eZSiteTemplateINISettings( $parameters );
00169 
00170     $extraCommonSettings = array();
00171     $extraCommonSettings[] = eZCommonContentINISettings( $parameters );
00172 
00173     //The following INI-files should be modified instead of being replaced
00174     $modifiableINIFiles = array();
00175     $modifiableINIFiles[] = 'design.ini';
00176 
00177 
00178     foreach ( $ezWebinSiteacceses as $sa )
00179     {
00180         if( $sa and is_array( $sa ) )
00181         {
00182             $saName = key($sa);
00183             $saPath = current($sa);
00184 
00185             // NOTE: it's copy/paste from ezstep_create_sites.php
00186             foreach ( $extraSettings as $extraSetting )
00187             {
00188                 if ( $extraSetting === false )
00189                     continue;
00190 
00191                 $iniName = $extraSetting['name'];
00192                 $settings = $extraSetting['settings'];
00193                 $resetArray = false;
00194                 if ( isset( $extraSetting['reset_arrays'] ) )
00195                     $resetArray = $extraSetting['reset_arrays'];
00196 
00197                 if ( in_array( $iniName, $modifiableINIFiles ) )
00198                 {
00199                     //Certain INI files we don't want to replace fully, for instance design.ini can have other values for sitestyles.
00200                     $iniToModify = $iniName . '.append.php';
00201                     $tmpINI = eZINI::instance( $iniToModify, $saPath );
00202                     // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables.
00203                     $tmpINI->setReadOnlySettingsCheck( false );
00204                     $tmpINI->setVariables( $settings );
00205                     $tmpINI->save( false, false, false, false, $saPath, $resetArray );
00206                 }
00207                 else
00208                 {
00209                     //Replace new INI files eZ webin 1.2 accordingly.
00210                     $tmpINI = eZINI::create( $iniName );
00211                     // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables.
00212                     $tmpINI->setReadOnlySettingsCheck( false );
00213                     $tmpINI->setVariables( $settings );
00214                     $tmpINI->save( false, '.append.php', false, true, $saPath, $resetArray );
00215                 }
00216             }
00217         }
00218     }
00219 
00220     foreach ( $extraCommonSettings as $extraSetting )
00221     {
00222         if ( $extraSetting === false )
00223             continue;
00224 
00225         $iniName = $extraSetting['name'];
00226         $settings = $extraSetting['settings'];
00227         $resetArray = false;
00228         if ( isset( $extraSetting['reset_arrays'] ) )
00229             $resetArray = $extraSetting['reset_arrays'];
00230 
00231         if ( file_exists( 'settings/override/' . $iniName . '.append' ) ||
00232              file_exists( 'settings/override/' . $iniName . '.append.php' ) )
00233         {
00234             $tmpINI = eZINI::instance( $iniName, 'settings/override', null, null, false, true );
00235         }
00236         else
00237         {
00238             $tmpINI = eZINI::create( $iniName );
00239         }
00240         // Set ReadOnlySettingsCheck to false: towards
00241         // Ignore site.ini[eZINISettings].ReadonlySettingList[] settings when saving ini variables.
00242         $tmpINI->setReadOnlySettingsCheck( false );
00243         $tmpINI->setVariables( $settings );
00244         $tmpINI->save( false, '.append.php', false, true, "settings/override", $resetArray );
00245     }
00246 }
00247 
00248 
00249 function isValidWebinUpgradeVersion( $version )
00250 {
00251     $isValid = false;
00252 
00253     switch( $version )
00254     {
00255         case '1.2-0':
00256         case '1.3-0':
00257             {
00258                 $isValid = true;
00259             } break;
00260         default:
00261             break;
00262     }
00263 
00264     return $isValid;
00265 }
00266 
00267 // script initializing
00268 $cli = eZCLI::instance();
00269 $script = eZScript::instance( array( 'description' => ( "\n" .
00270                                                         "This script will upgrade ezwebin." ),
00271                                      'use-session' => false,
00272                                      'use-modules' => true,
00273                                      'use-extensions' => false,
00274                                      'user' => true ) );
00275 $script->startup();
00276 
00277 $scriptOptions = $script->getOptions( "[to-version:][repository:][package:][package-dir:][url:][auto-mode:]",
00278                                       "",
00279                                       array( 'to-version' => "Specify what upgrade path to use. \n" .
00280                                                              " available options: '1.2-0' - upgrade 1.1-1 to 1.2-0\n" .
00281                                                              "                    '1.3-0' - upgrade 1.2-0 to 1.3-0",
00282                                              'repository' => "Path to repository where unpacked(unarchived) packages are \n" .
00283                                                          "placed. it's relative to 'var/[site.ini].[FileSettings].[StorageDir]/[package.ini].[RepositorySettings].[RepositoryDirectory]' \n".
00284                                                          "(default is 'var/storage/packages/ez_systems')",
00285                                              'package' => "Package(s) to install, f.e. 'ezwebin_classes'",
00286                                              'package-dir' => "Path to directory with packed(ezpkg) packages(default is '/tmp/ezwebin') ",
00287                                              'url' => "URL to download packages, f.e. 'http://packages.ez.no/ezpublish/3.9'.\n" .
00288                                                       "'package-dir' can be specified to store uploaded packages on local computer.\n" .
00289                                                       "if 'package-dir' is not specified then default dir('/tmp/ezwebin') will be used.",
00290                                              'auto-mode' => "[on/off]. Do not ask what to do in case of confilicts. By default is 'on'"
00291                                            ),
00292                                       false,
00293                                       array( 'user' => true )
00294                                      );
00295 
00296 
00297 if ( !$scriptOptions['siteaccess'] )
00298 {
00299     showNotice( "No siteaccess provided, will use default siteaccess" );
00300 }
00301 else
00302 {
00303     $siteAccessExists = checkSiteaccess( $scriptOptions['siteaccess'] );
00304 
00305     if ( $siteAccessExists )
00306     {
00307         showNotice( "Using siteaccess " . $scriptOptions['siteaccess'] );
00308         $script->setUseSiteAccess( $scriptOptions['siteaccess'] );
00309     }
00310     else
00311     {
00312         showError( "Siteaccess '" . $scriptOptions['siteaccess'] . "' does not exist. Exiting..." );
00313     }
00314 }
00315 $script->initialize();
00316 
00317 
00318 /**************************************************************
00319 * process options                                             *
00320 ***************************************************************/
00321 
00322 $toVersion = '1.2-0';
00323 if ( $scriptOptions['to-version'] )
00324 {
00325     $version = $scriptOptions['to-version'];
00326     if ( isValidWebinUpgradeVersion( $version ) )
00327     {
00328         $toVersion = $version;
00329     }
00330     else
00331     {
00332         showError( "invalid '--to-version' option" );
00333     }
00334 }
00335 
00336 //
00337 // 'repository' option
00338 //
00339 $packageRepository = $scriptOptions['repository'];
00340 if ( !$packageRepository )
00341 {
00342     $packageRepository = repositoryByVendor( defaultVendor() );
00343 }
00344 
00345 
00346 //
00347 // 'package' option
00348 //
00349 $packageList = $scriptOptions['package'];
00350 if ( !$packageList )
00351 {
00352     $packageList = upgradePackageListByWebinVersion( $toVersion );
00353 }
00354 else
00355 {
00356     $packageList = split( ' ', $packageList );
00357 }
00358 
00359 //
00360 // 'package-dir' option
00361 //
00362 $packageDir = $scriptOptions['package-dir'] ? $scriptOptions['package-dir'] : "/tmp/ezwebin";
00363 
00364 //
00365 // 'url' option
00366 //
00367 $packageURL = $scriptOptions['url'];
00368 if ( !$packageURL )
00369 {
00370     $packageINI = eZINI::instance( 'package.ini' );
00371     $packageURL = $packageINI->variable( 'RepositorySettings', 'RemotePackagesIndexURL' );
00372 }
00373 
00374 //
00375 // 'auto-mode' option
00376 //
00377 global $autoMode;
00378 $autoMode = $scriptOptions['auto-mode'];
00379 if( $autoMode != 'off' )
00380 {
00381     $autoMode = 'on';
00382     $importDir = eZPackage::repositoryPath() . "/$packageRepository";
00383     showWarning( "Processing in auto-mode: \n".
00384                  "- packages will be downloaded to '$packageDir';\n" .
00385                  "- packages will be imported to '$importDir';\n" .
00386                  "- installing of existing classes will be skipped;\n" .
00387                  "- all files(extesion, design, downloaded and imported packages) will be overwritten;" );
00388     $action = getUserInput( "Continue? [y/n]: ");
00389     if( strpos( $action, 'y' ) !== 0 )
00390         $script->shutdown( 0, 'Done' );
00391 }
00392 
00393 /**************************************************************
00394 * do the work                                                 *
00395 ***************************************************************/
00396 
00397 if( downloadPackages( $packageList, $packageURL, $packageDir, $packageRepository ) )
00398 {
00399     // install
00400     installPackages( $packageList );
00401 }
00402 
00403 if( file_exists( installScriptDir( $packageRepository ) ) )
00404 {
00405     include_once( installScriptDir( $packageRepository ) . "/settings/ezwebininstaller.php" );
00406     include_once( installScriptDir( $packageRepository ) . "/settings/ini-site.php" );
00407     include_once( installScriptDir( $packageRepository ) . "/settings/ini-common.php" );
00408 
00409     showMessage2( "Updating content classes..." );
00410     execUpdateFunction( "updateClasses", $toVersion );
00411 
00412     showMessage2( "Updating content objects..." );
00413     execUpdateFunction( "updateObjects", $toVersion );
00414 
00415     showMessage2( "Updating INI-files..." );
00416     execUpdateFunction( "updateINI", $toVersion );
00417 }
00418 else
00419 {
00420     showWarning( "no data for updating content classes, objects, roles, ini" );
00421 }
00422 
00423 showMessage2( "Upgrade complete" );
00424 $script->shutdown( 0 );
00425 
00426 ?>