ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBookingManagerObjectInfoMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
27
28 public function getLabel(): string
29 {
30 return 'Migration of booking object info files to the resource storage service.';
31 }
32
34 {
35 return 1000;
36 }
37
38 public function getPreconditions(Environment $environment): array
39 {
41 }
42
43 public function prepare(Environment $environment): void
44 {
45 $this->helper = new ilResourceStorageMigrationHelper(new ilBookObjectInfoStakeholder(), $environment);
46 }
47
48 public function step(Environment $environment): void
49 {
50 $r = $this->helper->getDatabase()->query(
51 'SELECT booking_object_id, pool_id, owner FROM booking_object JOIN object_data ON pool_id = obj_id WHERE obj_info_rid IS NULL LIMIT 1'
52 );
53 $d = $this->helper->getDatabase()->fetchObject($r);
54 $pool_id = (int) $d->pool_id;
55 $booking_object_id = (int) $d->booking_object_id;
56 $resource_owner_id = (int) $d->owner;
57 $base_path = $this->buildAbsolutPath($booking_object_id);
58 $pattern = '/[^\.].*/m';
59 $rid = is_dir($base_path)
60 ? $this->helper->moveFirstFileOfPatternToStorage($base_path, $pattern, $resource_owner_id)
61 : '';
62 $this->helper->getDatabase()->update(
63 'booking_object',
64 [
65 'obj_info_rid' => [ilDBConstants::T_TEXT, (string) $rid]
66 ],
67 [
68 'booking_object_id' => [ilDBConstants::T_INTEGER, $booking_object_id],
69 'pool_id' => [ilDBConstants::T_INTEGER, $pool_id]
70 ]
71 );
72 }
73
74 public function getRemainingAmountOfSteps(): int
75 {
76 $r = $this->helper->getDatabase()->query(
77 'SELECT count(booking_object_id) amount FROM booking_object JOIN object_data ON pool_id = obj_id WHERE obj_info_rid IS NULL'
78 );
79
80 return (int) $this->helper->getDatabase()->fetchObject($r)->amount;
81 }
82
83 protected function buildAbsolutPath(int $booking_object_id): string
84 {
85 $path_from_id = ilFileSystemAbstractionStorage::createPathFromId($booking_object_id, 'book');
86 return CLIENT_WEB_DIR . "/ilBookingManager/{$path_from_id}/file";
87 }
88}
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getPreconditions(Environment $environment)
Objectives the migration depend on.
static createPathFromId(int $a_container_id, string $a_name)
const CLIENT_WEB_DIR
Definition: constants.php:47
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29