70 $db = $environment->
getResource(Environment::RESOURCE_DATABASE);
71 $ilias_ini = $environment->
getResource(Environment::RESOURCE_ILIAS_INI);
73 $data_dir = $ilias_ini->readVariable(
'clients',
'datadir');
74 $client_data_dir =
"{$data_dir}/{$client_id}";
75 if (!defined(
"CLIENT_WEB_DIR")) {
76 define(
"CLIENT_WEB_DIR", dirname(__DIR__, 5) .
"/public/data/" .
$client_id);
78 if (!defined(
"ILIAS_WEB_DIR")) {
79 define(
"ILIAS_WEB_DIR",
'public/data');
81 if (!defined(
"CLIENT_ID")) {
84 if (!defined(
"ILIAS_DATA_DIR")) {
88 $this->database = $db;
90 if (!is_writable(
"{$data_dir}/{$client_id}/storage/fsv2")) {
91 throw new Exception(
'storage directory is not writable, abort...');
98 $storageConfiguration =
new LocalConfig($client_data_dir);
100 $container[
'filesystem.storage'] =
$f->getLocal($storageConfiguration);
102 $this->resource_builder = $init->getResourceBuilder(
$container);
103 $this->flavour_builder = $init->getFlavourBuilder(
$container);
112 $this->resource_builder,
113 $this->collection_builder,
171 ?
int $new_owner_id = null
173 $resource = $this->manager->getResource($resource_identification);
174 $resource->removeStakeholder($old_stakeholder);
175 $this->repositories->getStakeholderRepository()->deregister($resource_identification, $old_stakeholder);
176 $resource->addStakeholder($new_stakeholder);
177 $this->repositories->getStakeholderRepository()->register($resource_identification, $new_stakeholder);
179 if ($new_owner_id !== null) {
180 foreach ($resource->getAllRevisionsIncludingDraft() as $revision) {
181 $revision->setOwnerId($new_owner_id);
185 $this->resource_builder->store($resource);
189 public function moveFilesOfPathToCollection(
190 string $absolute_path,
191 int $resource_owner_id,
192 int $collection_owner_user_id = ResourceCollection::NO_SPECIFIC_OWNER,
193 ?
Closure $file_name_callback = null,
194 ?
Closure $revision_name_callback = null
199 if (!$file_info->isFile()) {
203 $file_info->getRealPath(),
206 $revision_name_callback
208 if ($resource_id !== null) {
209 $collection->add($resource_id);
214 return $collection->getIdentification();
220 string $absolute_base_path,
222 int $resource_owner_id,
223 int $collection_owner_user_id = ResourceCollection::NO_SPECIFIC_OWNER,
224 ?
Closure $file_name_callback = null,
225 ?
Closure $revision_name_callback = null
231 foreach ($regex_iterator as $file_info) {
232 if (!$file_info->isFile()) {
236 $file_info->getRealPath(),
239 $revision_name_callback
241 if ($resource_id !== null) {
242 $collection->add($resource_id);
245 if ($collection->count() === 0) {
250 return $collection->getIdentification();
256 string $absolute_base_path,
258 int $resource_owner_id,
259 ?
Closure $file_name_callback = null,
260 ?
Closure $revision_name_callback = null
264 foreach ($regex_iterator as $file_info) {
265 if (!$file_info->isFile()) {
269 $file_info->getRealPath(),
272 $revision_name_callback
274 if ($resource_id !== null) {
283 string $absolute_path,
285 ?
Closure $file_name_callback = null,
286 ?
Closure $revision_name_callback = null,
287 ?
bool $copy_instead_of_move =
false 291 $open_path = fopen($absolute_path,
'rb');
296 if ($open_path ===
false) {
299 $stream = Streams::ofResource($open_path);
302 $revision_title = $revision_name_callback !== null
303 ? $revision_name_callback(basename($absolute_path))
304 : basename($absolute_path);
306 $file_name = $file_name_callback !== null
307 ? $file_name_callback(basename($absolute_path))
310 $resource = $this->resource_builder->newFromStream(
319 $copy_instead_of_move ??
false 323 $resource->addStakeholder($this->stakeholder);
324 $this->resource_builder->store($resource);
326 return $resource->getIdentification();
330 string $absolute_path_to_directory,
334 if (!is_dir($absolute_path_to_directory)) {
339 (
new ZipOptions())->withDirectoryHandling(ZipDirectoryHandling::KEEP_STRUCTURE)
341 $zip->addDirectory($absolute_path_to_directory);
343 $zip_stream = $zip->get();
349 $resource = $this->resource_builder->newFromStream(
355 basename($absolute_path_to_directory),
356 basename($absolute_path_to_directory)
363 $resource->addStakeholder($this->stakeholder);
364 $this->resource_builder->store($resource);
369 return $resource->getIdentification();
373 string $absolute_base_path,
374 string $pattern =
'.*' 375 ): RecursiveRegexIterator {
376 return new RecursiveRegexIterator(
379 RecursiveRegexIterator::MATCH
buildRecursivePatternIterator(string $absolute_base_path, string $pattern='.*')
FlavourBuilder $flavour_builder
Class ilResourceStorageDB90.
Class ilStorageContainersExistingObjective.
const D_REPOSITORY_PRELOADER
Responsible for loading the Resource Storage into the dependency injection container of ILIAS...
Class ResourceCollectionIdentification.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Repositories $repositories
moveResourceToNewStakeholderAndOwner(ResourceIdentification $resource_identification, ResourceStakeholder $old_stakeholder, ResourceStakeholder $new_stakeholder, ?int $new_owner_id=null)
Class CollectionDBRepository.
Customizing of pimple-DIC for ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ResourceStakeholder $stakeholder
Class ResourceIdentification.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
movePathToStorage(string $absolute_path, int $owner_user_id, ?Closure $file_name_callback=null, ?Closure $revision_name_callback=null, ?bool $copy_instead_of_move=false)
__construct(ResourceStakeholder $stakeholder, Environment $environment)
ilResourceStorageMigrationHelper constructor.
moveDirectoryToContainerResource(string $absolute_path_to_directory, int $owner_user_id,)
moveFirstFileOfPatternToStorage(string $absolute_base_path, string $pattern, int $resource_owner_id, ?Closure $file_name_callback=null, ?Closure $revision_name_callback=null)
An environment holds resources to be used in the setup process.
CollectionBuilder $collection_builder
This class is used to configure the local filesystem adapter.
Interface ResourceStakeholder.
static getPreconditions()
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)
ResourceBuilder $resource_builder