eZ Publish  [trunk]
ezpackagehandler.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZPackageHandler class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /*!
00012   \class eZPackageHandler ezpackagehandler.php
00013   \brief The class eZPackageHandler does
00014 
00015 */
00016 
00017 class eZPackageHandler
00018 {
00019     /*!
00020      Constructor
00021     */
00022     function eZPackageHandler( $handlerType, $parameters = array() )
00023     {
00024         $parameters = array_merge( array( 'extract-install-content' => false ),
00025                                    $parameters );
00026         $this->ExtractInstallContent = $parameters['extract-install-content'];
00027         $this->HandlerType = $handlerType;
00028     }
00029 
00030     /*!
00031      \return true if the content of the install item should be extracted
00032              from disk before the install() function is called.
00033     */
00034     function extractInstallContent()
00035     {
00036         return $this->ExtractInstallContent;
00037     }
00038 
00039     /*!
00040      \pure
00041      Installs the package item
00042     */
00043     function install( $package, $installType, $parameters,
00044                       $name, $os, $filename, $subdirectory,
00045                       $content, &$installParameters,
00046                       &$installData )
00047     {
00048     }
00049 
00050     /*!
00051      \pure
00052      Uninstalls the package item
00053     */
00054     function uninstall( $package, $installType, $parameters,
00055                         $name, $os, $filename, $subdirectory,
00056                         $content, &$installParameters,
00057                         &$installData )
00058     {
00059     }
00060 
00061     /*!
00062      \return the name of the type this handler works for.
00063     */
00064     function handlerType()
00065     {
00066         return $this->HandlerType;
00067     }
00068 
00069     /*!
00070      Resets all data in the handler so that it's ready to handle a new package.
00071     */
00072     function reset()
00073     {
00074     }
00075 
00076     /*!
00077      \pure
00078      Returns an explanation (human readable) for the install item \a $installItem.
00079      The explanation is an array with the following items.
00080      - description - Textual description of what will be installed
00081 
00082      Use $requestedInfo to request portion of info.
00083 
00084      \note This must be implemented for package handlers.
00085     */
00086     function explainInstallItem( $package, $installItem, $requestedInfo = array() )
00087     {
00088     }
00089 
00090     /*!
00091      \pure
00092      Adds items defined in \a $parameters to the package \a $package.
00093     */
00094     function add( $packageType, $package, $cli, $parameters )
00095     {
00096     }
00097 
00098     /*!
00099      \pure
00100      Called when command line parameters must be handled by the package handler.
00101      This function must return an array with values which can easily be used in the add() function.
00102      \param $packageType The type that was specified when using the add command,
00103                          which is either the name of this handler or an alias for it.
00104      \param $package     The package object.
00105      \param $cli         Command line interface object, can be used to output errors etc.
00106      \param $arguments   An array with string values taken from the command line after the add command.
00107     */
00108     function handleAddParameters( $packageType, $package, $cli, $arguments )
00109     {
00110     }
00111 
00112 //     /*!
00113 //      \pure
00114 //      Inteprets the parameters defined in \a $parameters and adds items to \a $package.
00115 //     */
00116 //     function handle( $package, $parameters )
00117 //     {
00118 //     }
00119 
00120     /*!
00121      \pure
00122      Fills in extra information on the dependency node \a $dependencyNode which is
00123      specific to the current handler.
00124      \param $package The current package.
00125      \param $dependencyItem Contains all variables for the dependency
00126      \param $dependencySection The section for the dependency, can be \c 'provide', \c 'require', \c 'obsolete' or \c 'conflict'
00127     */
00128     function createDependencyNode( $package, &$dependencyNode, $dependencyItem, $dependencySection )
00129     {
00130     }
00131 
00132     /*!
00133      \pure
00134      Parses the XML node \c $dependencyNode and fills in extra information not handled
00135      by the package parser.
00136      \param $package The current package.
00137      \param $dependencyParameters Reference to an array with must be filled with specific data for the current handler.
00138      \param $dependencySection The section for the dependency, can be \c 'provide', \c 'require', \c 'obsolete' or \c 'conflict'
00139     */
00140     function parseDependencyNode( $package, &$dependencyNode, &$dependencyParameters, $dependencySection )
00141     {
00142     }
00143 
00144     /*!
00145      Creates a text specific for the dependency item \a $dependencyItem and returns it.
00146      \param $package The current package.
00147      \param $dependencyItem Associative array with dependency values.
00148      \param $dependencySection The section for the dependency, can be \c 'provide', \c 'require', \c 'obsolete' or \c 'conflict'
00149      \return \c false if no special text is required.
00150     */
00151     function createDependencyText( $package, $dependencyItem, $dependencySection )
00152     {
00153     }
00154 
00155     /*!
00156      \pure
00157      Fills in extra information on the install node \a $installNode which is
00158      specific to the current handler.
00159      \param $package The current package.
00160      \param $installItem Contains all variables for the install
00161      \param $installType The type of install, can be \c 'install' or \c 'uninstall'
00162     */
00163     function createInstallNode( $package, $installNode, $installItem, $installType )
00164     {
00165     }
00166 
00167     /*!
00168      \pure
00169      Parses the XML node \c $installNode and fills in extra information not handled
00170      by the package parser.
00171      \param $package The current package.
00172      \param $installParameters Reference to an array which must be filled with specific data for the current handler.
00173      \param $isInstall Is \c true if this is an install node, \c false if it is an uninstall node
00174     */
00175     function parseInstallNode( $package, $installNode, &$installParameters, $isInstall )
00176     {
00177     }
00178 
00179     /*!
00180         Helper function to process install errors.
00181         Decides to skip current element or not when cycling thru elements
00182         Also skips element where error has occured if action is not choosen
00183     */
00184 
00185     function isErrorElement( $elementID, &$installParameters )
00186     {
00187         if ( $elementID == $installParameters['error']['element_id'] )
00188         {
00189             // If action not set - skip this element
00190             if ( !isset( $installParameters['error']['choosen_action'] ) )
00191             {
00192                  $installParameters['error'] = array();
00193                  return false;
00194             }
00195             return true;
00196         }
00197         return false;
00198 
00199     }
00200 
00201     /*!
00202         Helper function to process install errors.
00203         \return choosen action code.
00204         If $resetError is false, array should be manually reset in handler.
00205     */
00206 
00207     static function errorChoosenAction( $errorCode, &$installParameters, $description, $handlerType, $resetError = true )
00208     {
00209         if ( isset( $installParameters['non-interactive'] ) && $installParameters['non-interactive'] )
00210         {
00211             if ( $description )
00212             {
00213                 eZDebug::writeNotice( $description, 'Package installation conflict' );
00214             }
00215             return eZPackage::NON_INTERACTIVE;
00216         }
00217 
00218         if ( isset( $installParameters['error_default_actions'][$handlerType][$errorCode] ) )
00219         {
00220             if ( $resetError && count( $installParameters['error'] ) )
00221                 $installParameters['error'] = array();
00222             return $installParameters['error_default_actions'][$handlerType][$errorCode];
00223         }
00224 
00225         if ( isset( $installParameters['error']['error_code'] ) &&
00226              $installParameters['error']['error_code'] == $errorCode )
00227         {
00228             if ( isset( $installParameters['error']['choosen_action'] ) )
00229             {
00230                 $choosenAction = $installParameters['error']['choosen_action'];
00231                 if ( $resetError )
00232                     $installParameters['error'] = array();
00233                 return $choosenAction;
00234             }
00235         }
00236         return false;
00237     }
00238 
00239 }
00240 
00241 ?>