ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilUserProfilePictureMigration.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Setup;
20 use ILIAS\Refinery;
23 use ILIAS\UI;
24 
28 class ilUserProfilePictureMigration implements Setup\Migration
29 {
30  protected \ilResourceStorageMigrationHelper $helper;
31 
32  public function getLabel(): string
33  {
34  return "Migration of Profile Pictures to the Resource Storage Service.";
35  }
36 
38  {
39  return 10000;
40  }
41 
42  public function getPreconditions(Environment $environment): array
43  {
44  return \ilResourceStorageMigrationHelper::getPreconditions();
45  }
46 
47  public function prepare(Environment $environment): void
48  {
49  $this->helper = new \ilResourceStorageMigrationHelper(
51  $environment
52  );
53  }
54 
55  public function step(Environment $environment): void
56  {
57  $r = $this->helper->getDatabase()->query(
58  "SELECT
59  usr_id
60  FROM usr_data
61  WHERE usr_data.rid IS NULL OR usr_data.rid = ''
62  LIMIT 1;"
63  );
64 
65  $d = $this->helper->getDatabase()->fetchObject($r);
66  $user_id = (int)$d->usr_id;
67 
68  $base_path = $this->buildBasePath();
69  $pattern = '/.*\/(usr|upload)\_' . $user_id . '\..*/m';
70 
71  $rid = $this->helper->moveFirstFileOfPatternToStorage(
72  $base_path,
73  $pattern,
74  $user_id
75  );
76 
77  $save_rid = $rid === null ? '-' : $rid->serialize();
78  $this->helper->getDatabase()->update(
79  'usr_data',
80  ['rid' => ['text', $save_rid]],
81  ['usr_id' => ['integer', $user_id],]
82  );
83  }
84 
85  public function getRemainingAmountOfSteps(): int
86  {
87  $r = $this->helper->getDatabase()->query(
88  "SELECT
89  count(usr_data.usr_id) AS amount
90  FROM usr_data
91  WHERE usr_data.rid IS NULL OR usr_data.rid = '';"
92  );
93  $d = $this->helper->getDatabase()->fetchObject($r);
94 
95  return (int)$d->amount;
96  }
97 
98  protected function buildBasePath(): string
99  {
100  return CLIENT_WEB_DIR . '/usr_images/';
101  }
102 }
const CLIENT_WEB_DIR
Definition: constants.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r