ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssQuestionProcessLockerDb.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  protected $db;
31 
35  protected $atom_query;
36 
40  private $assessmentLogEnabled = false;
41 
45  public function __construct(ilDBInterface $db)
46  {
47  $this->db = $db;
48  }
49 
50  public function isAssessmentLogEnabled(): bool
51  {
53  }
54 
56  {
57  $this->assessmentLogEnabled = $assessmentLogEnabled;
58  }
59 
63  private function getTablesUsedDuringAssessmentLog(): array
64  {
65  return array(
66  array('name' => 'qpl_questions', 'sequence' => false),
67  array('name' => 'tst_tests', 'sequence' => false),
68  array('name' => 'tst_active', 'sequence' => false),
69  array('name' => 'ass_log', 'sequence' => true)
70  );
71  }
72 
73  private function getTablesUsedDuringSolutionUpdate(): array
74  {
75  return [
76  ['name' => 'tst_solutions', 'sequence' => true],
77  ['name' => PassPresentedVariablesRepo::TABLE_NAME, 'sequence' => false]
78  ];
79  }
80 
84  private function getTablesUsedDuringResultUpdate(): array
85  {
86  return array(
87  array('name' => 'tst_test_result', 'sequence' => true)
88  );
89  }
90 
95  {
96  $tables = $this->getTablesUsedDuringSolutionUpdate();
97 
98  if ($this->isAssessmentLogEnabled()) {
99  $tables = array_merge($tables, $this->getTablesUsedDuringAssessmentLog());
100  }
101 
102  $this->atom_query = $this->db->buildAtomQuery();
103  foreach ($tables as $table) {
104  $this->atom_query->addTableLock($table['name'])->lockSequence((bool) $table['sequence']);
105  }
106  }
107 
112  {
113  $this->atom_query = $this->db->buildAtomQuery();
114  foreach ($this->getTablesUsedDuringResultUpdate() as $table) {
115  $this->atom_query->addTableLock($table['name'])->lockSequence((bool) $table['sequence']);
116  }
117  }
118 
123  {
124  $this->atom_query = $this->db->buildAtomQuery();
125  foreach (array_merge(
128  ) as $table) {
129  $this->atom_query->addTableLock($table['name'])->lockSequence((bool) $table['sequence']);
130  }
131  }
132 
137  {
138  $this->atom_query = $this->db->buildAtomQuery();
139  $this->atom_query->addTableLock('tst_result_cache');
140  $this->atom_query->addTableLock('tst_test_result')->lockSequence(true);
141  $this->atom_query->addTableLock('tst_solutions')->lockSequence(true);
142  }
143 
147  protected function executeOperation(callable $operation): void
148  {
149  if ($this->atom_query) {
150  $this->atom_query->addQueryCallable(function (ilDBInterface $ilDB) use ($operation) {
151  $operation();
152  });
153  $this->atom_query->run();
154  } else {
155  $operation();
156  }
157 
158  $this->atom_query = null;
159  }
160 }