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

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

Member Function Documentation

◆ buildBasePath()

ilForumDraftsFilesMigration::buildBasePath ( )
protected

Definition at line 114 of file class.ilForumDraftsFilesMigration.php.

References CLIENT_DATA_DIR.

Referenced by step().

114  : string
115  {
116  return CLIENT_DATA_DIR . '/forum/drafts/';
117  }
const CLIENT_DATA_DIR
Definition: constants.php:46
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

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

34  : int
35  {
36  return 10000;
37  }

◆ getFileNameCallback()

ilForumDraftsFilesMigration::getFileNameCallback ( string  $pattern)

Definition at line 119 of file class.ilForumDraftsFilesMigration.php.

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

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

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

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

◆ getPreconditions()

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

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilForumDraftsFilesMigration::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 100 of file class.ilForumDraftsFilesMigration.php.

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

100  : int
101  {
102  $r = $this->helper->getDatabase()->query(
103  "SELECT
104  count(frm_posts_drafts.draft_id) AS amount
105 FROM frm_posts_drafts
106 JOIN frm_data ON frm_posts_drafts.forum_id = frm_data.top_pk
107 WHERE frm_posts_drafts.rcid IS NULL OR frm_posts_drafts.rcid = '';"
108  );
109  $d = $this->helper->getDatabase()->fetchObject($r);
110 
111  return (int) $d->amount;
112  }
$r

◆ getRevisionNameCallback()

ilForumDraftsFilesMigration::getRevisionNameCallback ( )

Definition at line 129 of file class.ilForumDraftsFilesMigration.php.

Referenced by step().

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

◆ prepare()

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

◆ step()

ilForumDraftsFilesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

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

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

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

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilForumDraftsFilesMigration::$helper
protected

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


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