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

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

Protected Member Functions

 buildAbsolutPath (int $test_id, int $active_id, int $question_id, string $filename)
 

Private Attributes

ilResourceStorageMigrationHelper $helper = null
 

Additional Inherited Members

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

Detailed Description

Member Function Documentation

◆ buildAbsolutPath()

ilTestQuestionPoolFileUploadQuestionMigration::buildAbsolutPath ( int  $test_id,
int  $active_id,
int  $question_id,
string  $filename 
)
protected

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

References $filename, and CLIENT_WEB_DIR.

Referenced by step().

134  : string {
135  return CLIENT_WEB_DIR
136  . '/assessment'
137  . '/tst_' . $test_id
138  . '/' . $active_id
139  . '/' . $question_id
140  . '/files/'
141  . $filename;
142  }
const CLIENT_WEB_DIR
Definition: constants.php:47
$filename
Definition: buildRTE.php:78
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilTestQuestionPoolFileUploadQuestionMigration::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 31 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

31  : int
32  {
33  return 1000;
34  }

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

Definition at line 26 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

26  : string
27  {
28  return 'File Upload Question Migration';
29  }

◆ getPreconditions()

ilTestQuestionPoolFileUploadQuestionMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 36 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilTestQuestionPoolFileUploadQuestionMigration::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 115 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

References $res.

115  : int
116  {
117  $database = $this->helper->getDatabase();
118  $res = $database->query(
119  "SELECT COUNT(*) as count
120  FROM tst_solutions
121  INNER JOIN qpl_qst_fileupload ON qpl_qst_fileupload.question_fi = tst_solutions.question_fi
122  INNER JOIN tst_active ON tst_active.active_id = tst_solutions.active_fi
123  WHERE tst_solutions.value2 != 'rid';"
124  );
125 
126  return (int) $database->fetchAssoc($res)['count'];
127  }
$res
Definition: ltiservices.php:66

◆ prepare()

ilTestQuestionPoolFileUploadQuestionMigration::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 41 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

41  : void
42  {
43  $this->helper = new \ilResourceStorageMigrationHelper(
45  $environment
46  );
47  }

◆ step()

ilTestQuestionPoolFileUploadQuestionMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 49 of file class.ilTestQuestionPoolFileUploadQuestionMigration.php.

References $filename, $path, $res, $user_id, buildAbsolutPath(), ILIAS\Repository\int(), and null.

49  : void
50  {
51  $db = $this->helper->getDatabase();
52  $res = $db->query(
53  'SELECT
54  tst_solutions.solution_id AS solution_id,
55  tst_active.user_fi AS user_id,
56  tst_solutions.question_fi AS question_id,
57  tst_solutions.active_fi AS active_id,
58  tst_active.test_fi AS test_id,
59  tst_solutions.value1 AS filename,
60  tst_solutions.value2 AS revision_name
61  FROM tst_solutions
62  INNER JOIN qpl_qst_fileupload ON qpl_qst_fileupload.question_fi = tst_solutions.question_fi
63  INNER JOIN tst_active ON tst_active.active_id = tst_solutions.active_fi
64  WHERE tst_solutions.value2 != "rid";'
65  );
66 
67  $res = $db->fetchAssoc($res);
68 
69  // read common data for all files of this question id
70  $user_id = (int) $res['user_id'];
71  $active_id = (int) $res['active_id'];
72  $test_id = (int) $res['test_id'];
73  $question_id = (int) $res['question_id'];
74  $filename = $res['filename'];
75  $revision_name = $res['revision_name'];
76  $solution_id = (int) $res['solution_id'];
77 
78  // build path to file
79  $path = $this->buildAbsolutPath(
80  $test_id,
81  $active_id,
82  $question_id,
83  $filename
84  );
85 
86  $rid = null;
87 
88  if (file_exists($path)) {
89  $rid = $this->helper->movePathToStorage(
90  $path,
91  $user_id,
92  null,
93  static function () use ($revision_name): string {
94  return $revision_name;
95  }
96  );
97  }
98  if ($rid !== null) {
99  $rid = $rid->serialize(); // no files found
100  }
101 
102  // store the rid in as value1 and 'rid' as value2
103  $db->update(
104  'tst_solutions',
105  [
106  'value1' => ['string', $rid],
107  'value2' => ['string', 'rid']
108  ],
109  [
110  'solution_id' => ['integer', $solution_id]
111  ]
112  );
113  }
$res
Definition: ltiservices.php:66
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
buildAbsolutPath(int $test_id, int $active_id, int $question_id, string $filename)
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilTestQuestionPoolFileUploadQuestionMigration::$helper = null
private

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