ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMobMigration Class Reference
+ Inheritance diagram for ilMobMigration:
+ Collaboration diagram for ilMobMigration:

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 ()
 

Protected Member Functions

 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.ilMobMigration.php.

Member Function Documentation

◆ buildBasePath()

ilMobMigration::buildBasePath ( int  $object_id)
protected

Definition at line 113 of file class.ilMobMigration.php.

References CLIENT_WEB_DIR.

Referenced by step().

113  : string
114  {
115  return CLIENT_WEB_DIR . '/mobs/mm_' . $object_id;
116  }
const CLIENT_WEB_DIR
Definition: constants.php:47
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilMobMigration::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.ilMobMigration.php.

34  : int
35  {
36  return 10000;
37  }

◆ getFileNameCallback()

ilMobMigration::getFileNameCallback ( string  $pattern)

Definition at line 118 of file class.ilMobMigration.php.

118  : Closure
119  {
120  return static function (string $file_name) use ($pattern): string {
121  if (preg_match($pattern, $file_name, $matches)) {
122  return $matches[1] ?? $file_name;
123  }
124  return $file_name;
125  };
126  }

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

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

29  : string
30  {
31  return 'Migration of Media Objects to the Resource Storage Service.';
32  }

◆ getPreconditions()

ilMobMigration::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.ilMobMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilMobMigration::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 104 of file class.ilMobMigration.php.

References Vendor\Package\$d, and $r.

104  : int
105  {
106  $r = $this->helper->getDatabase()->query(
107  "SELECT COUNT(od.obj_id) amount FROM object_data od LEFT JOIN mob_data md ON (od.obj_id = md.id) WHERE od.type='mob' AND (rid='' OR rid IS NULL)"
108  );
109  $d = $this->helper->getDatabase()->fetchObject($r) ?? new stdClass();
110  return (int) ($d->amount ?? 0);
111  }
$r

◆ getRevisionNameCallback()

ilMobMigration::getRevisionNameCallback ( )

Definition at line 128 of file class.ilMobMigration.php.

128  : Closure
129  {
130  return static function (string $file_name): string {
131  return md5($file_name);
132  };
133  }

◆ prepare()

ilMobMigration::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.ilMobMigration.php.

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

◆ recursiveRmDir()

ilMobMigration::recursiveRmDir ( string  $path)
private

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

Referenced by step().

95  : void
96  {
97  // recursively remove directory
98  $files = array_diff(scandir($path), ['.', '..']);
99  foreach ($files as $file) {
100  (is_dir("$path/$file")) ? $this->recursiveRmDir("$path/$file") : unlink("$path/$file");
101  }
102  }
$path
Definition: ltiservices.php:29
recursiveRmDir(string $path)
+ Here is the caller graph for this function:

◆ step()

ilMobMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

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

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

52  : void
53  {
54  $r = $this->helper->getDatabase()->query(
55  "SELECT * FROM object_data od LEFT JOIN mob_data md ON (od.obj_id = md.id) WHERE od.type='mob' AND (rid='' OR rid IS NULL) LIMIT 1;"
56  );
57 
58  $d = $this->helper->getDatabase()->fetchObject($r);
59  $object_id = (int) ($d->obj_id ?? null);
60 
61  $resource_owner_id = (int) ($d->owner_id ?? 6); // TODO JOIN
62 
63  $mob_path = $this->buildBasePath($object_id);
64 
65  $rid = $this->helper->moveDirectoryToContainerResource(
66  $mob_path,
67  $resource_owner_id
68  );
69 
70  if ($rid !== null) {
71  $this->helper->getDatabase()->replace(
72  "mob_data",
73  [
74  "id" => ["integer", $object_id]
75  ],
76  [
77  "rid" => ["text", $rid->serialize()]
78  ]
79  );
80 
81  $this->recursiveRmDir($mob_path);
82  } else {
83  $this->helper->getDatabase()->replace(
84  "mob_data",
85  [
86  "id" => ["integer", $object_id]
87  ],
88  [
89  "rid" => ["text", "-"]
90  ]
91  );
92  }
93  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
buildBasePath(int $object_id)
recursiveRmDir(string $path)
$r
+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilMobMigration::$helper
protected

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


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