ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileObjectToStorageMigration.php
Go to the documentation of this file.
1<?php
2
7
9{
10 private const FILE_PATH_REGEX = '/.*\/file_([\d]*)$/';
11 public const MIGRATION_LOG_CSV = "migration_log.csv";
12
16 private $helper;
20 protected $prepared = false;
24 protected $runner;
28 protected $database;
29
33 public function getLabel() : string
34 {
35 return "Migration of File-Objects to Storage service";
36 }
37
41 public function getDefaultAmountOfStepsPerRun() : int
42 {
43 return 10;
44 }
45
49 public function getPreconditions(Environment $environment) : array
50 {
51 return [
56 ];
57 }
58
62 public function prepare(Environment $environment) : void
63 {
69 $ilias_ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
70 $this->database = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
71
72 $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
73 $data_dir = $ilias_ini->readVariable('clients', 'datadir');
74
75 if (!$this->prepared) {
76 global $DIC;
77 $DIC['ilDB'] = $this->database;
78 $DIC['ilBench'] = null;
79
80 $legacy_files_dir = "{$data_dir}/{$client_id}/ilFile";
81 if (!defined("CLIENT_DATA_DIR")) {
82 define('CLIENT_DATA_DIR', "{$data_dir}/{$client_id}");
83 }
84 if (!defined("CLIENT_ID")) {
85 define('CLIENT_ID', $client_id);
86 }
87 if (!defined("ILIAS_ABSOLUTE_PATH")) {
88 define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
89 }
90 if (!defined("ILIAS_WEB_DIR")) {
91 define('ILIAS_WEB_DIR', dirname(__DIR__, 4) . "/data/");
92 }
93 if (!defined("CLIENT_WEB_DIR")) {
94 define("CLIENT_WEB_DIR", dirname(__DIR__, 4) . "/data/" . $client_id);
95 }
96
97 // if dir doesn't exists there are no steps to do,
98 // so don't initialize ilFileObjectToStorageMigrationHelper
99 if (!is_dir($legacy_files_dir)) {
101 $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
102 $io->inform("The legacy ilFile-directory ($legacy_files_dir) cannot be found, we cant perform a migration.");
103 return;
104 }
105
106 if (!is_readable($legacy_files_dir)) {
107 throw new Exception("{$legacy_files_dir} is not readable, abort...");
108 }
109
110 if (!is_writable("{$data_dir}/{$client_id}/storage")) {
111 throw new Exception("storage directory is not writable, abort...");
112 }
113
114 $this->helper = new ilFileObjectToStorageMigrationHelper($legacy_files_dir, $this->database);
115
116 $storageConfiguration = new LocalConfig("{$data_dir}/{$client_id}");
118
119 $this->runner = new ilFileObjectToStorageMigrationRunner(
120 $f->getLocal($storageConfiguration),
121 $this->database,
122 $legacy_files_dir . "/" . self::MIGRATION_LOG_CSV
123 );
124
125 }
126 }
127
131 public function step(Environment $environment) : void
132 {
133 if ($this->helper === null) {
134 return;
135 }
136 $item = $this->helper->getNext();
137 $this->runner->migrate($item);
138 }
139
143 public function getRemainingAmountOfSteps() : int
144 {
145 $r = $this->database->query("SELECT COUNT(file_id) AS amount FROM file_data WHERE rid IS NULL OR rid = '';");
146 $d = $this->database->fetchObject($r);
147
148 return (int) $d->amount;
149 }
150
151}
An exception for terminatinating execution or to throw for unit testing.
Class LocalConfig This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:14
step(Environment $environment)
@inheritDoc
getPreconditions(Environment $environment)
@inheritDoc
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: goto.php:24
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:13
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$client_id
Definition: webdav.php:17