ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDBUpdate5069.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
12 public function fix19795()
13 {
14 global $ilDB;
15
16 //query only the feedback with uploaded files.
17 $result = $ilDB->query(
18 "SELECT exc_assignment.exc_id, exc_assignment.peer_crit_cat, exc_assignment.id, exc_assignment_peer.giver_id, exc_assignment_peer.peer_id" .
19 " FROM exc_assignment_peer, exc_assignment" .
20 " WHERE exc_assignment.id = exc_assignment_peer.ass_id" .
21 " AND (exc_assignment.peer_file = 1 OR exc_assignment.peer_crit_cat > 0)" .
22 " AND exc_assignment_peer.tstamp IS NOT null"
23 );
24
25 while ($row = $ilDB->fetchAssoc($result)) {
26 include_once("./Services/Migration/DBUpdate_5069/classes/class.ilFSStorageExercise5069.php");
27 $storage = new ilFSStorageExercise5069($row['exc_id'], $row['id']);
28 //echo "0 -".$row['peer_crit_cat']."<br>";
29 //if the assignment has criteria category
30 if ($row['peer_crit_cat']) {
31 //get criteria id which is uploader
32 // *** string -> text
33 $res_crit = $ilDB->query(
34 $q = "SELECT id FROM exc_crit " .
35 " WHERE parent = " . $ilDB->quote($row['peer_crit_cat'], "integer") .
36 " AND type = " . $ilDB->quote('file', 'text')
37 );
38 //echo "#".$q."#<br>";
39 while ($row_crit = $ilDB->fetchAssoc($res_crit)) {
40 $original_path = $storage->getPeerReviewUploadPath($row['peer_id'], $row['giver_id'], $row_crit['id']);
41 //echo "a-$original_path-<br>";
42 $path_peaces = explode('/', rtrim($original_path, '/'));
43 array_pop($path_peaces);
44 $previous_dir_path = "";
45 foreach ($path_peaces as $piece) {
46 $previous_dir_path .= $piece . "/";
47 }
48 $dir_content = array_diff(scandir($previous_dir_path), array('.', '..'));
49 //echo $previous_dir_path."<br>";
50 //loop the directory content
51 foreach ($dir_content as $content) {
52 if (is_dir($previous_dir_path . $content)) {
53 //if the directory name is wrong(giver_id+criteria_id)
54 if ($content == $row['giver_id'] . $row_crit['id']) {
55 if (!is_dir($previous_dir_path . $row['giver_id'])) {
56 mkdir($previous_dir_path . $row['giver_id']);
57 //echo "1 make dir ".$previous_dir_path.$row['giver_id']."<br>";
58 }
59
60 if (!is_dir($previous_dir_path . $row['giver_id'] . "/" . $row_crit['id'])) {
61 mkdir($previous_dir_path . $row['giver_id'] . "/" . $row_crit['id']);
62 //echo "2 make dir ".$previous_dir_path.$row['giver_id']."/".$row_crit['id']."<br>";
63 }
64
65
66 $old = substr($original_path, 0, strlen($original_path) - 1);
67 $new = $previous_dir_path . $row['giver_id'] . "/" . $row_crit['id'];
68 if (is_dir($old)) {
69 rename($old, $new);
70 }
71 //echo "rename ".$old." to ".$new."<br>";
72 }
73 }
74 }
75 }
76 }
77 //assignment without criteria (just rename the file and move it to the proper directory)
78 else {
79 $original_path = $storage->getPeerReviewUploadPath($row['peer_id'], $row['giver_id'], $row['peer_crit_cat']);
80
81 $path_peaces = explode('/', rtrim($original_path, '/'));
82 array_pop($path_peaces);
83 $previous_dir_path = "";
84 foreach ($path_peaces as $piece) {
85 $previous_dir_path .= $piece . "/";
86 }
87
88 $dir_content = array_diff(scandir($previous_dir_path), array('.', '..'));
89
90 foreach ($dir_content as $content) {
91 if (!is_dir($previous_dir_path . $content)) {
92 if (substr($content, 0, strlen($row['giver_id'])) === $row['giver_id']) {
93 $new_filename = substr($content, strlen($row['giver_id']));
94 copy($previous_dir_path . $content, $original_path . "/" . $new_filename);
95 //echo "5 copy ".$previous_dir_path.$content." to ".$original_path."/".$new_filename."<br>";
96 }
97 }
98 }
99 }
100 }
101
102 // die("ende");
103 }
104}
$result
An exception for terminatinating execution or to throw for unit testing.
fix19795()
Migration for bug fix 19795.
$old
global $ilDB