ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.PRGUpdateRestartedSourceMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
24 
25 class PRGUpdateRestartedSourceMigration implements Setup\Migration
26 {
27  private const DEFAULT_AMOUNT_OF_STEPS = 1;
28  private ilDBInterface $db;
29 
33  private mixed $io;
34 
35  public function getLabel(): string
36  {
37  return "Update 'Assigned By' for restarted assignments";
38  }
39 
41  {
42  return self::DEFAULT_AMOUNT_OF_STEPS;
43  }
44 
45  public function getPreconditions(Environment $environment): array
46  {
47  return [
50  ];
51  }
52 
53  public function prepare(Environment $environment): void
54  {
55  $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
56  }
57 
61  public function step(Environment $environment): void
62  {
63  $query = "UPDATE prg_usr_assignments SET last_change_by = " . ilPRGAssignment::AUTO_ASSIGNED_BY_RESTART . PHP_EOL
64  . "WHERE id in (SELECT restarted_assignment_id FROM prg_usr_assignments WHERE restarted_assignment_id != -1)" . PHP_EOL
65  . "AND restarted_assignment_id NOT IN (SELECT id FROM prg_usr_assignments WHERE last_change_by = " . ilPRGAssignment::AUTO_ASSIGNED_BY_RESTART . ")";
66  $this->db->manipulate($query);
67  }
68 
69  public function getRemainingAmountOfSteps(): int
70  {
71  $query = "SELECT count(restarted_assignment_id) AS cnt FROM prg_usr_assignments" . PHP_EOL
72  . " WHERE restarted_assignment_id != -1" . PHP_EOL
73  . "AND restarted_assignment_id NOT IN (SELECT id FROM prg_usr_assignments WHERE last_change_by = " . ilPRGAssignment::AUTO_ASSIGNED_BY_RESTART . ");";
74 
75  $result = $this->db->query($query);
76  $row = $this->db->fetchAssoc($result);
77  return (int) $row['cnt'] > 0 ? 1 : 0;
78  }
79 }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27