66 $db = $environment->
getResource(Environment::RESOURCE_DATABASE);
67 $ilias_ini = $environment->
getResource(Environment::RESOURCE_ILIAS_INI);
69 $data_dir = $ilias_ini->readVariable(
'clients',
'datadir');
70 $client_data_dir =
"{$data_dir}/{$client_id}";
71 if (!defined(
"CLIENT_WEB_DIR")) {
72 define(
"CLIENT_WEB_DIR", dirname(__DIR__, 4) .
"/data/" .
$client_id);
74 if (!defined(
"ILIAS_WEB_DIR")) {
75 define(
"ILIAS_WEB_DIR", dirname(__DIR__, 4));
77 if (!defined(
"CLIENT_ID")) {
80 if (!defined(
"ILIAS_DATA_DIR")) {
84 $this->database = $db;
86 if (!is_writable(
"{$data_dir}/{$client_id}/storage/fsv2")) {
87 throw new Exception(
'storage directory is not writable, abort...');
94 $storageConfiguration =
new LocalConfig($client_data_dir);
96 $container[
'filesystem.storage'] =
$f->getLocal($storageConfiguration);
98 $this->resource_builder = $init->getResourceBuilder(
$container);
99 $this->flavour_builder = $init->getFlavourBuilder(
$container);
108 $this->resource_builder,
109 $this->collection_builder,
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
193 foreach (
new DirectoryIterator($absolute_path) as $file_info) {
194 if (!$file_info->isFile()) {
198 $file_info->getRealPath(),
201 $revision_name_callback
203 if ($resource_id !== null) {
204 $collection->add($resource_id);
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
226 foreach ($regex_iterator as $file_info) {
227 if (!$file_info->isFile()) {
231 $file_info->getRealPath(),
234 $revision_name_callback
236 if ($resource_id !== null) {
237 $collection->add($resource_id);
240 if ($collection->count() === 0) {
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
259 foreach ($regex_iterator as $file_info) {
260 if (!$file_info->isFile()) {
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');
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_base_path,
326 string $pattern =
'.*' 327 ): RecursiveRegexIterator {
328 return new RecursiveRegexIterator(
331 RecursiveRegexIterator::MATCH
buildRecursivePatternIterator(string $absolute_base_path, string $pattern='.*')
FlavourBuilder $flavour_builder
Class ilResourceStorageDB90.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilStorageContainersExistingObjective.
const D_REPOSITORY_PRELOADER
Responsible for loading the Resource Storage into the dependency injection container of ILIAS...
Class ResourceCollectionIdentification.
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.
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