65 $db = $environment->
getResource(Environment::RESOURCE_DATABASE);
66 $ilias_ini = $environment->
getResource(Environment::RESOURCE_ILIAS_INI);
68 $data_dir = $ilias_ini->readVariable(
'clients',
'datadir');
70 if (!defined(
"CLIENT_WEB_DIR")) {
71 define(
"CLIENT_WEB_DIR", dirname(__DIR__, 5) .
"/public/data/" .
$client_id);
73 if (!defined(
"ILIAS_WEB_DIR")) {
74 define(
"ILIAS_WEB_DIR",
'public/data');
76 if (!defined(
"CLIENT_ID")) {
79 if (!defined(
"ILIAS_DATA_DIR")) {
85 if (!is_writable(
"{$data_dir}/{$client_id}/storage/fsv2")) {
86 throw new Exception(
'storage directory is not writable, abort...');
95 $container[
'filesystem.storage'] =
$f->getLocal($storageConfiguration);
97 $this->resource_builder = $init->getResourceBuilder(
$container);
98 $this->flavour_builder = $init->getFlavourBuilder(
$container);
107 $this->resource_builder,
108 $this->collection_builder,
140 return $this->stakeholder;
166 ?
int $new_owner_id =
null
168 $resource = $this->manager->getResource($resource_identification);
169 $resource->removeStakeholder($old_stakeholder);
170 $this->repositories->getStakeholderRepository()->deregister($resource_identification, $old_stakeholder);
171 $resource->addStakeholder($new_stakeholder);
172 $this->repositories->getStakeholderRepository()->register($resource_identification, $new_stakeholder);
174 if ($new_owner_id !==
null) {
175 foreach ($resource->getAllRevisionsIncludingDraft() as $revision) {
176 $revision->setOwnerId($new_owner_id);
180 $this->resource_builder->store($resource);
184 public function moveFilesOfPathToCollection(
185 string $absolute_path,
186 int $resource_owner_id,
187 int $collection_owner_user_id = ResourceCollection::NO_SPECIFIC_OWNER,
188 ?Closure $file_name_callback =
null,
189 ?Closure $revision_name_callback =
null
191 $collection = $this->getCollectionBuilder()->new($collection_owner_user_id);
193 foreach (
new DirectoryIterator($absolute_path) as $file_info) {
194 if (!$file_info->isFile()) {
197 $resource_id = $this->movePathToStorage(
198 $file_info->getRealPath(),
201 $revision_name_callback
203 if ($resource_id !==
null) {
204 $collection->add($resource_id);
208 if ($this->getCollectionBuilder()->store($collection)) {
209 return $collection->getIdentification();
215 string $absolute_base_path,
217 int $resource_owner_id,
218 int $collection_owner_user_id = ResourceCollection::NO_SPECIFIC_OWNER,
219 ?Closure $file_name_callback =
null,
220 ?Closure $revision_name_callback =
null
222 $collection = $this->getCollectionBuilder()->new($collection_owner_user_id);
224 $regex_iterator = $this->buildRecursivePatternIterator($absolute_base_path, $pattern);
226 foreach ($regex_iterator as $file_info) {
227 if (!$file_info->isFile()) {
230 $resource_id = $this->movePathToStorage(
231 $file_info->getRealPath(),
234 $revision_name_callback
236 if ($resource_id !==
null) {
237 $collection->add($resource_id);
240 if ($collection->count() === 0) {
244 if ($this->getCollectionBuilder()->store($collection)) {
245 return $collection->getIdentification();
251 string $absolute_base_path,
253 int $resource_owner_id,
254 ?Closure $file_name_callback =
null,
255 ?Closure $revision_name_callback =
null
257 $regex_iterator = $this->buildRecursivePatternIterator($absolute_base_path, $pattern);
259 foreach ($regex_iterator as $file_info) {
260 if (!$file_info->isFile()) {
263 $resource_id = $this->movePathToStorage(
264 $file_info->getRealPath(),
267 $revision_name_callback
269 if ($resource_id !==
null) {
278 string $absolute_path,
280 ?Closure $file_name_callback =
null,
281 ?Closure $revision_name_callback =
null,
282 ?
bool $copy_instead_of_move =
false
286 $open_path = fopen($absolute_path,
'rb');
287 }
catch (Throwable) {
291 if ($open_path ===
false) {
294 $stream = Streams::ofResource($open_path);
297 $revision_title = $revision_name_callback !==
null
298 ? $revision_name_callback(basename($absolute_path))
299 : basename($absolute_path);
301 $file_name = $file_name_callback !==
null
302 ? $file_name_callback(basename($absolute_path))
305 $resource = $this->resource_builder->newFromStream(
314 $copy_instead_of_move ??
false
318 $resource->addStakeholder($this->stakeholder);
319 $this->resource_builder->store($resource);
321 return $resource->getIdentification();
325 string $absolute_path_to_directory,
329 if (!is_dir($absolute_path_to_directory)) {
334 (
new ZipOptions())->withDirectoryHandling(ZipDirectoryHandling::KEEP_STRUCTURE)
336 $zip->addDirectory($absolute_path_to_directory);
338 $zip_stream = $zip->get();
339 }
catch (Throwable
$e) {
344 $resource = $this->resource_builder->newFromStream(
350 basename($absolute_path_to_directory),
351 basename($absolute_path_to_directory)
358 $resource->addStakeholder($this->stakeholder);
359 $this->resource_builder->store($resource);
364 return $resource->getIdentification();
368 string $absolute_base_path,
369 string $pattern =
'.*'
370 ): RecursiveRegexIterator {
371 return new RecursiveRegexIterator(
372 new RecursiveDirectoryIterator($absolute_base_path),
374 RecursiveRegexIterator::MATCH
Customizing of pimple-DIC for ILIAS.
This class is used to configure the local filesystem adapter.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Class ResourceCollection.
Class ResourceCollectionIdentification.
Class ResourceIdentification.
Class CollectionDBRepository.
Responsible for loading the Resource Storage into the dependency injection container of ILIAS.
const D_REPOSITORY_PRELOADER
This class attempt to achieve a set of database update steps.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilResourceStorageDB90.
Class ilResourceStorageMigrationHelper.
buildRecursivePatternIterator(string $absolute_base_path, string $pattern='.*')
static getPreconditions()
CollectionBuilder $collection_builder
moveResourceToNewStakeholderAndOwner(ResourceIdentification $resource_identification, ResourceStakeholder $old_stakeholder, ResourceStakeholder $new_stakeholder, ?int $new_owner_id=null)
__construct(protected ResourceStakeholder $stakeholder, Environment $environment)
ilResourceStorageMigrationHelper constructor.
movePathToStorage(string $absolute_path, int $owner_user_id, ?Closure $file_name_callback=null, ?Closure $revision_name_callback=null, ?bool $copy_instead_of_move=false)
Repositories $repositories
moveDirectoryToContainerResource(string $absolute_path_to_directory, int $owner_user_id,)
moveFilesOfPatternToCollection(string $absolute_base_path, string $pattern, int $resource_owner_id, int $collection_owner_user_id=ResourceCollection::NO_SPECIFIC_OWNER, ?Closure $file_name_callback=null, ?Closure $revision_name_callback=null)
FlavourBuilder $flavour_builder
ResourceBuilder $resource_builder
moveFirstFileOfPatternToStorage(string $absolute_base_path, string $pattern, int $resource_owner_id, ?Closure $file_name_callback=null, ?Closure $revision_name_callback=null)
Class ilStorageContainersExistingObjective.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ResourceStakeholder.
An environment holds resources to be used in the setup process.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
if(!file_exists('../ilias.ini.php'))