ILIAS  release_8 Revision v8.23
class.PRGUpdateCompletionByMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
24 
25 class PRGUpdateCompletionByMigration implements Setup\Migration
26 {
27  private const DEFAULT_AMOUNT_OF_STEPS = 10000;
28  private ilDBInterface $db;
29 
33  private mixed $io;
34 
35  public function getLabel(): string
36  {
37  return "Update 'Completion By' for Course(References)";
38  }
39 
41  {
42  return self::DEFAULT_AMOUNT_OF_STEPS;
43  }
44 
45  public function getPreconditions(Environment $environment): array
46  {
47  return [
51  ];
52  }
53 
54  public function prepare(Environment $environment): void
55  {
56  $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
57  }
58 
62  public function step(Environment $environment): void
63  {
64  $query = 'SELECT assignment_id, prg_id, usr_id, completion_by, target_obj_id FROM prg_usr_progress' . PHP_EOL
65  . 'JOIN object_data ON prg_usr_progress.completion_by = object_data.obj_id' . PHP_EOL
66  . 'JOIN container_reference ON object_data.obj_id = container_reference.obj_id' . PHP_EOL
67  . 'WHERE object_data.type = "crsr" LIMIT 1';
68  $result = $this->db->query($query);
69  $row = $this->db->fetchAssoc($result);
70 
71  $crs_id = $row['target_obj_id'];
72 
73  $query = "UPDATE prg_usr_progress SET completion_by = " . $crs_id . PHP_EOL
74  . "WHERE assignment_id =" . $row['assignment_id'] . PHP_EOL
75  . "AND prg_id =" . $row['prg_id'] . PHP_EOL
76  . "AND usr_id =" . $row['usr_id'];
77  $this->db->manipulate($query);
78  }
79 
80  public function getRemainingAmountOfSteps(): int
81  {
82  $query = 'SELECT count(completion_by) AS cnt FROM prg_usr_progress' . PHP_EOL
83  . 'JOIN object_data ON prg_usr_progress.completion_by = object_data.obj_id' . PHP_EOL
84  . 'WHERE object_data.type = "crsr"';
85 
86  $result = $this->db->query($query);
87  $row = $this->db->fetchAssoc($result);
88  return (int) $row['cnt'];
89  }
90 }
$query
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