eZ Publish  [4.0]
ezinstallscriptpackagehandler.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZInstallScriptPackageHandler class
00004 //
00005 // Created on: <16-Feb-2006 11:15:42 ks>
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 ezinstallscripterpackagehandler.php
00032 */
00033 
00034 /*!
00035   \class eZInstallScriptPackageHandler ezinstallscriptpackagehandler.php
00036   \brief Empty handler to support package custom install scripts.
00037 
00038 */
00039 
00040 //include_once( 'kernel/classes/ezpackagehandler.php' );
00041 
00042 
00043 class eZInstallScriptPackageHandler extends eZPackageHandler
00044 {
00045     /*!
00046      Constructor
00047     */
00048     function eZInstallScriptPackageHandler()
00049     {
00050         $this->eZPackageHandler( 'ezinstallscript',
00051                                  array( 'extract-install-content' => false ) );
00052     }
00053 
00054     /*!
00055      \reimp
00056      Returns an explanation for the extension install item.
00057     */
00058     function explainInstallItem( $package, $installItem, $requestedInfo = array() )
00059     {
00060         $itemPath = $package->path() . '/' . $installItem['sub-directory'];
00061         $xmlPath = $itemPath . '/' . $installItem['filename'] . '.xml';
00062 
00063         $dom = $package->fetchDOMFromFile( $xmlPath );
00064         if ( !$dom )
00065             return false;
00066 
00067         $mainNode =& $dom->documentElement;
00068 
00069         $description = $mainNode->getAttribute( 'description' );
00070         if ( !$description )
00071             return false;
00072 
00073         return array( 'description' => ezi18n( 'kernel/package', 'Install script: %description', false,
00074                                                array( '%description' => $description ) ) );
00075     }
00076 
00077     /*!
00078      \reimp
00079      Do nothing
00080     */
00081     function uninstall( $package, $installType, $parameters,
00082                       $name, $os, $filename, $subdirectory,
00083                       $content, &$installParameters,
00084                       &$installData )
00085     {
00086         return true;
00087     }
00088 
00089     /*!
00090      \reimp
00091      Do nothing
00092     */
00093     function install( $package, $installType, $parameters,
00094                       $name, $os, $filename, $subdirectory,
00095                       $content, &$installParameters,
00096                       &$installData )
00097     {
00098         return true;
00099     }
00100 
00101     /*!
00102      \reimp
00103     */
00104     function add( $packageType, $package, $cli, $parameters )
00105     {
00106         //include_once( 'lib/ezutils/classes/ezini.php' );
00107         //include_once( 'lib/ezfile/classes/ezdir.php' );
00108 
00109         $siteINI = eZINI::instance();
00110         $extensionDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' );
00111 
00112         //$cli->output( var_export( $parameters, true ) );
00113         foreach ( $parameters as $scriptItem )
00114         {
00115             $cli->output( 'adding install script ' . $cli->style( 'dir' ) . $scriptItem['filename'] .  $cli->style( 'dir-end' ) );
00116 
00117             $sourceDir = $scriptItem['source-directory'];
00118             $targetDir = $package->path() . '/' . $scriptItem['sub-directory'];
00119 
00120             eZDir::mkdir( $targetDir, false, true );
00121             eZDir::copy( $sourceDir, $targetDir, false );
00122 
00123             $package->appendInstall( 'ezinstallscript', false, false, true,
00124                                      $scriptItem['filename'], $scriptItem['sub-directory'],
00125                                      array( 'content' => false ) );
00126         }
00127     }
00128 
00129     /*!
00130      \reimp
00131     */
00132     function handleAddParameters( $packageType, $package, $cli, $arguments )
00133     {
00134         $scriptArgumentList = array_chunk( $arguments, 3 );
00135         $params = array();
00136 
00137         foreach ( $scriptArgumentList as $scriptArguments )
00138         {
00139             if ( count( $scriptArguments ) < 3 )
00140             {
00141                 break;
00142             }
00143 
00144             $script = array(
00145                 'sub-directory' => $scriptArguments[0],
00146                 'filename' => $scriptArguments[1],
00147                 'source-directory' => $scriptArguments[2]
00148             );
00149 
00150             if ( !file_exists( $script['source-directory'] ) )
00151             {
00152                 $cli->error( 'install script source directory ' . $cli->style( 'dir' ) . $script['source-directory'] . $cli->style( 'dir-end' ) . 'does not exist' );
00153                 return false;
00154             }
00155 
00156             $installFile = $script['source-directory'] . '/' . $script['filename'] . '.xml';
00157             if ( !file_exists( $installFile ) )
00158             {
00159                 $cli->error( 'install script ' . $cli->style( 'dir' ) . $script['filename'] . '.xml' . $cli->style( 'dir-end' ) . 'does not exist in source dir' );
00160                 return false;
00161             }
00162 
00163             $params[] = $script;
00164         }
00165 
00166         return $params;
00167     }
00168 }
00169 
00170 ?>