ILIAS  release_8 Revision v8.24
class.ilTestProcessLockerFile.php
Go to the documentation of this file.
1<?php
2
26{
27 public const PROCESS_NAME_TEST_START_LOCK_CHECK = 'testStartLockCheck';
28 public const PROCESS_NAME_RANDOM_PASS_BUILD = 'randomPassBuild';
29 public const PROCESS_NAME_TEST_FINISH = 'testFinish';
30
32
37
43 {
44 $this->lockFileStorage = $lockFileStorage;
45 $this->lockFileHandles = array();
46 }
47
52 {
53 parent::onBeforeExecutingTestStartOperation();
54 $this->requestLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
55 }
56
61 {
62 $this->releaseLock(self::PROCESS_NAME_TEST_START_LOCK_CHECK);
63 parent::onAfterExecutingTestStartOperation();
64 }
65
69 protected function onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables = false)
70 {
71 parent::onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables);
72 $this->requestLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
73 }
74
78 protected function onAfterExecutingRandomPassBuildOperation($withTaxonomyTables = false)
79 {
80 $this->releaseLock(self::PROCESS_NAME_RANDOM_PASS_BUILD);
81 parent::onAfterExecutingRandomPassBuildOperation($withTaxonomyTables);
82 }
83
88 {
89 parent::onBeforeExecutingTestStartOperation();
90 $this->requestLock(self::PROCESS_NAME_TEST_FINISH);
91 }
92
97 {
98 $this->releaseLock(self::PROCESS_NAME_TEST_FINISH);
99 parent::onAfterExecutingTestStartOperation();
100 }
101
102 protected function onBeforeExecutingNamedOperation(string $operationDescriptor): void
103 {
104 $this->requestLock($operationDescriptor);
105 parent::onBeforeExecutingNamedOperation($operationDescriptor);
106 }
107
108 protected function onAfterExecutingNamedOperation(string $operationDescriptor): void
109 {
110 $this->releaseLock($operationDescriptor);
111 parent::onAfterExecutingNamedOperation($operationDescriptor);
112 }
113
114 private function requestLock($processName)
115 {
116 $lockFilePath = $this->getLockFilePath($processName);
117 $this->lockFileHandles[$processName] = fopen($lockFilePath, 'w');
118 flock($this->lockFileHandles[$processName], LOCK_EX);
119 }
120
121 private function getLockFilePath($processName): string
122 {
123 $path = $this->lockFileStorage->getAbsolutePath();
124 return $path . '/' . $processName . '.lock';
125 }
126
127 private function releaseLock($processName)
128 {
129 flock($this->lockFileHandles[$processName], LOCK_UN);
130 fclose($this->lockFileHandles[$processName]);
131 }
132}
ilTestProcessLockFileStorage $lockFileStorage
onBeforeExecutingNamedOperation(string $operationDescriptor)
onAfterExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
__construct(ilTestProcessLockFileStorage $lockFileStorage)
ilTestProcessLockerFile constructor.
onBeforeExecutingRandomPassBuildOperation($withTaxonomyTables=false)
{}
onAfterExecutingNamedOperation(string $operationDescriptor)
$path
Definition: ltiservices.php:32