ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBookingManagerBookingInfoMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21
26
28{
29 protected \ilResourceStorageMigrationHelper $helper;
30
31 public function getLabel(): string
32 {
33 return "Migration of post booking info files to the resource storage service.";
34 }
35
37 {
38 return 1000;
39 }
40
41 public function getPreconditions(Environment $environment): array
42 {
43 return \ilResourceStorageMigrationHelper::getPreconditions();
44 }
45
46 public function prepare(Environment $environment): void
47 {
48 $this->helper = new \ilResourceStorageMigrationHelper(
50 $environment
51 );
52 }
53
54 public function step(Environment $environment): void
55 {
56 $db = $this->helper->getDatabase();
57 $r = $this->helper->getDatabase()->query(
58 "SELECT booking_object_id, pool_id, owner FROM booking_object JOIN object_data ON pool_id = obj_id WHERE book_info_rid IS NULL LIMIT 1;"
59 );
60 $d = $this->helper->getDatabase()->fetchObject($r);
61 $pool_id = (int) $d->pool_id;
62 $booking_object_id = (int) $d->booking_object_id;
63 $resource_owner_id = (int) $d->owner;
64 $base_path = $this->buildAbsolutPath($pool_id, $booking_object_id);
65 $pattern = '/[^\.].*/m';
66 $rid = "";
67 if (is_dir($base_path)) {
68 $rid = $this->helper->moveFirstFileOfPatternToStorage(
69 $base_path,
70 $pattern,
71 $resource_owner_id
72 );
73 }
74 $this->helper->getDatabase()->update(
75 'booking_object',
76 [
77 'book_info_rid' => ['text', (string) $rid]
78 ],
79 [
80 'booking_object_id' => ['integer', $booking_object_id],
81 'pool_id' => ['integer', $pool_id]
82 ]
83 );
84 }
85
86 public function getRemainingAmountOfSteps(): int
87 {
88 $r = $this->helper->getDatabase()->query(
89 "SELECT count(booking_object_id) amount FROM booking_object JOIN object_data ON pool_id = obj_id WHERE book_info_rid IS NULL"
90 );
91 $d = $this->helper->getDatabase()->fetchObject($r);
92
93 return (int) $d->amount;
94 }
95
96 protected function buildAbsolutPath(int $pool_id, int $booking_object_id): string
97 {
98 return CLIENT_WEB_DIR
99 . '/ilBookingManager/'
101 $booking_object_id,
102 "book"
103 ) . "/post";
104 }
105}
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
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.
step(Environment $environment)
Run one step of the migration.
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