ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.IndAssStorageMigration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
24 
25 class IndAssStorageMigration implements Setup\Migration
26 {
27  private const DEFAULT_AMOUNT_OF_STEPS = 200;
28  private ilDBInterface $db;
31 
35  private mixed $io;
36 
37  public function getLabel(): string
38  {
39  return "Migrate FSStorage to IRSS";
40  }
41 
43  {
44  return self::DEFAULT_AMOUNT_OF_STEPS;
45  }
46 
47  public function getPreconditions(Environment $environment): array
48  {
49  return array_merge(
51  [
53  ]
54  );
55  }
56 
57  public function prepare(Environment $environment): void
58  {
59  $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
60  $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
61  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
62 
63  $DIC = $GLOBALS["DIC"];
64  $GLOBALS["DIC"] = new ILIAS\DI\Container();
65  $GLOBALS["DIC"]["ilDB"] = $this->db;
66  $GLOBALS["DIC"]["ilSetting"] = $settings_factory->settingsFor();
67  $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
68 
70  ilInitialisation::bootstrapFilesystems();
71 
72  $this->dic = $GLOBALS["DIC"];
73  $GLOBALS["DIC"] = $DIC;
74 
75  $stakeholder = new ilIndividualAssessmentGradingStakeholder();
76  $this->helper = new \ilResourceStorageMigrationHelper(
77  $stakeholder,
78  $environment
79  );
80  }
81 
85  public function step(Environment $environment): void
86  {
87  $GLOBALS["DIC"] = $this->dic;
88 
89  $query = "SELECT obj_id, usr_id, file_name FROM iass_members WHERE file_name LIKE '%.%' LIMIT 1;";
90  $result = $this->db->query($query);
91  $row = $this->db->fetchAssoc($result);
92 
93  $obj_id = (int) $row['obj_id'];
94  $usr_id = (int) $row['usr_id'];
96  $fs_storage->setUserId($usr_id);
97 
98  $filename = $row['file_name'];
99  $filename_cb = static fn(string $fn) => $filename;
100  $filepath = $fs_storage->getAbsolutePath() . '/' . $filename;
101 
102  if (! file_exists($filepath)) {
103  $dir = scandir($fs_storage->getAbsolutePath());
104  if ($dir === false) {
105  throw new \Exception('cannot scan directory:' . $fs_storage->getAbsolutePath());
106  }
107  $files = array_diff($dir, ['.', '..']);
108  $filepath = $fs_storage->getAbsolutePath() . '/' . current($files);
109  if (file_exists($filepath) === false || count($files) < 1) {
110  throw new \Exception('no file in:' . $filepath);
111  }
112  }
113 
114  $resource_id = $this->helper->movePathToStorage($filepath, 6, $filename_cb);
115  if (! $resource_id) {
116  throw new \Exception('not stored:' . $filepath);
117  }
118 
119  $identifier = $resource_id->serialize();
120  $query = "UPDATE iass_members SET file_name = '$identifier' WHERE obj_id = $obj_id AND usr_id = $usr_id";
121  $this->db->manipulate($query);
122  }
123 
124  public function getRemainingAmountOfSteps(): int
125  {
126  $query = "SELECT COUNT(*) AS amount FROM iass_members WHERE file_name LIKE '%.%';";
127  $result = $this->db->query($query);
128  $row = $this->db->fetchAssoc($result);
129  return (int) $row['amount'];
130  }
131 }
ilResourceStorageMigrationHelper $helper
static init(Container $c)
Definition: Init.php:40
global $DIC
Definition: feed.php:28
$GLOBALS["DIC"]
Definition: wac.php:31
Class ilResourceStorageMigrationHelper.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
getPreconditions(Environment $environment)
$filename
Definition: buildRTE.php:78
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
prepare(Environment $environment)
step(Environment $environment)