ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileObjectToStorageMigrationHelper.php
Go to the documentation of this file.
1<?php
2
4{
5 protected $base_path = '/var/iliasdata/ilias/default/ilFile';
6 public const MIGRATED = ".migrated";
10 protected $database;
11
17 {
18 $this->base_path = $base_path;
19 $this->database = $database;
20 }
21
23 {
24 $query = "SELECT file_id
25 FROM file_data
26 WHERE
27 (rid IS NULL OR rid = '')
28 AND (file_id != '' AND file_id IS NOT NULL)
29 LIMIT 1;";
30 $r = $this->database->query($query);
31 $d = $this->database->fetchObject($r);
32 if (!isset($d->file_id) || null === $d->file_id || '' === $d->file_id) {
33 throw new LogicException("error fetching file_id");
34 }
35
36 $file_id = (int) $d->file_id;
37 return new ilFileObjectToStorageDirectory($file_id, $this->createPathFromId($file_id));
38 }
39
40 private function createPathFromId(int $file_id) : string
41 {
42 $path = [];
43 $found = false;
44 $num = $file_id;
45 $path_string = '';
46 for ($i = 3; $i > 0; $i--) {
47 $factor = pow(100, $i);
48 if (($tmp = (int) ($num / $factor)) or $found) {
49 $path[] = $tmp;
50 $num = $num % $factor;
51 $found = true;
52 }
53 }
54
55 if (count($path)) {
56 $path_string = (implode('/', $path) . '/');
57 }
58
59 return $this->base_path . '/' . $path_string . 'file_' . $file_id;
60 }
61
62}
An exception for terminatinating execution or to throw for unit testing.
Class ilFileObjectToStorageDirectory.
__construct(string $base_path, ilDBInterface $database)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:24
$query