19 declare(strict_types=1);
39 return "Migrate FSStorage to IRSS";
44 return self::DEFAULT_AMOUNT_OF_STEPS;
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);
66 $GLOBALS[
"DIC"][
"ilSetting"] = $settings_factory->settingsFor();
67 $GLOBALS[
"DIC"][
"ilClientIniFile"] = $client_ini;
70 ilInitialisation::bootstrapFilesystems();
76 $this->helper = new \ilResourceStorageMigrationHelper(
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);
93 $obj_id = (
int) $row[
'obj_id'];
94 $usr_id = (
int) $row[
'usr_id'];
96 $fs_storage->setUserId($usr_id);
99 $filename_cb =
static fn(
string $fn) =>
$filename;
100 $filepath = $fs_storage->getAbsolutePath() .
'/' .
$filename;
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());
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);
114 $resource_id = $this->helper->movePathToStorage($filepath, 6, $filename_cb);
115 if (! $resource_id) {
116 throw new \Exception(
'not stored:' . $filepath);
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);
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'];
const DEFAULT_AMOUNT_OF_STEPS
static getInstance(int $container_id=0)
ilResourceStorageMigrationHelper $helper
static init(Container $c)
Class ilResourceStorageMigrationHelper.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
getPreconditions(Environment $environment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDefaultAmountOfStepsPerRun()
An environment holds resources to be used in the setup process.
prepare(Environment $environment)
getRemainingAmountOfSteps()
step(Environment $environment)
static getPreconditions()