ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilForumPostingFilesMigration Class Reference
+ Inheritance diagram for ilForumPostingFilesMigration:
+ Collaboration diagram for ilForumPostingFilesMigration:

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

Protected Attributes

ilResourceStorageMigrationHelper $helper
 

Additional Inherited Members

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

Detailed Description

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

Member Function Documentation

◆ buildBasePath()

ilForumPostingFilesMigration::buildBasePath ( )
protected

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

References CLIENT_DATA_DIR.

117  : string
118  {
119  return CLIENT_DATA_DIR . '/forum/';
120  }
const CLIENT_DATA_DIR
Definition: constants.php:46

◆ getDefaultAmountOfStepsPerRun()

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

34  : int
35  {
36  return 10000;
37  }

◆ getFileNameCallback()

ilForumPostingFilesMigration::getFileNameCallback ( string  $pattern)

Definition at line 122 of file class.ilForumPostingFilesMigration.php.

Referenced by step().

122  : Closure
123  {
124  return static function (string $file_name) use ($pattern): string {
125  if (preg_match($pattern, $file_name, $matches)) {
126  return $matches[1] ?? $file_name;
127  }
128  return $file_name;
129  };
130  }
+ Here is the caller graph for this function:

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

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

29  : string
30  {
31  return 'Migration of Files in Forum Posts to the Resource Storage Service.';
32  }

◆ getPreconditions()

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

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilForumPostingFilesMigration::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 103 of file class.ilForumPostingFilesMigration.php.

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

103  : int
104  {
105  $r = $this->helper->getDatabase()->query(
106  "SELECT
107  count(frm_posts.pos_pk) AS amount
108 FROM frm_posts
109 JOIN frm_data ON frm_posts.pos_top_fk = frm_data.top_pk
110 WHERE frm_posts.rcid IS NULL OR frm_posts.rcid = '';"
111  );
112  $d = $this->helper->getDatabase()->fetchObject($r);
113 
114  return (int) $d->amount;
115  }
$r

◆ getRevisionNameCallback()

ilForumPostingFilesMigration::getRevisionNameCallback ( )

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

Referenced by step().

132  : Closure
133  {
134  return static function (string $file_name): string {
135  return md5($file_name);
136  };
137  }
+ Here is the caller graph for this function:

◆ prepare()

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

◆ step()

ilForumPostingFilesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

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

References Vendor\Package\$d, $r, getFileNameCallback(), getRevisionNameCallback(), and ILIAS\Repository\int().

52  : void
53  {
54  $r = $this->helper->getDatabase()->query(
55  "SELECT
56  frm_posts.pos_pk AS posting_id,
57  frm_posts.pos_author_id AS owner_id,
58  frm_data.top_frm_fk AS object_id
59 FROM frm_posts
60 JOIN frm_data ON frm_posts.pos_top_fk = frm_data.top_pk
61 WHERE frm_posts.rcid IS NULL OR frm_posts.rcid = ''
62 LIMIT 1;"
63  );
64 
65  $d = $this->helper->getDatabase()->fetchObject($r);
66  if (!($d instanceof stdClass)) {
67  return;
68  }
69 
70  $posting_id = (int) $d->posting_id;
71  $object_id = (int) $d->object_id;
72  $resource_owner_id = (int) $d->owner_id;
73 
74  $base_path = $this->buildBasePath();
75  $filename_pattern = '/^' . $object_id . '\_' . $posting_id . '\_(.*)/m';
76  $pattern = '/.*\/' . $object_id . '\_' . $posting_id . '\_(.*)/m';
77 
78  if (is_dir($base_path) && count(scandir($base_path)) > 2) {
79  $collection_id = $this->helper->moveFilesOfPatternToCollection(
80  $base_path,
81  $pattern,
82  $resource_owner_id,
83  ResourceCollection::NO_SPECIFIC_OWNER,
84  $this->getFileNameCallback($filename_pattern),
86  );
87 
88  $save_colletion_id = $collection_id === null ? '-' : $collection_id->serialize();
89  $this->helper->getDatabase()->update(
90  'frm_posts',
91  ['rcid' => ['text', $save_colletion_id]],
92  ['pos_pk' => ['integer', $posting_id],]
93  );
94  } else {
95  $this->helper->getDatabase()->update(
96  'frm_posts',
97  ['rcid' => ['text', '-']],
98  ['pos_pk' => ['integer', $posting_id],]
99  );
100  }
101  }
$r
+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilForumPostingFilesMigration::$helper
protected

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


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