ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestProcessLockerFile.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionProcessLocker.php';
5
13{
14 const PROCESS_NAME_TEST_START_LOCK_CHECK = 'testStartLockCheck';
15 const PROCESS_NAME_RANDOM_PASS_BUILD = 'randomPassBuild';
16 const PROCESS_NAME_TEST_FINISH = 'testFinish';
17
22
27
33 {
34 $this->lockFileStorage = $lockFileStorage;
35 $this->lockFileHandles = array();
36 }
37
42 {
43 parent::onBeforeExecutingTestStartOperation();
44 $this->requestLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
45 }
46
51 {
52 $this->releaseLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
53 parent::onAfterExecutingTestStartOperation();
54 }
55
59 protected function onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables = false)
60 {
61 parent::onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables);
62 $this->requestLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
63 }
64
68 protected function onAfterExecutingRandomPassBuildOperation($withTaxonomyTables = false)
69 {
70 $this->releaseLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
71 parent::onAfterExecutingRandomPassBuildOperation($withTaxonomyTables);
72 }
73
78 {
79 parent::onBeforeExecutingTestStartOperation();
80 $this->requestLock(self::PROCESS_NAME_TEST_FINISH);
81 }
82
87 {
88 $this->releaseLock(self::PROCESS_NAME_TEST_FINISH);
89 parent::onAfterExecutingTestStartOperation();
90 }
91
92 protected function onBeforeExecutingNamedOperation(string $operationDescriptor) : void
93 {
94 $this->requestLock($operationDescriptor);
95 parent::onBeforeExecutingNamedOperation($operationDescriptor);
96 }
97
98 protected function onAfterExecutingNamedOperation(string $operationDescriptor) : void
99 {
100 $this->releaseLock($operationDescriptor);
101 parent::onAfterExecutingNamedOperation($operationDescriptor);
102 }
103
104 private function requestLock($processName)
105 {
106 $lockFilePath = $this->getLockFilePath($processName);
107 $this->lockFileHandles[$processName] = fopen($lockFilePath, 'w');
108 flock($this->lockFileHandles[$processName], LOCK_EX);
109 }
110
111 private function getLockFilePath($processName)
112 {
113 $path = $this->lockFileStorage->getPath();
114 return $path . '/' . $processName . '.lock';
115 }
116
117 private function releaseLock($processName)
118 {
119 flock($this->lockFileHandles[$processName], LOCK_UN);
120 fclose($this->lockFileHandles[$processName]);
121 }
122}
An exception for terminatinating execution or to throw for unit testing.
onBeforeExecutingNamedOperation(string $operationDescriptor)
onAfterExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
__construct(ilTestProcessLockFileStorage $lockFileStorage)
ilTestProcessLockerFile constructor.
onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
onAfterExecutingNamedOperation(string $operationDescriptor)