Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = 0;
$fileplans = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_fileplan']
]);
if (!empty($fileplans)) {
$superadmin = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => 'superadmin']);
if (empty($superadmin)) {
$firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1]);
$masterOwnerId = $firstMan[0]['id'];
} else {
$masterOwnerId = $superadmin['id'];
}
$masterFolderId = \Folder\models\FolderModel::create([
'label' => 'Reprise Plan de Classement',
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => null,
'level' => 0
]);
fillEntities($masterFolderId);
foreach ($fileplans as $fileplan) {
$positions = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_fileplan_positions'],
'where' => ['fileplan_id = ?'],
'data' => [$fileplan['fileplan_id']]
]);
if (empty($fileplan['user_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $fileplan['fileplan_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $masterFolderId,
'level' => 1
]);
fillEntities($id);
foreach ($positions as $position) {
if (empty($position['parent_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $id,
'level' => 2
]);
fillEntities($id);
runPositionsForPublic($positions, $position['position_id'], $id, 3, $masterOwnerId);
}
}
} else {
$user = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => $fileplan['user_id']]);
if (empty($user)) {
continue;
}
$id = \Folder\models\FolderModel::create([
'label' => $fileplan['fileplan_label'],
'public' => false,
'user_id' => $user['id'],
'parent_id' => null,
'level' => 0
]);
foreach ($positions as $position) {
if (empty($position['parent_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => false,
'user_id' => $user['id'],
'parent_id' => $id,
'level' => 1
]);
fillResources($id, $position['position_id']);
runPositionsForPrivate($positions, $position['position_id'], $id, 2, $user['id']);
}
}
}
++$migrated;
}
}
printf("Migration Plan de Classement (CUSTOM {$custom}) : " . $migrated . " Plan trouvé(s) et migré(s).\n");
}
function runPositionsForPublic($positions, $parentPositionId, $parentFolderId, $level, $masterOwnerId)
{
foreach ($positions as $position) {
if ($position['parent_id'] == $parentPositionId) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $parentFolderId,
'level' => $level
]);
fillEntities($id);
runPositionsForPublic($positions, $position['position_id'], $id, $level + 1, $masterOwnerId);
break;
}
}
}
function runPositionsForPrivate($positions, $parentPositionId, $parentFolderId, $level, $ownerId)
{
foreach ($positions as $position) {
if ($position['parent_id'] == $parentPositionId) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => false,
'user_id' => $ownerId,
'parent_id' => $parentFolderId,
'level' => $level
]);
fillResources($id, $position['position_id']);
runPositionsForPrivate($positions, $position['position_id'], $id, $level + 1, $ownerId);
break;
}
}
}
function fillEntities($folderId)
{
\Folder\models\EntityFolderModel::create([
'folder_id' => $folderId,
'entity_id' => null,
'edition' => true,
'keyword' => 'ALL_ENTITIES'
]);
}
function fillResources($folderId, $positionId)
{
$resources = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_res_fileplan_positions'],
'where' => ['position_id = ?', 'coll_id = ?'],
'data' => [$positionId, 'letterbox_coll']
]);
foreach ($resources as $resource) {
\Folder\models\ResourceFolderModel::create([
'folder_id' => $folderId,
'res_id' => $resource['res_id']
]);
}
}