ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStorageHandlerV1Migration.php
Go to the documentation of this file.
1 <?php
2 
27 
33 {
34  protected \DirectoryIterator $iterator;
38  protected $database;
41  protected ?string $data_dir = null;
42 
43  protected string $from = 'fsv1';
44  protected string $to = 'fsv2';
45 
46  public function getLabel(): string
47  {
48  return \ilStorageHandlerV1Migration::class;
49  }
50 
52  {
53  return 10000;
54  }
55 
59  public function getPreconditions(Environment $environment): array
60  {
61  return [
62  new \ilIniFilesLoadedObjective(),
63  new \ilDatabaseUpdatedObjective(),
65  ];
66  }
67 
68  public function prepare(Environment $environment): void
69  {
70  $ilias_ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
71  $client_id = $environment->getResource(Environment::RESOURCE_CLIENT_ID);
72 
73  $data_dir = $ilias_ini->readVariable('clients', 'datadir');
74  $this->data_dir = $data_dir . "/" . $client_id;
75 
76  $configuration = new LocalConfig("{$data_dir}/{$client_id}");
78  $filesystem = $f->getLocal($configuration);
79 
80  $this->database = $environment->getResource(Environment::RESOURCE_DATABASE);
82  // ATTENTION: This is a total abomination. It only exists to allow the db-
83  // update to run. This is a memento to the fact, that dependency injection
84  // is something we want. Currently, every component could just service
85  // locate the whole world via the global $DIC.
87  $DIC = $GLOBALS["DIC"] ?? [];
88  $GLOBALS["DIC"] = new Container();
89  $GLOBALS["DIC"]["ilDB"] = $this->database;
90  $GLOBALS["ilDB"] = $this->database;
91 
92  // Build Container
93  $init = new InitResourceStorage();
94  $container = new Container();
95  $container['ilDB'] = $this->database;
96  $container['filesystem.storage'] = $filesystem;
97 
98  $this->resource_builder = $init->getResourceBuilder($container);
99 
100  $this->migrator = new Migrator(
102  $this->resource_builder,
103  $this->database,
104  $this->data_dir
105  );
106  }
107 
108  public function step(Environment $environment): void
109  {
111  $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
112 
113  $r = $this->database->queryF(
114  "SELECT rid FROM il_resource WHERE storage_id = %s LIMIT 1",
115  ['text'],
116  [$this->from]
117  );
118  $d = $this->database->fetchObject($r);
119  if ($d->rid) {
120  $resource = $this->resource_builder->get(new ResourceIdentification($d->identification));
121  if (!$this->migrator->migrate($resource, $this->to)) {
122  $i = $resource->getIdentification()->serialize();
123  $io->text(
124  'Resource ' . $i . ' not migrated, file not found. All Stakeholder have been informed about the deletion.'
125  );
126  }
127  }
128  }
129 
130  public function getRemainingAmountOfSteps(): int
131  {
132  $r = $this->database->queryF(
133  "SELECT COUNT(rid) as old_storage FROM il_resource WHERE storage_id != %s",
134  ['text'],
135  [$this->to]
136  );
137  $d = $this->database->fetchObject($r);
138 
139  return (int)($d->old_storage ?? 0);
140  }
141 }
step(Environment $environment)
Run one step of the migration.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
Responsible for loading the Resource Storage into the dependency injection container of ILIAS...
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
$container
Definition: wac.php:14
prepare(Environment $environment)
Prepare the migration by means of some environment.
global $DIC
Definition: feed.php:28
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
Class ilStorageHandlerV1Migration.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
ILIAS ResourceStorage StorageHandler Migrator $migrator
$client_id
Definition: ltiauth.php:68
ILIAS ResourceStorage Resource ResourceBuilder $resource_builder
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$i
Definition: metadata.php:41