ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStorageHandlerV1Migration.php
Go to the documentation of this file.
1 <?php
2 
22 
28 {
32  protected $iterator;
36  protected $database;
40  protected $migrator;
44  protected $resource_builder;
48  protected $data_dir;
49 
50  protected $from = 'fsv1';
51  protected $to = 'fsv2';
52 
53  public function getLabel() : string
54  {
55  return 'ilStorageHandlerV1Migration';
56  }
57 
58  public function getDefaultAmountOfStepsPerRun() : int
59  {
60  return 10000;
61  }
62 
63  public function getPreconditions(Environment $environment) : array
64  {
65  return [
66  new \ilIniFilesLoadedObjective(),
67  new \ilDatabaseUpdatedObjective(),
69  ];
70  }
71 
72  public function prepare(Environment $environment) : void
73  {
74  $ilias_ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
75  $client_id = $environment->getResource(Environment::RESOURCE_CLIENT_ID);
76 
77  $data_dir = $ilias_ini->readVariable('clients', 'datadir');
78  $this->data_dir = $data_dir . "/" . $client_id;
79 
80  $configuration = new LocalConfig("{$data_dir}/{$client_id}");
82  $filesystem = $f->getLocal($configuration);
83 
84  $this->database = $environment->getResource(Environment::RESOURCE_DATABASE);
85 
86  // ATTENTION: This is a total abomination. It only exists to allow the db-
87  // update to run. This is a memento to the fact, that dependency injection
88  // is something we want. Currently, every component could just service
89  // locate the whole world via the global $DIC.
90  $DIC = $GLOBALS["DIC"] ?? [];
91  $GLOBALS["DIC"] = new Container();
92  $GLOBALS["DIC"]["ilDB"] = $this->database;
93  $GLOBALS["ilDB"] = $this->database;
94 
95  $storage_handler_factory = new StorageHandlerFactory([
96  new MaxNestingFileSystemStorageHandler($filesystem, Location::STORAGE),
97  new FileSystemStorageHandler($filesystem, Location::STORAGE)
98  ]);
99 
100  $this->resource_builder = new ResourceBuilder(
101  $storage_handler_factory,
102  new RevisionDBRepository($this->database),
103  new ResourceDBRepository($this->database),
104  new InformationDBRepository($this->database),
105  new StakeholderDBRepository($this->database),
106  new LockHandlerilDB($this->database),
107  new FileNamePolicyStack()
108  );
109 
110  $this->migrator = new Migrator(
111  $storage_handler_factory,
112  $this->resource_builder,
113  $this->database,
114  $this->data_dir
115  );
116 
117  }
118 
119  public function step(Environment $environment) : void
120  {
122  $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
123 
124  $r = $this->database->queryF(
125  "SELECT rid FROM il_resource WHERE storage_id = %s LIMIT 1",
126  ['text'],
127  [$this->from]
128  );
129  $d = $this->database->fetchObject($r);
130  if ($d->rid) {
131  $resource = $this->resource_builder->get(new ResourceIdentification($d->rid));
132  if (!$this->migrator->migrate($resource, $this->to)) {
133  $i = $resource->getIdentification()->serialize();
134  $io->text('Resource ' . $i . ' not migrated, file not found. All Stakeholder have been informed about the deletion.');
135  }
136  }
137  }
138 
139  public function getRemainingAmountOfSteps() : int
140  {
141  $r = $this->database->queryF(
142  "SELECT COUNT(rid) as old_storage FROM il_resource WHERE storage_id != %s",
143  ['text'],
144  [$this->to]
145  );
146  $d = $this->database->fetchObject($r);
147 
148  return (int) ($d->old_storage ?? 0);
149  }
150 
151 }
step(Environment $environment)
Run one step of the migration.
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:12
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:18
$client_id
Definition: webdav.php:17
prepare(Environment $environment)
Prepare the migration by means of some environment.
global $DIC
Definition: goto.php:24
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:11
Class LocalConfig This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:13
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$i
Definition: metadata.php:24
getPreconditions(Environment $environment)
Objectives the migration depend on.