ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilHTLMMigration Class Reference
+ Inheritance diagram for ilHTLMMigration:
+ Collaboration diagram for ilHTLMMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 
 getFileNameCallback (string $pattern)
 
 getRevisionNameCallback ()
 
 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Protected Member Functions

 determineStartFile (string $lm_path, string $start_file)
 Learning modules without a stored start file relied on a fallback to index.html or index.htm before the migration. More...
 
 buildBasePath (int $object_id)
 

Protected Attributes

ilResourceStorageMigrationHelper $helper
 

Private Member Functions

 recursiveRmDir (string $path)
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Definition at line 25 of file class.ilHTLMMigration.php.

Member Function Documentation

◆ buildBasePath()

ilHTLMMigration::buildBasePath ( int  $object_id)
protected

Definition at line 127 of file class.ilHTLMMigration.php.

127 : string
128 {
129 return CLIENT_WEB_DIR . '/lm_data/lm_' . $object_id;
130 }
const CLIENT_WEB_DIR
Definition: constants.php:47

References CLIENT_WEB_DIR.

Referenced by step().

+ Here is the caller graph for this function:

◆ determineStartFile()

ilHTLMMigration::determineStartFile ( string  $lm_path,
string  $start_file 
)
protected

Learning modules without a stored start file relied on a fallback to index.html or index.htm before the migration.

Persist that fallback, the stored start file wins.

Definition at line 95 of file class.ilHTLMMigration.php.

95 : string
96 {
97 if ($start_file !== '') {
98 return $start_file;
99 }
100 foreach (['index.html', 'index.htm'] as $candidate) {
101 if (is_file($lm_path . '/' . $candidate)) {
102 return $candidate;
103 }
104 }
105 return '';
106 }

Referenced by step().

+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilHTLMMigration::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 34 of file class.ilHTLMMigration.php.

34 : int
35 {
36 return 10000;
37 }

◆ getFileNameCallback()

ilHTLMMigration::getFileNameCallback ( string  $pattern)

Definition at line 132 of file class.ilHTLMMigration.php.

132 : Closure
133 {
134 return static function (string $file_name) use ($pattern): string {
135 if (preg_match($pattern, $file_name, $matches)) {
136 return $matches[1] ?? $file_name;
137 }
138 return $file_name;
139 };
140 }

References $pattern.

◆ getLabel()

ilHTLMMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 29 of file class.ilHTLMMigration.php.

29 : string
30 {
31 return 'Migration of HTML Learning Modules to the Resource Storage Service.';
32 }

◆ getPreconditions()

ilHTLMMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 39 of file class.ilHTLMMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilHTLMMigration::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 117 of file class.ilHTLMMigration.php.

117 : int
118 {
119 $r = $this->helper->getDatabase()->query(
120 "SELECT COUNT(id) AS amount FROM file_based_lm WHERE rid IS NULL OR rid = ''"
121 );
122 $d = $this->helper->getDatabase()->fetchObject($r) ?? new stdClass();
123
124 return (int) ($d->amount ?? 0);
125 }

References Vendor\Package\$d.

◆ getRevisionNameCallback()

ilHTLMMigration::getRevisionNameCallback ( )

Definition at line 142 of file class.ilHTLMMigration.php.

142 : Closure
143 {
144 return static function (string $file_name): string {
145 return md5($file_name);
146 };
147 }

◆ prepare()

ilHTLMMigration::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 44 of file class.ilHTLMMigration.php.

44 : void
45 {
46 $this->helper = new ilResourceStorageMigrationHelper(
48 $environment
49 );
50 }

◆ recursiveRmDir()

ilHTLMMigration::recursiveRmDir ( string  $path)
private

Definition at line 108 of file class.ilHTLMMigration.php.

108 : void
109 {
110 // recursively remove directory
111 $files = array_diff(scandir($path), ['.', '..']);
112 foreach ($files as $file) {
113 (is_dir("$path/$file")) ? $this->recursiveRmDir("$path/$file") : unlink("$path/$file");
114 }
115 }
recursiveRmDir(string $path)

References $files, and recursiveRmDir().

Referenced by recursiveRmDir(), and step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ step()

ilHTLMMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 52 of file class.ilHTLMMigration.php.

52 : void
53 {
54 $r = $this->helper->getDatabase()->query(
55 "SELECT id, startfile FROM file_based_lm WHERE rid IS NULL OR rid = '' LIMIT 1;"
56 );
57
58 $d = $this->helper->getDatabase()->fetchObject($r);
59 $object_id = (int) ($d->id ?? null);
60
61 $resource_owner_id = (int) ($d->owner_id ?? 6); // TODO JOIN
62
63 $lm_path = $this->buildBasePath($object_id);
64 $start_file = $this->determineStartFile($lm_path, (string) ($d->startfile ?? ''));
65
66 $rid = $this->helper->moveDirectoryToContainerResource(
67 $lm_path,
68 $resource_owner_id
69 );
70
71 if ($rid !== null) {
72 $this->helper->getDatabase()->update(
73 'file_based_lm',
74 [
75 'rid' => ['text', $rid->serialize()],
76 'startfile' => ['text', $start_file],
77 ],
78 ['id' => ['integer', $object_id],]
79 );
80
81 $this->recursiveRmDir($lm_path);
82 } else {
83 $this->helper->getDatabase()->update(
84 'file_based_lm',
85 ['rid' => ['text', '-']],
86 ['id' => ['integer', $object_id],]
87 );
88 }
89 }
determineStartFile(string $lm_path, string $start_file)
Learning modules without a stored start file relied on a fallback to index.html or index....
buildBasePath(int $object_id)

References Vendor\Package\$d, buildBasePath(), determineStartFile(), ILIAS\Repository\int(), and recursiveRmDir().

+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilHTLMMigration::$helper
protected

Definition at line 27 of file class.ilHTLMMigration.php.


The documentation for this class was generated from the following file: