ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFileObjectToStorageMigrationHelper.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  protected string $base_path = '/var/iliasdata/ilias/default/ilFile';
22  public const MIGRATED = ".migrated";
24 
25 
26  public function __construct(ilResourceStorageMigrationHelper $irss_helper)
27  {
28  $this->base_path = $irss_helper->getClientDataDir() . '/ilFile';
29  $this->database = $irss_helper->getDatabase();
30  }
31 
33  {
34  do {
35  $next_id = $this->getNextFileId();
36  $path = $this->createPathFromId($next_id);
37  $path_found = file_exists($path);
38  if (!$path_found) {
39  $this->database->update(
40  'file_data',
41  ['rid' => ['text', 'unknown']],
42  ['file_id' => ['integer', $next_id]]
43  );
44  } else {
45  return new ilFileObjectToStorageDirectory($next_id, $path);
46  }
47  } while (!$path_found);
48  }
49 
50  private function getNextFileId(): int
51  {
52  $query = "SELECT file_id
53  FROM file_data
54  WHERE
55  (rid IS NULL OR rid = '')
56  AND (file_id != '' AND file_id IS NOT NULL)
57  LIMIT 1;";
58  $r = $this->database->query($query);
59  $d = $this->database->fetchObject($r);
60  if (!isset($d->file_id) || null === $d->file_id || '' === $d->file_id) {
61  throw new LogicException("error fetching file_id");
62  }
63 
64  return (int) $d->file_id;
65  }
66 
67 
68  private function createPathFromId(int $file_id): string
69  {
70  $path = [];
71  $found = false;
72  $num = $file_id;
73  $path_string = '';
74  for ($i = 3; $i > 0; $i--) {
75  $factor = pow(100, $i);
76  if (($tmp = (int) ($num / $factor)) or $found) {
77  $path[] = $tmp;
78  $num = $num % $factor;
79  $found = true;
80  }
81  }
82 
83  if (count($path)) {
84  $path_string = (implode('/', $path) . '/');
85  }
86 
87  return $this->base_path . '/' . $path_string . 'file_' . $file_id;
88  }
89 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
Class ilResourceStorageMigrationHelper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
__construct(ilResourceStorageMigrationHelper $irss_helper)
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$i
Definition: metadata.php:41