[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezpackageinstallationhandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZPackageInstallationHandler class
   4  //
   5  // Created on: <31-Mar-2004 10:15:36 kk>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezpackageinstallationhandler.php
  30  */
  31  
  32  /*!
  33    \ingroup package
  34    \class eZPackageInstallationHandler ezpackageinstallationhandler.php
  35    \brief The class eZPackageInstallationHandler does
  36  
  37  */
  38  
  39  class eZPackageInstallationHandler
  40  {
  41      /*!
  42       Constructor
  43      */
  44      function eZPackageInstallationHandler( &$package, $type, $installItem, $name = null, $steps = null )
  45      {
  46          $this->Package = $package;
  47          $this->Attributes = array( 'type' => $type,
  48                                     'name' => $name,
  49                                     'steps' => $steps,
  50                                     'step_map' => false,
  51                                     'current_steps' => $steps );
  52          $this->InitializeStepMethodMap = array();
  53          $this->ValidateStepMethodMap = array();
  54          $this->CommitStepMethodMap = array();
  55          $this->InstallItem = $installItem;
  56      }
  57  
  58      /*!
  59       Will go over the steps and make sure that:
  60       - The next and previous links are correct
  61       - Steps that aren't needed are removed
  62  
  63        It will also make sure that steps can be looked up by their ID.
  64      */
  65  	function generateStepMap( &$package, &$persistentData )
  66      {
  67          $steps = $this->attribute( 'steps' );
  68          $map = array();
  69          $lastStep = false;
  70          $currentSteps = array();
  71          for ( $i = 0; $i < count( $steps ); ++$i )
  72          {
  73              $step =& $steps[$i];
  74              if ( !isset( $step['previous_step'] ) )
  75              {
  76                  if ( $lastStep )
  77                      $step['previous_step'] = $lastStep['id'];
  78                  else
  79                      $step['previous_step'] = false;
  80              }
  81              if ( !isset( $step['next_step'] ) )
  82              {
  83                  if ( $i + 1 < count( $steps ) )
  84                      $step['next_step'] = $steps[$i+1]['id'];
  85                  else
  86                      $step['next_step'] = false;
  87              }
  88              if ( isset( $step['methods']['initialize'] ) )
  89                  $this->InitializeStepMethodMap[$step['id']] = $step['methods']['initialize'];
  90              if ( isset( $step['methods']['validate'] ) )
  91                  $this->ValidateStepMethodMap[$step['id']] = $step['methods']['validate'];
  92              if ( isset( $step['methods']['commit'] ) )
  93                  $this->CommitStepMethodMap[$step['id']] = $step['methods']['commit'];
  94              $isStepIncluded = true;
  95              if ( isset( $step['methods']['check'] ) )
  96              {
  97                  $checkMethod = $step['methods']['check'];
  98                  $isStepIncluded = $this->$checkMethod( $package, $persistentData );
  99              }
 100              if ( $isStepIncluded )
 101              {
 102                  $map[$step['id']] =& $step;
 103                  $lastStep =& $step;
 104                  $currentSteps[] =& $step;
 105              }
 106          }
 107          $this->StepMap = array( 'first' => &$steps[0],
 108                                  'map' => &$map,
 109                                  'steps' => &$steps );
 110          $this->Attributes['step_map'] =& $this->StepMap;
 111          $this->Attributes['current_steps'] = $currentSteps;
 112      }
 113  
 114      function attributes()
 115      {
 116          return array_keys( $this->Attributes );
 117      }
 118  
 119      function hasAttribute( $name )
 120      {
 121          return array_key_exists( $name, $this->Attributes );
 122      }
 123  
 124      function &attribute( $name )
 125      {
 126          if ( array_key_exists( $name, $this->Attributes ) )
 127              return $this->Attributes[$name];
 128          {
 129              eZDebug::writeError( "Attribute '$name' does not exist", 'eZPackageInstallationHandler::attribute' );
 130              $retValue = null;
 131              return $retValue;
 132          }
 133      }
 134  
 135      function initializeStepMethodMap()
 136      {
 137          return $this->InitializeStepMethodMap;
 138      }
 139  
 140      function validateStepMethodMap()
 141      {
 142          return $this->ValidateStepMethodMap;
 143      }
 144  
 145      function commitStepMethodMap()
 146      {
 147          return $this->CommitStepMethodMap;
 148      }
 149  
 150      /*!
 151       \return a process step map which has proper next/previous links,
 152               method maps and allows lookup of steps by ID.
 153      */
 154      function &stepMap()
 155      {
 156          return $this->StepMap;
 157      }
 158  
 159      /*!
 160       \virtual
 161      */
 162      function stepTemplate( $package, $installItem, $step )
 163      {
 164          $stepTemplatePath = 'design:package/';
 165          $stepTemplateName = $step['template'];
 166          if ( isset( $step['use_standard_template'] ) and
 167               $step['use_standard_template'] )
 168              $stepTemplatePath .= "create";
 169          else
 170              $stepTemplatePath .= "installers/" . $this->attribute( 'type' );
 171          return array( 'name' => $stepTemplateName,
 172                        'path' => $stepTemplatePath );
 173      }
 174  
 175      /*!
 176       \virtual
 177       This is called the first time the step is entered (ie. not on validations)
 178       and can be used to fill in values in the \a $persistentData variable
 179       for use in the template or later retrieval.
 180      */
 181      function initializeStep( &$package, &$http, $step, &$persistentData, &$tpl, &$module )
 182      {
 183          $methodMap = $this->initializeStepMethodMap();
 184          if ( count( $methodMap ) > 0 )
 185          {
 186              if ( isset( $methodMap[$step['id']] ) )
 187              {
 188                  $method = $methodMap[$step['id']];
 189                  return $this->$method( $package, $http, $step, $persistentData, $tpl, $module );
 190              }
 191          }
 192      }
 193  
 194      /*!
 195       This is called after a step is finished. Reimplement this function to validate
 196       the step values and give back errors.
 197       \return \c false if the next step should not be fetched (ie. errors) or
 198               \c true if the all is OK and the next step should be fetched.
 199               It is also possible to return a step identifier, in which case
 200               this will be the next step.
 201      */
 202      function validateStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 203      {
 204          $nextStep = $this->validateAndAdvanceStep( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
 205          if ( $nextStep === true )
 206          {
 207              if ( !isset( $stepMap['map'][$currentStepID] ) )
 208              {
 209                  $nextStep = $stepMap['first']['id'];
 210              }
 211              else
 212              {
 213                  $currentStep =& $stepMap['map'][$currentStepID];
 214                  $nextStep = $currentStep['next_step'];
 215              }
 216          }
 217          else if ( $nextStep === false )
 218              $nextStep = $currentStepID;
 219          return $nextStep;
 220      }
 221  
 222      /*!
 223       \virtual
 224      */
 225      function validateAndAdvanceStep( &$package, &$http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
 226      {
 227          $methodMap = $this->validateStepMethodMap();
 228          if ( count( $methodMap ) > 0 )
 229          {
 230              if ( isset( $methodMap[$currentStepID] ) )
 231              {
 232                  $method = $methodMap[$currentStepID];
 233                  return $this->$method( $package, $http, $currentStepID, $stepMap, $persistentData, $errorList );
 234              }
 235          }
 236          return true;
 237      }
 238  
 239      /*!
 240       \virtual
 241       This is called after a step has validated it's information. It can
 242       be used to put values in the \a $persistentData variable for later retrieval.
 243      */
 244      function commitStep( &$package, &$http, $step, &$persistentData, &$tpl )
 245      {
 246          $methodMap = $this->commitStepMethodMap();
 247          if ( count( $methodMap ) > 0 )
 248          {
 249              if ( isset( $methodMap[$step['id']] ) )
 250              {
 251                  $method = $methodMap[$step['id']];
 252                  return $this->$method( $package, $http, $step, $persistentData, $tpl );
 253              }
 254          }
 255      }
 256  
 257      /*!
 258       \virtual
 259       Finalizes the creation process with the gathered information.
 260       This is usually the function that creates the package and
 261       adds the proper elements.
 262      */
 263      function finalize( &$package, &$http, &$persistentData )
 264      {
 265      }
 266  
 267      /*!
 268       \return the package installation handler object for the handler named \a $handlerName.
 269  
 270       \param handler name'
 271       \param install Item
 272      */
 273      function &instance( &$package, $handlerName, $installItem )
 274      {
 275          // if no installItem is given, then this is the whole package installer
 276          /*if ( $installItem == null )
 277          {
 278              include_once( $package->path() . '/' . $package->installerDirectory() . '/' . $package->installerFileName() );
 279              $handlerClassName = $package->installerFileName();
 280              $handler =& new $handlerClassName( $package, null, null );
 281              return $handler;
 282          }*/
 283  
 284          $handlers =& $GLOBALS['eZPackageCreationInstallers'];
 285          if ( !isset( $handlers ) )
 286              $handlers = array();
 287          $handler = false;
 288          include_once ( 'lib/ezutils/classes/ezextension.php' );
 289          if ( eZExtension::findExtensionType( array( 'ini-name' => 'package.ini',
 290                                                      'repository-group' => 'PackageSettings',
 291                                                      'repository-variable' => 'RepositoryDirectories',
 292                                                      'extension-group' => 'PackageSettings',
 293                                                      'extension-variable' => 'ExtensionDirectories',
 294                                                      'subdir' => 'packageinstallers',
 295                                                      'extension-subdir' => 'packageinstallers',
 296                                                      'suffix-name' => 'packageinstaller.php',
 297                                                      'type-directory' => true,
 298                                                      'type' => $handlerName,
 299                                                      'alias-group' => 'InstallerSettings',
 300                                                      'alias-variable' => 'HandlerAlias' ),
 301                                               $result ) )
 302          {
 303              $handlerFile = $result['found-file-path'];
 304              if ( file_exists( $handlerFile ) )
 305              {
 306                  include_once( $handlerFile );
 307                  $handlerClassName = $result['type'] . 'PackageInstaller';
 308  
 309                  if ( isset( $handlers[$result['type']] ) )
 310                  {
 311                      $handler =& $handlers[$result['type']];
 312                      $handler->reset();
 313                  }
 314                  else
 315                  {
 316                      $handler =& new $handlerClassName( $package, $handlerName, $installItem );
 317                      $handlers[$result['type']] =& $handler;
 318                  }
 319  
 320                  // if custom install handler is available in the package, we use it
 321                  $customInstallHandler = $handler->customInstallHandlerInfo( $package, $installItem );
 322                  if ( $customInstallHandler )
 323                  {
 324                      unset( $handler );
 325                      $handlerClassName = $customInstallHandler['classname'];
 326                      $handlerFile = $customInstallHandler['file-path'];
 327  
 328                      include_once( $handlerFile );
 329                      $handler =& new $handlerClassName( $package, $handlerName, $installItem );
 330                  }
 331              }
 332          }
 333          return $handler;
 334      }
 335  
 336      /*!
 337       \virtual
 338       \return The package type taken from \a $package if the package exists,
 339               otherwise \c false.
 340       If the creator should have a specific package type this function should be reimplemented.
 341       See eZPackage::typeList() for more information on available types.
 342  
 343       \note This function is called from createPackage and checkPackageMaintainer()
 344      */
 345  	function packageType( &$package, &$persistentData )
 346      {
 347          if ( get_class( $package ) == 'ezpackage' )
 348          {
 349              return $package->attribute( 'type' );
 350          }
 351          return false;
 352      }
 353  
 354      /*!
 355       \private
 356       Get root dom node of current install item.
 357      */
 358      function rootDOMNode()
 359      {
 360          if ( !isset( $this->InstallItem['content'] ) || !$this->InstallItem['content'] )
 361          {
 362              $filename = $this->InstallItem['filename'];
 363              $subdirectory = $this->InstallItem['sub-directory'];
 364              if ( $subdirectory )
 365                  $filepath = $subdirectory . '/' . $filename . '.xml';
 366              else
 367                  $filepath = $filename . '.xml';
 368  
 369              $filepath = $this->Package->path() . '/' . $filepath;
 370  
 371              $dom =& $this->Package->fetchDOMFromFile( $filepath );
 372              if ( $dom )
 373              {
 374                  $this->InstallItem['content'] =& $dom->root();
 375              }
 376              else
 377              {
 378                  eZDebug::writeError( 'Failed fetching dom from file ' . $filepath,
 379                                       'eZPackageInstallationHandler::rootDOMNode()' );
 380                  exit(0);
 381              }
 382          }
 383  
 384          return $this->InstallItem['content'];
 385      }
 386  
 387      /*!
 388       \private
 389       Support for custom installers (stored within the package)
 390      */
 391      function customInstallHandlerInfo( $package, $installItem )
 392      {
 393          return false;
 394      }
 395  
 396  }
 397  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7