forked from ezsystems/ezpublish-legacy
/
ezmoduleoperationinfo.php
865 lines (810 loc) · 36.9 KB
/
ezmoduleoperationinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
<?php
/**
* File containing the eZModuleOperationInfo class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
* @package lib
*/
/*!
\class eZModuleOperationInfo ezmoduleoperationinfo.php
\brief The class eZModuleOperationInfo does
*/
class eZModuleOperationInfo
{
const ERROR_NO_CLASS = 5;
const ERROR_NO_CLASS_METHOD = 6;
const ERROR_CLASS_INSTANTIATE_FAILED = 7;
const ERROR_MISSING_PARAMETER = 8;
const STATUS_CONTINUE = 1;
const STATUS_CANCELLED = 2;
const STATUS_HALTED = 3;
const STATUS_REPEAT = 4;
const STATUS_QUEUED = 5;
/**
* Constructor
*
* @param string $moduleName
* @param bool $useTriggers
*/
public function __construct( $moduleName, $useTriggers = true )
{
$this->ModuleName = $moduleName;
$this->IsValid = false;
$this->OperationList = array();
$this->Memento = null;
$this->UseTriggers = $useTriggers;
}
/**
* ???
*
* @return bool
*/
function isValid()
{
return $this->IsValid;
}
/**
* Loads the operations definition for the current module
* @return bool true if the operations were loaded, false if an error occured
*/
function loadDefinition()
{
$pathList = eZModule::globalPathList();
foreach ( $pathList as $path )
{
$definitionFile = $path . '/' . $this->ModuleName . '/operation_definition.php';
if ( file_exists( $definitionFile ) )
break;
$definitionFile = null;
}
if ( $definitionFile === null )
{
eZDebug::writeError( 'Missing operation definition file for module: ' . $this->ModuleName, __METHOD__ );
return false;
}
unset( $OperationList );
include( $definitionFile );
if ( !isset( $OperationList ) )
{
eZDebug::writeError( 'Missing operation definition list for module: ' . $this->ModuleName, __METHOD__ );
return false;
}
$this->OperationList = $OperationList;
$this->IsValid = true;
return true;
}
function makeOperationKeyArray( $operationDefinition, $operationParameters )
{
$keyDefinition = null;
if ( array_key_exists( 'keys', $operationDefinition ) and
is_array( $operationDefinition['keys'] ) )
{
$keyDefinition = $operationDefinition['keys'];
}
return $this->makeKeyArray( $keyDefinition, $operationDefinition['parameters'], $operationParameters );
}
function makeKeyArray( $keyDefinition, $parameterDefinition, $operationParameters )
{
$keyArray = array();
if ( $keyDefinition !== null )
{
foreach ( $keyDefinition as $key )
{
$keyArray[$key] = $operationParameters[$key];
}
}
else
{
foreach ( $parameterDefinition as $operationParameter )
{
$keyArray[$operationParameter['name']] = $operationParameters[$operationParameter['name']];
}
}
return $keyArray;
}
/**
* Executes the operation
*
* @param string $operationName
* @param array $operationParameters
* @param array $mementoData
* @return mixed the operation execution result, or null if an error occured
*/
function execute( $operationName, $operationParameters, $mementoData = null )
{
$moduleName = $this->ModuleName;
if ( !isset( $this->OperationList[$operationName] ) )
{
eZDebug::writeError( "No such operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
}
$operationDefinition = $this->OperationList[$operationName];
if ( !isset( $operationDefinition['default_call_method'] ) )
{
eZDebug::writeError( "No call method defined for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
}
if ( !isset( $operationDefinition['body'] ) )
{
eZDebug::writeError( "No body for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
}
if ( !isset( $operationDefinition['parameters'] ) )
{
eZDebug::writeError( "No parameters defined for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
}
$callMethod = $operationDefinition['default_call_method'];
$resultArray = null;
$this->Memento = null;
if ( isset( $callMethod['include_file'] ) and
isset( $callMethod['class'] ) )
{
$bodyCallCount = array( 'loop_run' => array() );
$operationKeys = null;
if ( isset( $operationDefinition['keys'] ) )
$operationKeys = $operationDefinition['keys'];
$operationParameterDefinitions = $operationDefinition['parameters'];
$this->storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $operationName );
// Method callback that must be invoked when the operation gets interrupted (trigger, method...)
$onInterrupt = isset( $operationDefinition['on-interrupt'] ) ? $operationDefinition['on-interrupt'] : null;
$runOperation = true;
if ( $mementoData === null )
{
$keyArray = $this->makeOperationKeyArray( $operationDefinition, $operationParameters );
$mainMemento = null;
if ( $this->UseTriggers )
$mainMemento = eZOperationMemento::fetchMain( $keyArray );
if ( $mainMemento !== null )
{
$this->Memento = $mainMemento;
$mementoOperationData = $this->Memento->data();
if ( isset( $mementoOperationData['loop_run'] ) )
$bodyCallCount['loop_run'] = $mementoOperationData['loop_run'];
}
$mementoList = null;
if ( $this->UseTriggers )
$mementoList = eZOperationMemento::fetchList( $keyArray );
if ( count( $mementoList ) > 0 )
{
$lastResultArray = array();
$mementoRestoreSuccess = true;
// restoring running operation
foreach ( $mementoList as $memento )
{
$mementoData = $memento->data();
$memento->remove();
$resultArray = $this->executeBody( $callMethod['include_file'], $callMethod['class'], $operationDefinition['body'],
$operationKeys, $operationParameterDefinitions, $operationParameters,
$mementoData, $bodyCallCount, $operationDefinition['name'], null, $onInterrupt );
if ( is_array( $resultArray ) )
{
$lastResultArray = array_merge( $lastResultArray, $resultArray );
if ( !$resultArray['status'] )
$mementoRestoreSuccess = false;
}
}
$resultArray = $lastResultArray;
// $resultArray['status'] = $mementoRestoreSuccess;
$runOperation = false;
}
}
if ( $runOperation )
{
// start new operation
$resultArray = $this->executeBody( $callMethod['include_file'], $callMethod['class'], $operationDefinition['body'],
$operationKeys, $operationParameterDefinitions, $operationParameters,
$mementoData, $bodyCallCount, $operationDefinition['name'],
null, $onInterrupt );
}
if ( is_array( $resultArray ) and
isset( $resultArray['status'] ) and
( $resultArray['status'] == eZModuleOperationInfo::STATUS_HALTED
or $resultArray['status'] == eZModuleOperationInfo::STATUS_REPEAT ) )
{
if ( $this->Memento !== null )
{
// $bodyCallCount stores an indexed array of each operation method that was executed
// it must be store in the memento on HALT/REPEAT so that the operation can be resumed
// where it was stopped (same behaviour as triggers)
$this->storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $operationName );
$data = $this->Memento->data();
$data['loop_run'] = $bodyCallCount['loop_run'];
$this->Memento->setData( $data );
$this->Memento->store();
}
}
else if ( $this->Memento !== null and
$this->Memento->attribute( 'id' ) !== null )
{
// eZDebug::writeDebug( $this->Memento, 'ezmodule operation result not halted' );
$this->Memento->remove();
}
// if ( $resultArray['status'] == eZModuleOperationInfo::STATUS_CANCELLED )
// {
// return null;
// }
/*
else if ( isset( $mementoData['memento_key'] ) )
{
$memento = eZOperationMemento::fetch( $mementoData['mementoKey'] );
if ( $memento->attribute( 'main_key') != $mementoData['mementoKey'] )
{
$mainMemento = eZOperationMemento::fetch( $memento->attribute( 'main_key') );
}
$memento->remove();
}
*/
$this->Memento = null;
}
else
{
eZDebug::writeError( "No valid call methods found for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
}
if ( !is_array( $resultArray ) )
{
eZDebug::writeError( "Operation '$operationName' in module '$moduleName' did not return a result array", __METHOD__ );
return null;
}
if ( isset( $resultArray['internal_error'] ) )
{
switch ( $resultArray['internal_error'] )
{
case eZModuleOperationInfo::ERROR_NO_CLASS:
{
$className = $resultArray['internal_error_class_name'];
eZDebug::writeError( "No class '$className' available for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
} break;
case eZModuleOperationInfo::ERROR_NO_CLASS_METHOD:
{
$className = $resultArray['internal_error_class_name'];
$classMethodName = $resultArray['internal_error_class_method_name'];
eZDebug::writeError( "No method '$classMethodName' in class '$className' available for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
} break;
case eZModuleOperationInfo::ERROR_CLASS_INSTANTIATE_FAILED:
{
$className = $resultArray['internal_error_class_name'];
eZDebug::writeError( "Failed instantiating class '$className' which is needed for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
} break;
case eZModuleOperationInfo::ERROR_MISSING_PARAMETER:
{
$parameterName = $resultArray['internal_error_parameter_name'];
eZDebug::writeError( "Missing parameter '$parameterName' for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
} break;
default:
{
$internalError = $resultArray['internal_error'];
eZDebug::writeError( "Unknown internal error '$internalError' for operation '$operationName' in module '$moduleName'", __METHOD__ );
return null;
} break;
}
return null;
}
else if ( isset( $resultArray['error'] ) )
{
}
else if ( isset( $resultArray['status'] ) )
{
return $resultArray;
}
else
{
eZDebug::writeError( "Operation '$operationName' in module '$moduleName' did not return a result value", __METHOD__ );
}
return null;
}
/**
* Executes the operation body
*
* @param string $includeFile Path to the file where the operation class is defined
* @param string $className Name of the class holding the operation methods (@see $includeFile)
* @param array $bodyStructure
* @param array $operationKeys
* @param array $operationParameterDefinitions
* @param array $operationParameters
* @param array $mementoData
* @param int $bodyCallCount
* @param string $operationName
* @param array $currentLoopData
* @param array $onInterrupt method array that must be called if the operation is interrupted
* @return array
*/
function executeBody( $includeFile, $className, $bodyStructure,
$operationKeys, $operationParameterDefinitions, $operationParameters,
&$mementoData, &$bodyCallCount, $operationName, $currentLoopData = null, $onInterrupt = null )
{
$bodyReturnValue = array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
$interrupt = false;
foreach ( $bodyStructure as $body )
{
if ( !isset( $body['type'] ) )
{
eZDebug::writeError( 'No type for body element, skipping', __METHOD__ );
continue;
}
if ( !isset( $body['name'] ) )
{
eZDebug::writeError( 'No name for body element, skipping', __METHOD__ );
continue;
}
$bodyName = $body['name'];
if ( !isset( $bodyCallCount['loop_run'][$bodyName] ) )
$bodyCallCount['loop_run'][$bodyName] = 0;
$type = $body['type'];
switch ( $type )
{
case 'loop':
{
$children = $body['children'];
$tmpOperationParameterDefinitions = $operationParameterDefinitions;
if ( isset( $body['child_parameters'] ) )
$tmpOperationParameterDefinitions = $body['child_parameters'];
$loopName = $body['name'];
if ( $mementoData !== null )
{
$returnValue = $this->executeBody( $includeFile, $className, $children,
$operationKeys, $tmpOperationParameterDefinitions, $operationParameters,
$mementoData, $bodyCallCount, $operationName, null );
if ( !$returnValue['status'] )
return $returnValue;
}
else
{
++$bodyCallCount['loop_run'][$bodyName];
$method = $body['method'];
$resultArray = $this->executeClassMethod( $includeFile, $className, $method,
$operationParameterDefinitions, $operationParameters );
$parameters = array();
if ( isset( $resultArray['parameters'] ) )
{
$parameters = $resultArray['parameters'];
}
$count = 0;
$countDone = 0;
$countHalted = 0;
$countCanceled = 0;
$countRepeated = 0;
foreach ( $parameters as $parameterStructure )
{
$tmpOperationParameters = $operationParameters;
foreach ( $parameterStructure as $parameterName => $parameterValue )
{
$tmpOperationParameters[$parameterName] = $parameterValue;
}
++$count;
$returnValue = $this->executeBody( $includeFile, $className, $children,
$operationKeys, $tmpOperationParameterDefinitions, $tmpOperationParameters,
$mementoData, $bodyCallCount, $operationName, array( 'name' => $loopName,
'count' => count( $parameters ),
'index' => $count ) );
switch( $returnValue['status'] )
{
case eZModuleOperationInfo::STATUS_CANCELLED:
{
$bodyReturnValue = $returnValue;
++$countCanceled;
}break;
case eZModuleOperationInfo::STATUS_CONTINUE:
{
$bodyReturnValue = $returnValue;
++$countDone;
}break;
case eZModuleOperationInfo::STATUS_HALTED:
{
$bodyReturnValue = $returnValue;
++$countHalted;
}break;
case eZModuleOperationInfo::STATUS_REPEAT:
{
$bodyReturnValue = $returnValue;
++$countRepeated;
}break;
}
}
if ( $body['continue_operation'] == 'all' )
{
if ( $count == $countDone )
{
// continue operation
}
if ( $countCanceled > 0 )
{
return $bodyReturnValue;
//cancel operation
}
if ( $countHalted > 0 )
{
return $bodyReturnValue; //show tempalate
}
}
}
} break;
case 'trigger':
{
if ( !$this->UseTriggers )
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_CONTINUE;
continue 2;
}
$triggerName = $body['name'];
$triggerRestored = false;
$executeTrigger = true;
if ( $mementoData !== null )
{
if ( $mementoData['name'] == $triggerName )
{
$executeTrigger = $this->restoreBodyMementoData( $bodyName, $mementoData,
$operationParameters, $bodyCallCount, $currentLoopData );
$triggerRestored = true;
}
else
{
$executeTrigger = false;
}
}
$interrupt = false;
if ( $executeTrigger )
{
$status = $this->executeTrigger( $bodyReturnValue, $body,
$operationParameterDefinitions, $operationParameters,
$bodyCallCount, $currentLoopData,
$triggerRestored, $operationName, $operationKeys );
switch( $status )
{
case eZModuleOperationInfo::STATUS_CONTINUE:
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_CONTINUE;
}break;
case eZModuleOperationInfo::STATUS_CANCELLED:
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_CANCELLED;
$interrupt = true;
}break;
case eZModuleOperationInfo::STATUS_HALTED:
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_HALTED;
$interrupt = true;
}break;
case eZModuleOperationInfo::STATUS_REPEAT:
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_REPEAT;
$interrupt = true;
}
}
}else
{
$bodyReturnValue['status'] = eZModuleOperationInfo::STATUS_CONTINUE;
}
} break;
case 'method':
{
if ( $mementoData === null )
{
$method = $body['method'];
$frequency = $body['frequency'];
$executeMethod = true;
if ( $frequency == 'once' and
$bodyCallCount['loop_run'][$bodyName] != 0 )
$executeMethod = false;
$tmpOperationParameterDefinitions = $operationParameterDefinitions;
if ( isset( $body['parameters'] ) )
$tmpOperationParameterDefinitions = $body['parameters'];
if ( $executeMethod )
{
$result = $this->executeClassMethod( $includeFile, $className, $method,
$tmpOperationParameterDefinitions, $operationParameters );
if ( $result && array_key_exists( 'status', $result ) )
{
switch( $result['status'] )
{
case eZModuleOperationInfo::STATUS_CONTINUE:
default:
{
// moved from outside the case:
// we don't want to count the method as executed if it doesn't return a CONTINUE status,
// or it won't be executed next run
++$bodyCallCount['loop_run'][$bodyName];
$result['status'] = eZModuleOperationInfo::STATUS_CONTINUE;
$bodyReturnValue = $result;
} break;
case eZModuleOperationInfo::STATUS_CANCELLED:
case eZModuleOperationInfo::STATUS_HALTED:
{
$bodyReturnValue = $result;
$interrupt = true;
} break;
}
}
}
}
} break;
default:
{
eZDebug::writeError( "Unknown operation type $type", __METHOD__ );
}
}
if ( $interrupt )
{
// If the operation defined an interrupt callback, we execute it before returning
if ( $onInterrupt )
{
$this->executeClassMethod(
$includeFile,
$className,
$onInterrupt['method'],
( isset( $onInterrupt['parameters'] ) ? $onInterrupt['parameters'] : array() ),
$operationParameters
);
}
return $bodyReturnValue;
}
}
return $bodyReturnValue;
}
/**
* Executes an operation trigger
*
* @param array $bodyReturnValue The current return value
* @param array $body Body data for the trigger being executed
* @param array $operationParameterDefinitions Operation parameters definition
* @param array $operationParameters Operation parameters values
* @param int $bodyCallCount Number of times the body was called
* @param array $currentLoopData Memento data for the operation
* @param bool $triggerRestored Boolean that indicates if operation data (memento) was restored
* @param string $operationName The operation name
* @param array $operationKeys Additional parameters. Only used by looping so far.
* @return
*/
function executeTrigger( &$bodyReturnValue, $body,
$operationParameterDefinitions, $operationParameters,
&$bodyCallCount, $currentLoopData,
$triggerRestored, $operationName, &$operationKeys )
{
$triggerName = $body['name'];
$triggerKeys = $body['keys'];
$status = eZTrigger::runTrigger( $triggerName, $this->ModuleName, $operationName, $operationParameters, $triggerKeys );
if ( $status['Status'] == eZTrigger::WORKFLOW_DONE ||
$status['Status'] == eZTrigger::NO_CONNECTED_WORKFLOWS )
{
++$bodyCallCount['loop_run'][$triggerName];
return eZModuleOperationInfo::STATUS_CONTINUE;
}
else if ( $status['Status'] == eZTrigger::STATUS_CRON_JOB ||
$status['Status'] == eZTrigger::FETCH_TEMPLATE ||
$status['Status'] == eZTrigger::FETCH_TEMPLATE_REPEAT ||
$status['Status'] == eZTrigger::REDIRECT )
{
$bodyMemento = $this->storeBodyMemento( $triggerName, $triggerKeys,
$operationKeys, $operationParameterDefinitions, $operationParameters,
$bodyCallCount, $currentLoopData, $operationName );
$workflowProcess = $status['WorkflowProcess'];
if ( $workflowProcess !== null )
{
$workflowProcess->setAttribute( 'memento_key', $bodyMemento->attribute( 'memento_key' ) );
$workflowProcess->store();
}
$bodyReturnValue['result'] = $status['Result'];
if ( $status['Status'] == eZTrigger::REDIRECT )
{
$bodyReturnValue['redirect_url'] = $status['Result'];
}
if ( $status['Status'] == eZTrigger::FETCH_TEMPLATE_REPEAT )
{
// Hack for project issue #14371 (fetch template repeat)
// The object version's status is set to REPEAT so that it can
// be submitted again
if ( $operationName == 'publish' && $this->ModuleName == 'content' )
{
eZContentOperationCollection::setVersionStatus( $operationParameters['object_id'],
$operationParameters['version'], eZContentObjectVersion::STATUS_REPEAT );
}
return eZModuleOperationInfo::STATUS_REPEAT;
}
else
{
return eZModuleOperationInfo::STATUS_HALTED;
}
}
else if ( $status['Status'] == eZTrigger::WORKFLOW_CANCELLED or
$status['Status'] == eZTrigger::WORKFLOW_RESET )
{
return eZModuleOperationInfo::STATUS_CANCELLED;
$bodyReturnValue['result'] = $status['Result'];
}
}
function storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters,
&$bodyCallCount, $operationName )
{
$mementoData = array();
$mementoData['module_name'] = $this->ModuleName;
$mementoData['operation_name'] = $operationName;
if ( $this->Memento === null )
{
$keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
$mementoData['loop_run'] = $bodyCallCount['loop_run'];
$memento = eZOperationMemento::create( $keyArray, $mementoData, true );
$this->Memento = $memento;
}
else
{
$mementoData = $this->Memento->data();
$mementoData['loop_run'] = $bodyCallCount['loop_run'];
$this->Memento->setData( $mementoData );
}
}
function removeBodyMemento( $bodyName, $bodyKeys,
$operationKeys, $operationParameterDefinitions, $operationParameters,
&$bodyCallCount, $currentLoopData, $operationName )
{
$keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
}
/**
* Packs the current body data (memento) for save & re-use
*
* @param string $bodyName
* @param array $bodyKeys
* @param array $operationKeys
* @param array $operationParameterDefinitions
* @param array $operationParameters
* @param int $bodyCallCount
* @param array $currentLoopData
* @param string $operationName
* @return The memento
*/
function storeBodyMemento( $bodyName, $bodyKeys,
$operationKeys, $operationParameterDefinitions, $operationParameters,
&$bodyCallCount, $currentLoopData, $operationName )
{
$this->storeOperationMemento( $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $operationName );
$keyArray = $this->makeKeyArray( $operationKeys, $operationParameterDefinitions, $operationParameters );
$http = eZHTTPTool::instance();
$keyArray['session_key'] = $http->sessionID();
$mementoData = array();
$mementoData['name'] = $bodyName;
$mementoData['parameters'] = $operationParameters;
$mementoData['loop_data'] = $currentLoopData;
$mementoData['module_name'] = $this->ModuleName;
$mementoData['operation_name'] = $operationName;
$memento = eZOperationMemento::create( $keyArray, $mementoData, false, $this->Memento->attribute( 'memento_key' ) );
$memento->store();
return $memento;
}
function restoreBodyMementoData( $bodyName, &$mementoData,
&$operationParameters, &$bodyCallCount, &$currentLoopData )
{
$operationParameters = array();
if ( isset( $mementoData['parameters'] ) )
$operationParameters = $mementoData['parameters'];
if ( isset( $mementoData[ 'main_memento' ] ) )
{
$this->Memento = $mementoData[ 'main_memento' ];
$mainMementoData = $this->Memento->data();
if ( isset( $mainMementoData['loop_run'] ) )
{
$bodyCallCount['loop_run'] = $mainMementoData['loop_run'];
}
}
// if ( $this->Memento !== null )
// {
// $mementoOperationData = $this->Memento->data();
// if ( isset( $mementoOperationData['loop_run'] ) )
// $bodyCallCount['loop_run'] = $mementoOperationData['loop_run'];
// }
if ( isset( $mementoData['loop_data'] ) )
$currentLoopData = $mementoData['loop_data'];
if ( isset( $mementoData['skip_trigger'] ) && $mementoData['skip_trigger'] == true )
{
$mementoData = null;
return false;
}
else
{
$mementoData = null;
return true;
}
return true;
}
/**
* Executes a class method in an operation body
*
* @param string $includeFile The file where the class & method are defined
* @param string $className The class where the method is implemented
* @param string $methodName The method to call
* @param mixed $operationParameterDefinitions The method parameters definition
* @param mixed $operationParameters The method parameters values
* @return array
*/
function executeClassMethod( $includeFile, $className, $methodName,
$operationParameterDefinitions, $operationParameters )
{
if ( !class_exists( $className ) )
{
include_once( $includeFile );
if ( !class_exists( $className, false ) )
{
return array( 'internal_error' => eZModuleOperationInfo::ERROR_NO_CLASS,
'internal_error_class_name' => $className );
}
}
$classObject = $this->objectForClass( $className );
if ( $classObject === null )
{
return array( 'internal_error' => eZModuleOperationInfo::ERROR_CLASS_INSTANTIATE_FAILED,
'internal_error_class_name' => $className );
}
if ( !method_exists( $classObject, $methodName ) )
{
return array( 'internal_error' => eZModuleOperationInfo::ERROR_NO_CLASS_METHOD,
'internal_error_class_name' => $className,
'internal_error_class_method_name' => $methodName );
}
$parameterArray = array();
foreach ( $operationParameterDefinitions as $operationParameterDefinition )
{
$parameterName = $operationParameterDefinition['name'];
if ( isset( $operationParameterDefinition['constant'] ) )
{
$constantValue = $operationParameterDefinition['constant'];
$parameterArray[] = $constantValue;
}
else if ( isset( $operationParameters[$parameterName] ) )
{
// Do type checking
$parameterArray[] = $operationParameters[$parameterName];
}
else
{
if ( $operationParameterDefinition['required'] )
{
return array( 'internal_error' => eZModuleOperationInfo::ERROR_MISSING_PARAMETER,
'internal_error_parameter_name' => $parameterName );
}
else if ( isset( $operationParameterDefinition['default'] ) )
{
$parameterArray[] = $operationParameterDefinition['default'];
}
else
{
$parameterArray[] = null;
}
}
}
return call_user_func_array( array( $classObject, $methodName ), $parameterArray );
}
/**
* Helper method that keeps and returns the instances of operation objects
* @param string $className The class the method should return an object for
* @return $className
* @private
* @todo Use a static variable instead of globals
*/
function objectForClass( $className )
{
if ( !isset( $GLOBALS['eZModuleOperationClassObjectList'] ) )
{
$GLOBALS['eZModuleOperationClassObjectList'] = array();
}
if ( isset( $GLOBALS['eZModuleOperationClassObjectList'][$className] ) )
{
return $GLOBALS['eZModuleOperationClassObjectList'][$className];
}
return $GLOBALS['eZModuleOperationClassObjectList'][$className] = new $className();
}
/// \privatesection
public $ModuleName;
public $FunctionList;
public $IsValid;
public $UseTriggers = false;
/**
* @var eZOperationMemento
*/
public $Memento;
}
?>