[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/lib/ezutils/classes/ -> ezmoduleoperationinfo.php (source)

   1  <?php
   2  //
   3  // Definition of eZModuleOperationInfo class
   4  //
   5  // Created on: <06-Oct-2002 16:27:36 amos>
   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 ezmoduleoperationinfo.php
  30  */
  31  
  32  /*!
  33    \class eZModuleOperationInfo ezmoduleoperationinfo.php
  34    \brief The class eZModuleOperationInfo does
  35  
  36  */
  37  
  38  include_once ( 'lib/ezutils/classes/ezmodule.php' );
  39  include_once ( 'lib/ezutils/classes/ezdebug.php' );
  40  include_once ( 'lib/ezutils/classes/ezoperationmemento.php' );
  41  include_once ( 'kernel/classes/eztrigger.php' );
  42  
  43  include_once ( 'lib/ezutils/classes/ezmoduleoperationdefinition.php' );
  44  
  45  
  46  class eZModuleOperationInfo
  47  {
  48      /*!
  49       Constructor
  50      */
  51      function eZModuleOperationInfo( $moduleName, $useTriggers = true )
  52      {
  53          $this->ModuleName = $moduleName;
  54          $this->IsValid = false;
  55          $this->OperationList = array();
  56          $this->UseOldCall = false;
  57          $this->Memento = null;
  58          $this->UseTriggers = $useTriggers;
  59      }
  60  
  61      function isValid()
  62      {
  63          return $this->IsValid;
  64      }
  65  
  66      function loadDefinition()
  67      {
  68          $pathList = eZModule::globalPathList();
  69          foreach ( $pathList as $path )
  70          {
  71              $definitionFile = $path . '/' . $this->ModuleName . '/operation_definition.php';
  72              if ( file_exists( $definitionFile ) )
  73                  break;
  74              $definitionFile = null;
  75          }
  76          if ( $definitionFile === null )
  77          {
  78              eZDebug::writeError( 'Missing operation definition file for module: ' . $this->ModuleName,
  79                                   'eZModuleOperationInfo::loadDefinition' );
  80              return false;
  81          }
  82          unset( $OperationList );
  83          include( $definitionFile );
  84          if ( !isset( $OperationList ) )
  85          {
  86              eZDebug::writeError( 'Missing operation definition list for module: ' . $this->ModuleName,
  87                                   'eZModuleOperationInfo::loadDefinition' );
  88              return false;
  89          }
  90          $this->OperationList = $OperationList;
  91          $this->IsValid = true;
  92          return true;
  93      }
  94  
  95      function makeOperationKeyArray( $operationDefinition, $operationParameters )
  96      {
  97          $keyDefinition = null;
  98          if ( array_key_exists( 'keys', $operationDefinition ) and
  99               is_array( $operationDefinition['keys'] ) )
 100          {
 101              $keyDefinition = $operationDefinition['keys'];
 102          }
 103          return $this->makeKeyArray( $keyDefinition, $operationDefinition['parameters'], $operationParameters );
 104      }
 105  
 106      function makeKeyArray( $keyDefinition, $parameterDefinition, $operationParameters )
 107      {
 108          $keyArray = array();
 109          if ( $keyDefinition !== null )
 110          {
 111              foreach ( $keyDefinition as $key )
 112              {
 113                  $keyArray[$key] = $operationParameters[$key];
 114              }
 115          }
 116          else
 117          {
 118              foreach ( $parameterDefinition as $operationParameter )
 119              {
 120                  $keyArray[$operationParameter['name']] = $operationParameters[$operationParameter['name']];
 121              }
 122          }
 123          return $keyArray;
 124      }
 125  
 126      function execute( $operationName, $operationParameters, $mementoData = null )
 127      {
 128          $moduleName = $this->ModuleName;
 129          if ( !isset( $this->OperationList[$operationName] ) )
 130          {
 131              eZDebug::writeError( "No such operation '$operationName' in module '$moduleName'",
 132                                   'eZModuleOperationInfo::execute' );
 133              return null;
 134          }
 135          $operationDefinition =& $this->OperationList[$operationName];
 136          if ( !isset( $operationName['default_call_method'] ) )
 137          {
 138              eZDebug::writeError( "No call method defined for operation '$operationName' in module '$moduleName'",
 139                                   'eZModuleOperationInfo::execute' );
 140              return null;
 141          }
 142          if ( !isset( $operationName['body'] ) )
 143          {
 144              eZDebug::writeError( "No body for operation '$operationName' in module '$moduleName'",
 145                                   'eZModuleOperationInfo::execute' );
 146              return null;
 147          }
 148          if ( !isset( $operationName['parameters'] ) )
 149          {
 150              eZDebug::writeError( "No parameters defined for operation '$operationName' in module '$moduleName'",
 151                                   'eZModuleOperationInfo::execute' );
 152              return null;
 153          }
 154          $callMethod =& $operationDefinition['default_call_method'];
 155          $resultArray = null;
 156          $this->Memento = null;
 157          if ( isset( $callMethod['include_file'] ) and
 158               isset( $callMethod['class'] ) )
 159          {
 160              $bodyCallCount = array( 'loop_run' => array() );
 161              $operationKeys = null;
 162              if ( isset( $operationDefinition['keys'] ) )
 163                  $operationKeys = $operationDefinition['keys'];
 164              $operationParameterDefinitions = $operationDefinition['parameters'];
 165              $this->storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $operationName );
 166  
 167              $runOperation = true;
 168              if ( $mementoData === null )
 169              {
 170                  $keyArray = $this->makeOperationKeyArray( $operationDefinition, $operationParameters );
 171                  $keyArray['session_key'] = eZHTTPTool::getSessionKey();
 172                  $mainMemento = null;
 173                  if ( $this->UseTriggers )
 174                      $mainMemento = eZOperationMemento::fetchMain( $keyArray );
 175  
 176                  if ( $mainMemento !== null )
 177                  {
 178                      $this->Memento =& $mainMemento;
 179                      $mementoOperationData = $this->Memento->data();
 180                      if ( isset( $mementoOperationData['loop_run'] ) )
 181                          $bodyCallCount['loop_run'] = $mementoOperationData['loop_run'];
 182                  }
 183  //                 else
 184  //                     eZDebug::writeWarning( 'Missing main operation memento for key: ' . $this->Memento->attribute( 'memento_key' ), 'eZModuleOperationInfo::execute' );
 185  
 186                  $mementoList = null;
 187                  if ( $this->UseTriggers )
 188                      $mementoList = eZOperationMemento::fetchList( $keyArray );
 189  
 190                  if ( count( $mementoList ) > 0 )
 191                  {
 192                      $lastResultArray = array();
 193                      $mementoRestoreSuccess = true;
 194                      // restoring running operation
 195                      foreach ( array_keys( $mementoList ) as $key )
 196                      {
 197                          $memento =& $mementoList[$key];
 198                          $mementoData = $memento->data();
 199                          $memento->remove();
 200  
 201                          $resultArray = $this->executeBody( $callMethod['include_file'], $callMethod['class'], $operationDefinition['body'],
 202                                                             $operationKeys, $operationParameterDefinitions, $operationParameters,
 203                                                             $mementoData, $bodyCallCount, $operationDefinition['name'] );
 204                          if ( is_array( $resultArray ) )
 205                          {
 206                              $lastResultArray = array_merge( $lastResultArray, $resultArray );
 207                              if ( !$resultArray['status'] )
 208                                  $mementoRestoreSuccess = false;
 209                          }
 210                      }
 211                      $resultArray = $lastResultArray;
 212                      //                 $resultArray['status'] = $mementoRestoreSuccess;
 213                      $runOperation = false;
 214                  }
 215              }
 216              if ( $runOperation )
 217              {
 218                  // start  new operation
 219                  $resultArray = $this->executeBody( $callMethod['include_file'], $callMethod['class'], $operationDefinition['body'],
 220                                                      $operationKeys, $operationParameterDefinitions, $operationParameters,
 221                                                      $mementoData, $bodyCallCount, $operationDefinition['name'] );
 222  
 223  //                 eZDebug::writeDebug( $resultArray, 'ezmodule operation result array' );
 224              }
 225  
 226              if ( is_array( $resultArray ) and
 227                   isset( $resultArray['status'] ) and
 228                   $resultArray['status'] == EZ_MODULE_OPERATION_HALTED )
 229              {
 230  //                 eZDebug::writeDebug( $this->Memento, 'ezmodule operation result halted' );
 231                  if ( $this->Memento !== null )
 232                  {
 233                      $this->Memento->store();
 234                  }
 235              }
 236              else if ( $this->Memento !== null and
 237                        $this->Memento->attribute( 'id' ) !== null )
 238              {
 239  //                 eZDebug::writeDebug( $this->Memento, 'ezmodule operation result not halted' );
 240                  $this->Memento->remove();
 241              }
 242  //            if ( $resultArray['status'] == EZ_MODULE_OPERATION_CANCELED )
 243  //            {
 244  //                return null;
 245  //            }
 246              /*
 247              else if ( isset( $mementoData['memento_key'] ) )
 248              {
 249                  $memento = eZOperationMemento::fetch( $mementoData['mementoKey'] );
 250                  if ( $memento->attribute( 'main_key') !=  $mementoData['mementoKey'] )
 251                  {
 252                      $mainMemento = eZOperationMemento::fetch( $memento->attribute( 'main_key') );
 253                  }
 254                  $memento->remove();
 255              }
 256              */
 257              $this->Memento = null;
 258          }
 259          else
 260          {
 261              eZDebug::writeError( "No valid call methods found for operation '$operationName' in module '$moduleName'",
 262                                   'eZModuleOperationInfo::execute' );
 263              return null;
 264          }
 265          if ( !is_array( $resultArray ) )
 266          {
 267              eZDebug::writeError( "Operation '$operationName' in module '$moduleName' did not return a result array",
 268                                   'eZOperationHandler::execute' );
 269              return null;
 270          }
 271          if ( isset( $resultArray['internal_error'] ) )
 272          {
 273              switch ( $resultArray['internal_error'] )
 274              {
 275                  case EZ_MODULE_OPERATION_ERROR_NO_CLASS:
 276                  {
 277                      $className = $resultArray['internal_error_class_name'];
 278                      eZDebug::writeError( "No class '$className' available for operation '$operationName' in module '$moduleName'",
 279                                           'eZModuleOperationInfo::execute' );
 280                      return null;
 281                  } break;
 282                  case EZ_MODULE_OPERATION_ERROR_NO_CLASS_METHOD:
 283                  {
 284                      $className = $resultArray['internal_error_class_name'];
 285                      $classMethodName = $resultArray['internal_error_class_method_name'];
 286                      eZDebug::writeError( "No method '$classMethodName' in class '$className' available for operation '$operationName' in module '$moduleName'",
 287                                           'eZModuleOperationInfo::execute' );
 288                      return null;
 289                  } break;
 290                  case EZ_MODULE_OPERATION_ERROR_CLASS_INSTANTIATE_FAILED:
 291                  {
 292                      $className = $resultArray['internal_error_class_name'];
 293                      eZDebug::writeError( "Failed instantiating class '$className' which is needed for operation '$operationName' in module '$moduleName'",
 294                                           'eZModuleOperationInfo::execute' );
 295                      return null;
 296                  } break;
 297                  case EZ_MODULE_OPERATION_ERROR_MISSING_PARAMETER:
 298                  {
 299                      $parameterName = $resultArray['internal_error_parameter_name'];
 300                      eZDebug::writeError( "Missing parameter '$parameterName' for operation '$operationName' in module '$moduleName'",
 301                                           'eZModuleOperationInfo::execute' );
 302                      return null;
 303                  } break;
 304                  default:
 305                  {
 306                      $internalError = $resultArray['internal_error'];
 307                      eZDebug::writeError( "Unknown internal error '$internalError' for operation '$operationName' in module '$moduleName'",
 308                                           'eZModuleOperationInfo::execute' );
 309                      return null;
 310                  } break;
 311              }
 312              return null;
 313          }
 314          else if ( isset( $resultArray['error'] ) )
 315          {
 316          }
 317          else if ( isset( $resultArray['status'] ) )
 318          {
 319              return $resultArray;
 320          }
 321          else
 322          {
 323              eZDebug::writeError( "Operation '$operationName' in module '$moduleName' did not return a result value",
 324                                   'eZOperationHandler::execute' );
 325          }
 326          return null;
 327      }
 328  
 329      function executeBody( $includeFile, $className, $bodyStructure,
 330                            $operationKeys, $operationParameterDefinitions, $operationParameters,
 331                            &$mementoData, &$bodyCallCount, $operationName, $currentLoopData = null )
 332      {
 333          $bodyReturnValue = array( 'status' => EZ_MODULE_OPERATION_CONTINUE );
 334          foreach ( $bodyStructure as $body )
 335          {
 336              if ( !isset( $body['type'] ) )
 337              {
 338                  eZDebug::writeError( 'No type for body element, skipping', 'eZModuleOperationInfo::executeBody' );
 339                  continue;
 340              }
 341              if ( !isset( $body['name'] ) )
 342              {
 343                  eZDebug::writeError( 'No name for body element, skipping', 'eZModuleOperationInfo::executeBody' );
 344                  continue;
 345              }
 346              $bodyName = $body['name'];
 347              if ( !isset( $bodyCallCount['loop_run'][$bodyName] ) )
 348                  $bodyCallCount['loop_run'][$bodyName] = 0;
 349              $type = $body['type'];
 350              switch ( $type )
 351              {
 352                  case 'loop':
 353                  {
 354                      $children = $body['children'];
 355                      $tmpOperationParameterDefinitions = $operationParameterDefinitions;
 356                      if ( isset( $body['child_parameters'] ) )
 357                          $tmpOperationParameterDefinitions = $body['child_parameters'];
 358                      $loopName = $body['name'];
 359  
 360                      if ( $mementoData !== null )
 361                      {
 362                          $returnValue = $this->executeBody( $includeFile, $className, $children,
 363                                                             $operationKeys, $tmpOperationParameterDefinitions, $operationParameters,
 364                                                             $mementoData, $bodyCallCount, $operationName, null );
 365                          if ( !$returnValue['status'] )
 366                              return $returnValue;
 367                      }
 368                      else
 369                      {
 370                          ++$bodyCallCount['loop_run'][$bodyName];
 371  
 372                          $method = $body['method'];
 373                          $resultArray = $this->executeClassMethod( $includeFile, $className, $method,
 374                                                                    $operationParameterDefinitions, $operationParameters );
 375                          $parameters = array();
 376                          if ( isset( $resultArray['parameters'] ) )
 377                          {
 378                              $parameters = $resultArray['parameters'];
 379                          }
 380                          $count = 0;
 381                          $countDone = 0;
 382                          $countHalted = 0;
 383                          $countCanceled = 0;
 384                          foreach ( $parameters as $parameterStructure )
 385                          {
 386                              $tmpOperationParameters = $operationParameters;
 387                              foreach ( $parameterStructure as $parameterName => $parameterValue )
 388                              {
 389                                  $tmpOperationParameters[$parameterName] = $parameterValue;
 390                              }
 391  
 392                              ++$count;
 393                              $returnValue = $this->executeBody( $includeFile, $className, $children,
 394                                                                 $operationKeys, $tmpOperationParameterDefinitions, $tmpOperationParameters,
 395                                                                 $mementoData, $bodyCallCount, $operationName, array( 'name' => $loopName,
 396                                                                                                                      'count' => count( $parameters ),
 397                                                                                                                      'index' => $count  ) );
 398                              switch( $returnValue['status'] )
 399                              {
 400                                  case EZ_MODULE_OPERATION_CANCELED:
 401                                  {
 402                                      $bodyReturnValue = $returnValue;
 403                                      ++$countCanceled;
 404                                  }break;
 405                                  case EZ_MODULE_OPERATION_CONTINUE:
 406                                  {
 407                                      $bodyReturnValue = $returnValue;
 408  
 409                                      ++$countDone;
 410                                  }break;
 411                                  case EZ_MODULE_OPERATION_HALTED:
 412                                  {
 413                                      $bodyReturnValue = $returnValue;
 414                                      ++$countHalted;
 415                                  }break;
 416                              }
 417                          }
 418                          if ( $body['continue_operation'] == 'all' )
 419                          {
 420                              if ( $count == $countDone )
 421                              {
 422                                  // continue operation
 423                              }
 424                              if ( $countCanceled > 0 )
 425                              {
 426                                  return $bodyReturnValue;
 427                                  //cancel operation
 428                              }
 429                              if ( $countHalted > 0 )
 430                              {
 431                                  return $bodyReturnValue;                                //show tempalate
 432                              }
 433  
 434                          }
 435                      }
 436                  } break;
 437                  case 'trigger':
 438                  {
 439                      if ( !$this->UseTriggers )
 440                      {
 441                          $bodyReturnValue['status'] = EZ_MODULE_OPERATION_CONTINUE;
 442                          continue;
 443  
 444                      }
 445  
 446                      $triggerName = $body['name'];
 447                      $triggerRestored = false;
 448                      $executeTrigger = true;
 449                      if ( $mementoData !== null )
 450                      {
 451                          if ( $mementoData['name'] == $triggerName )
 452                          {
 453                              $executeTrigger =  $this->restoreBodyMementoData( $bodyName, $mementoData,
 454                                                                                $operationParameters, $bodyCallCount, $currentLoopData );
 455                              $triggerRestored = true;
 456                          }
 457                          else
 458                          {
 459                              $executeTrigger = false;
 460                          }
 461                      }
 462                      if ( $executeTrigger )
 463                      {
 464                          $status = $this->executeTrigger( $bodyReturnValue, $body,
 465                                                            $operationParameterDefinitions, $operationParameters,
 466                                                            $bodyCallCount, $currentLoopData,
 467                                                            $triggerRestored, $operationName, $operationKeys );
 468  
 469                          switch( $status )
 470                          {
 471                              case EZ_MODULE_OPERATION_CONTINUE:
 472                              {
 473                                  $bodyReturnValue['status'] = EZ_MODULE_OPERATION_CONTINUE;
 474                              }break;
 475                              case EZ_MODULE_OPERATION_CANCELED:
 476                              {
 477                                  $bodyReturnValue['status'] = EZ_MODULE_OPERATION_CANCELED;
 478                                  return $bodyReturnValue;
 479                              }break;
 480                              case EZ_MODULE_OPERATION_HALTED:
 481                              {
 482  
 483                                  $bodyReturnValue['status'] = EZ_MODULE_OPERATION_HALTED;
 484                                  return $bodyReturnValue;
 485                              }
 486                          }
 487                      }else
 488                      {
 489                          $bodyReturnValue['status'] = EZ_MODULE_OPERATION_CONTINUE;
 490                      }
 491                  } break;
 492                  case 'method':
 493                  {
 494                      if ( $mementoData === null )
 495                      {
 496                          $method = $body['method'];
 497                          $frequency = $body['frequency'];
 498                          $executeMethod = true;
 499                          if ( $frequency == 'once' and
 500                               $bodyCallCount['loop_run'][$bodyName] != 0 )
 501                              $executeMethod = false;
 502                          $tmpOperationParameterDefinitions = $operationParameterDefinitions;
 503                          if ( isset( $body['parameters'] ) )
 504                              $tmpOperationParameterDefinitions = $body['parameters'];
 505                          if ( $executeMethod )
 506                          {
 507                              ++$bodyCallCount['loop_run'][$bodyName];
 508                              $result = $this->executeClassMethod( $includeFile, $className, $method,
 509                                                                   $tmpOperationParameterDefinitions, $operationParameters );
 510  
 511                              switch( $result['status'] )
 512                              {
 513                                  case EZ_MODULE_OPERATION_CONTINUE:
 514                                  default:
 515                                  {
 516                                      $result['status'] = EZ_MODULE_OPERATION_CONTINUE;
 517                                      $bodyReturnValue = $result;
 518                                  } break;
 519  
 520                                  case EZ_MODULE_OPERATION_CANCELED:
 521                                  case EZ_MODULE_OPERATION_HALTED:
 522                                  {
 523                                      return $result;
 524                                  } break;
 525                              }
 526                          }
 527                      }
 528                  } break;
 529                  default:
 530                  {
 531                      eZDebug::writeError( "Unknown operation type $type", 'eZModuleOperationInfo::executeBody' );
 532                  }
 533              }
 534          }
 535  
 536          return $bodyReturnValue;
 537      }
 538  
 539      function executeTrigger( &$bodyReturnValue, $body,
 540                               $operationParameterDefinitions, $operationParameters,
 541                               &$bodyCallCount, $currentLoopData,
 542                               $triggerRestored, $operationName, &$operationKeys )
 543      {
 544          $triggerName = $body['name'];
 545          $triggerKeys = $body['keys'];
 546  
 547          $status = eZTrigger::runTrigger( $triggerName, $this->ModuleName, $operationName, $operationParameters, $triggerKeys );
 548  
 549  
 550          if ( $status['Status'] == EZ_TRIGGER_WORKFLOW_DONE ||
 551               $status['Status'] == EZ_TRIGGER_NO_CONNECTED_WORKFLOWS )
 552          {
 553              ++$bodyCallCount['loop_run'][$triggerName];
 554              return EZ_MODULE_OPERATION_CONTINUE;
 555          }
 556          else if ( $status['Status'] == EZ_TRIGGER_STATUS_CRON_JOB ||
 557                    $status['Status'] == EZ_TRIGGER_FETCH_TEMPLATE ||
 558                    $status['Status'] == EZ_TRIGGER_REDIRECT )
 559          {
 560              $bodyMemento =& $this->storeBodyMemento( $triggerName, $triggerKeys,
 561                                                       $operationKeys, $operationParameterDefinitions, $operationParameters,
 562                                                       $bodyCallCount, $currentLoopData, $operationName );
 563              $workflowProcess =& $status['WorkflowProcess'];
 564              if ( ! is_null( $workflowProcess ) )
 565              {
 566                  $workflowProcess->setAttribute( 'memento_key', $bodyMemento->attribute( 'memento_key' ) );
 567                  $workflowProcess->store();
 568              }
 569  
 570              $bodyReturnValue['result'] =& $status['Result'];
 571              if ( $status['Status'] == EZ_TRIGGER_REDIRECT )
 572              {
 573                  $bodyReturnValue['redirect_url'] =& $status['Result'];
 574              }
 575              return EZ_MODULE_OPERATION_HALTED;
 576          }
 577          else if ( $status['Status'] == EZ_TRIGGER_WORKFLOW_CANCELED or
 578                    $status['Status'] == EZ_TRIGGER_WORKFLOW_RESET )
 579          {
 580               return EZ_MODULE_OPERATION_CANCELED;
 581               $bodyReturnValue['result'] =& $status['Result'];
 582          }
 583      }
 584  
 585      function storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters,
 586                                      &$bodyCallCount, $operationName )
 587      {
 588          $mementoData = array();
 589          $mementoData['module_name'] = $this->ModuleName;
 590          $mementoData['operation_name'] = $operationName;
 591          if ( $this->Memento === null )
 592          {
 593              $keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
 594              $keyArray['session_key'] = eZHTTPTool::getSessionKey();
 595              $mementoData['loop_run'] = $bodyCallCount['loop_run'];
 596              $memento = eZOperationMemento::create( $keyArray, $mementoData, true );
 597              $this->Memento =& $memento;
 598          }
 599          else
 600          {
 601              $mementoData = $this->Memento->data();
 602              $mementoData['loop_run'] = $bodyCallCount['loop_run'];
 603              $this->Memento->setData( $mementoData );
 604          }
 605      }
 606  
 607      function removeBodyMemento( $bodyName, $bodyKeys,
 608                                  $operationKeys, $operationParameterDefinitions, $operationParameters,
 609                                  &$bodyCallCount, $currentLoopData, $operationName )
 610      {
 611          $keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
 612      }
 613      function &storeBodyMemento( $bodyName, $bodyKeys,
 614                                 $operationKeys, $operationParameterDefinitions, $operationParameters,
 615                                 &$bodyCallCount, $currentLoopData, $operationName )
 616      {
 617          $this->storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $operationName );
 618  
 619          $keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
 620          $keyArray['session_key'] = eZHTTPTool::getSessionKey();
 621          $mementoData = array();
 622          $mementoData['name'] = $bodyName;
 623          $mementoData['parameters'] = $operationParameters;
 624          $mementoData['loop_data'] = $currentLoopData;
 625          $mementoData['module_name'] = $this->ModuleName;
 626          $mementoData['operation_name'] = $operationName;
 627          $memento = eZOperationMemento::create( $keyArray, $mementoData, false, $this->Memento->attribute( 'memento_key' ) );
 628          $memento->store();
 629          return $memento;
 630      }
 631  
 632      function restoreBodyMementoData( $bodyName, &$mementoData,
 633                                       &$operationParameters, &$bodyCallCount, &$currentLoopData )
 634      {
 635          $operationParameters = array();
 636          if ( isset( $mementoData['parameters'] ) )
 637              $operationParameters = $mementoData['parameters'];
 638          if ( isset( $mementoData[ 'main_memento' ] ) )
 639          {
 640              $this->Memento =& $mementoData[ 'main_memento' ];
 641              $mainMementoData = $this->Memento->data();
 642              if ( isset( $mainMementoData['loop_run'] ) )
 643              {
 644                  $bodyCallCount['loop_run'] = $mainMementoData['loop_run'];
 645              }
 646  
 647          }
 648  
 649  //         if ( $this->Memento !== null )
 650  //         {
 651  //             $mementoOperationData = $this->Memento->data();
 652  //             if ( isset( $mementoOperationData['loop_run'] ) )
 653  //                 $bodyCallCount['loop_run'] = $mementoOperationData['loop_run'];
 654  //         }
 655          if ( isset( $mementoData['loop_data'] ) )
 656              $currentLoopData = $mementoData['loop_data'];
 657  
 658          if ( isset( $mementoData['skip_trigger'] ) && $mementoData['skip_trigger'] == true )
 659          {
 660              $mementoData = null;
 661              return false;
 662          }
 663          else
 664          {
 665              $mementoData = null;
 666              return true;
 667          }
 668  
 669          return true;
 670      }
 671  
 672      function executeClassMethod( $includeFile, $className, $methodName,
 673                                   $operationParameterDefinitions, $operationParameters )
 674      {
 675          include_once( $includeFile );
 676          if ( !class_exists( $className ) )
 677          {
 678              return array( 'internal_error' => EZ_MODULE_OPERATION_ERROR_NO_CLASS,
 679                            'internal_error_class_name' => $className );
 680          }
 681          $classObject =& $this->objectForClass( $className );
 682          if ( $classObject === null )
 683          {
 684              return array( 'internal_error' => EZ_MODULE_OPERATION_ERROR_CLASS_INSTANTIATE_FAILED,
 685                            'internal_error_class_name' => $className );
 686          }
 687          if ( !method_exists( $classObject, $methodName ) )
 688          {
 689              return array( 'internal_error' => EZ_MODULE_OPERATION_ERROR_NO_CLASS_METHOD,
 690                            'internal_error_class_name' => $className,
 691                            'internal_error_class_method_name' => $methodName );
 692          }
 693          $parameterArray = array();
 694  
 695          foreach ( $operationParameterDefinitions as $operationParameterDefinition )
 696          {
 697              $parameterName = $operationParameterDefinition['name'];
 698              if ( isset( $operationParameterDefinition['constant'] ) )
 699              {
 700                  $constantValue = $operationParameterDefinition['constant'];
 701                  $parameterArray[] = $constantValue;
 702              }
 703              else if ( isset( $operationParameters[$parameterName] ) )
 704              {
 705                  // Do type checking
 706                  $parameterArray[] = $operationParameters[$parameterName];
 707              }
 708              else
 709              {
 710                  if ( $operationParameterDefinition['required'] )
 711                  {
 712  
 713                      return array( 'internal_error' => EZ_MODULE_OPERATION_ERROR_MISSING_PARAMETER,
 714                                    'internal_error_parameter_name' => $parameterName );
 715                  }
 716                  else if ( isset( $operationParameterDefinition['default'] ) )
 717                  {
 718                      $parameterArray[] = $operationParameterDefinition['default'];
 719                  }
 720                  else
 721                  {
 722                      $parameterArray[] = null;
 723                  }
 724              }
 725          }
 726  
 727          return $this->callClassMethod( $methodName, $classObject, $parameterArray );
 728      }
 729  
 730      function &objectForClass( $className )
 731      {
 732          $classObjectList =& $GLOBALS['eZModuleOperationClassObjectList'];
 733          if ( !isset( $classObjectList ) )
 734              $classObjectList = array();
 735          if ( isset( $classObjectList[$className] ) )
 736              return $classObjectList[$className];
 737          $classObject = new $className();
 738          $classObjectList[$className] =& $classObject;
 739          return $classObject;
 740      }
 741  
 742      function callClassMethod( $methodName, &$classObject, $parameterArray )
 743      {
 744          if ( $this->UseOldCall )
 745              return call_user_method_array( $methodName, $classObject, $parameterArray );
 746          else
 747              return call_user_func_array( array( $classObject, $methodName ), $parameterArray );
 748      }
 749  
 750  
 751      /// \privatesection
 752      var $ModuleName;
 753      var $FunctionList;
 754      var $IsValid;
 755      var $UseOldCall;
 756      var $UseTriggers = false;
 757  }
 758  
 759  ?>


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