Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 57696a1

Browse files
author
Julien Jomier
committed
ENH: Improved migration from MIDAS2 to MIDAS3
1 parent 0236f4d commit 57696a1

File tree

3 files changed

+225
-12
lines changed

3 files changed

+225
-12
lines changed

core/controllers/components/MIDAS2MigrationComponent.php

Lines changed: 176 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
require_once BASE_PATH.'/core/models/dao/AssetstoreDao.php';
77
require_once BASE_PATH.'/core/controllers/components/UploadComponent.php';
88

9+
define("MIDAS2_RESOURCE_BITSTREAM" , 0);
10+
define("MIDAS2_RESOURCE_BUNDLE" , 1);
11+
define("MIDAS2_RESOURCE_ITEM" , 2);
12+
define("MIDAS2_RESOURCE_COLLECTION", 3);
13+
define("MIDAS2_RESOURCE_COMMUNITY" , 4);
14+
define("MIDAS2_POLICY_READ" , 0);
15+
define("MIDAS2_POLICY_WRITE" , 1);
16+
define("MIDAS2_POLICY_DELETE", 2);
17+
define("MIDAS2_POLICY_ADD" , 3);
18+
define("MIDAS2_POLICY_REMOVE", 4);
19+
920
/** Migration tool*/
1021
class MIDAS2MigrationComponent extends AppComponent
1122
{
@@ -34,7 +45,9 @@ private function _createFolderForItem($collectionId, $parentFolderid)
3445
$Folderpolicygroup = $modelLoader->loadModel("Folderpolicygroup");
3546
$Folderpolicyuser = $modelLoader->loadModel("Folderpolicyuser");
3647
$Itempolicygroup = $modelLoader->loadModel("Itempolicygroup");
37-
48+
$Itempolicyuser = $modelLoader->loadModel("Itempolicyuser");
49+
$User = $modelLoader->loadModel("User");
50+
3851
$colquery = pg_query("SELECT i.item_id,mtitle.text_value AS title,mabstract.text_value AS abstract ".
3952
"FROM item AS i ".
4053
"LEFT JOIN metadatavalue AS mtitle ON (i.item_id = mtitle.item_id AND mtitle.metadata_field_id = 64) ".
@@ -74,6 +87,33 @@ private function _createFolderForItem($collectionId, $parentFolderid)
7487
$policyValue = $policy->getPolicy();
7588
$Folderpolicyuser->createPolicy($user, $folderDao, $policyValue);
7689
}
90+
91+
// Add specific MIDAS policies for users (not dealing with groups)
92+
$policyquery = pg_query("SELECT max(action_id) AS actionid,eperson.eperson_id,eperson.email
93+
FROM resourcepolicy
94+
LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
95+
WHERE epersongroup_id IS NULL AND resource_type_id=".MIDAS2_RESOURCE_ITEM.
96+
" AND resource_id=".$item_id." GROUP BY eperson.eperson_id,email");
97+
98+
while($policyquery_array = pg_fetch_array($policyquery))
99+
{
100+
$actionid = $policyquery_array['actionid'];
101+
$email = $policyquery_array['email'];
102+
if($actionid > 1)
103+
{
104+
$policyValue = MIDAS_POLICY_ADMIN;
105+
}
106+
else if ($actionid == 1)
107+
{
108+
$policyValue = MIDAS_POLICY_WRITE;
109+
}
110+
else
111+
{
112+
$policyValue = MIDAS_POLICY_READ;
113+
}
114+
$userDao = $User->getByEmail($email);
115+
$Folderpolicyuser->createPolicy($userDao, $folderDao, $policyValue);
116+
}
77117
}
78118
catch(Zend_Exception $e)
79119
{
@@ -95,11 +135,44 @@ private function _createFolderForItem($collectionId, $parentFolderid)
95135
$itemdao->setName($filename);
96136
$Item->save($itemdao);
97137

98-
// Set the policy of the item
99-
//$this->Itempolicyuser->createPolicy($this->userSession->Dao, $item, MIDAS_POLICY_ADMIN);
100-
$anonymousGroup = $Group->load(MIDAS_GROUP_ANONYMOUS_KEY);
101-
$Itempolicygroup->createPolicy($anonymousGroup, $itemdao, MIDAS_POLICY_READ);
102-
138+
// Just check if the group anonymous can access the item
139+
$policyquery = pg_query("SELECT policy_id FROM resourcepolicy WHERE resource_type_id=".MIDAS2_RESOURCE_ITEM.
140+
" AND resource_id=".$item_id." AND epersongroup_id=0");
141+
$privacy = MIDAS_COMMUNITY_PRIVATE;
142+
if(pg_num_rows($policyquery)>0)
143+
{
144+
$anonymousGroup = $Group->load(MIDAS_GROUP_ANONYMOUS_KEY);
145+
$Itempolicygroup->createPolicy($anonymousGroup, $itemdao, MIDAS_POLICY_READ);
146+
}
147+
148+
// Add specific MIDAS policies for users
149+
$policyquery = pg_query("SELECT max(action_id) AS actionid,eperson.eperson_id,eperson.email
150+
FROM resourcepolicy
151+
LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
152+
WHERE epersongroup_id IS NULL AND resource_type_id=".MIDAS2_RESOURCE_ITEM.
153+
" AND resource_id=".$item_id." GROUP BY eperson.eperson_id,email");
154+
155+
while($policyquery_array = pg_fetch_array($policyquery))
156+
{
157+
$actionid = $policyquery_array['actionid'];
158+
$email = $policyquery_array['email'];
159+
if($actionid > 1)
160+
{
161+
$policyValue = MIDAS_POLICY_ADMIN;
162+
}
163+
else if ($actionid == 1)
164+
{
165+
$policyValue = MIDAS_POLICY_WRITE;
166+
}
167+
else
168+
{
169+
$policyValue = MIDAS_POLICY_READ;
170+
}
171+
$userDao = $User->getByEmail($email);
172+
// Set the policy of the item
173+
$Itempolicyuser->createPolicy($userDao, $itemdao, $policyValue);
174+
}
175+
103176
// Add the item to the current directory
104177
$Folder->addItem($folderDao, $itemdao);
105178

@@ -111,7 +184,7 @@ private function _createFolderForItem($collectionId, $parentFolderid)
111184

112185
// Add the metadata
113186
$MetadataModel = $modelLoader->loadModel("Metadata");
114-
// Register the common metadata (this should move to the main function
187+
// Register the common metadata (this should move to the main function)
115188
try
116189
{
117190
$MetadataModel->addMetadata(MIDAS_METADATA_GLOBAL,'contributor','author','Author of the data');
@@ -194,7 +267,8 @@ private function _createFolderForCollection($communityId, $parentFolderid)
194267
{
195268
set_time_limit(0);
196269
$modelLoader = new MIDAS_ModelLoader;
197-
$Folder = $modelLoader->loadModel("Folder");
270+
$Folder = $modelLoader->loadModel("Folder");
271+
$User = $modelLoader->loadModel("User");
198272
$Folderpolicygroup = $modelLoader->loadModel("Folderpolicygroup");
199273
$Folderpolicyuser = $modelLoader->loadModel("Folderpolicyuser");
200274

@@ -227,8 +301,35 @@ private function _createFolderForCollection($communityId, $parentFolderid)
227301
$policyValue = $policy->getPolicy();
228302
$Folderpolicyuser->createPolicy($user, $folderDao, $policyValue);
229303
}
304+
305+
// Add specific MIDAS policies for users (not dealing with groups)
306+
$policyquery = pg_query("SELECT max(action_id) AS actionid,eperson.eperson_id,eperson.email
307+
FROM resourcepolicy
308+
LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
309+
WHERE epersongroup_id IS NULL AND resource_type_id=".MIDAS2_RESOURCE_COLLECTION.
310+
" AND resource_id=".$collection_id." GROUP BY eperson.eperson_id,email");
311+
312+
while($policyquery_array = pg_fetch_array($policyquery))
313+
{
314+
$actionid = $policyquery_array['actionid'];
315+
$email = $policyquery_array['email'];
316+
if($actionid > 1)
317+
{
318+
$policyValue = MIDAS_POLICY_ADMIN;
319+
}
320+
else if ($actionid == 1)
321+
{
322+
$policyValue = MIDAS_POLICY_WRITE;
323+
}
324+
else
325+
{
326+
$policyValue = MIDAS_POLICY_READ;
327+
}
328+
$userDao = $User->getByEmail($email);
329+
$Folderpolicyuser->createPolicy($userDao, $folderDao, $policyValue);
330+
}
230331
}
231-
catch(Zend_Exception $e)
332+
catch(Zend_Exception $e)
232333
{
233334
$this->getLogger()->info($e->getMessage());
234335
//Zend_Debug::dump($e);
@@ -290,6 +391,34 @@ private function _createFolderForCommunity($communityidMIDAS2, $parentFolderid)
290391
$policyValue = $policy->getPolicy();
291392
$Folderpolicyuser->createPolicy($user, $folderDao, $policyValue);
292393
}
394+
395+
// Add specific MIDAS policies for users (not dealing with groups)
396+
$policyquery = pg_query("SELECT max(action_id) AS actionid,eperson.eperson_id,eperson.email
397+
FROM resourcepolicy
398+
LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
399+
WHERE epersongroup_id IS NULL AND resource_type_id=".MIDAS2_RESOURCE_COMMUNITY.
400+
" AND resource_id=".$community_id." GROUP BY eperson.eperson_id,email");
401+
402+
while($policyquery_array = pg_fetch_array($policyquery))
403+
{
404+
$actionid = $policyquery_array['actionid'];
405+
$email = $policyquery_array['email'];
406+
if($actionid > 1)
407+
{
408+
$policyValue = MIDAS_POLICY_ADMIN;
409+
}
410+
else if ($actionid == 1)
411+
{
412+
$policyValue = MIDAS_POLICY_WRITE;
413+
}
414+
else
415+
{
416+
$policyValue = MIDAS_POLICY_READ;
417+
}
418+
$userDao = $User->getByEmail($email);
419+
420+
$Folderpolicyuser->createPolicy($user, $folderDao, $policyValue);
421+
}
293422
}
294423
catch(Zend_Exception $e)
295424
{
@@ -343,6 +472,7 @@ function migrate($userid)
343472

344473
// STEP 1: Import the users
345474
$User = $modelLoader->loadModel("User");
475+
$Group = $modelLoader->loadModel("Group");
346476
$query = pg_query("SELECT email,password,firstname,lastname FROM eperson");
347477
while($query_array = pg_fetch_array($query))
348478
{
@@ -377,9 +507,44 @@ function migrate($userid)
377507
try
378508
{
379509
// Check the policies for the community
510+
// If anonymous can access then we set it public
511+
$policyquery = pg_query("SELECT policy_id FROM resourcepolicy WHERE resource_type_id=".MIDAS2_RESOURCE_COMMUNITY.
512+
" AND resource_id=".$community_id." AND epersongroup_id=0");
513+
$privacy = MIDAS_COMMUNITY_PRIVATE;
514+
if(pg_num_rows($policyquery)>0)
515+
{
516+
$privacy = MIDAS_COMMUNITY_PUBLIC;
517+
}
518+
$communityDao = $Community->createCommunity($name, $short_description, $privacy, NULL); // no user
519+
520+
// Add the users to the community
521+
// MIDAS2 was not using the group heavily so we ignore them. This would have to be a manual step
522+
$policyquery = pg_query("SELECT max(action_id) AS actionid,eperson.eperson_id,eperson.email
523+
FROM resourcepolicy
524+
LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
525+
WHERE epersongroup_id IS NULL AND resource_type_id=".MIDAS2_RESOURCE_COMMUNITY.
526+
" AND resource_id=".$community_id." GROUP BY eperson.eperson_id,email");
527+
528+
while($policyquery_array = pg_fetch_array($policyquery))
529+
{
530+
$actionid = $policyquery_array['actionid'];
531+
$email = $policyquery_array['email'];
532+
if($actionid > 1)
533+
{
534+
$memberGroupDao = $communityDao->getAdminGroup();
535+
}
536+
else if ($actionid == 1)
537+
{
538+
$memberGroupDao = $communityDao->getModeratorGroup();
539+
}
540+
else
541+
{
542+
$memberGroupDao = $communityDao->getMemberGroup();
543+
}
544+
$userDao = $User->getByEmail($email);
545+
$Group->addUser($memberGroupDao,$userDao);
546+
}
380547

381-
382-
$communityDao = $Community->createCommunity($name, $short_description, MIDAS_COMMUNITY_PUBLIC, NULL); // no user
383548
}
384549
catch(Zend_Exception $e)
385550
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
h2 {
2+
margin-left: 10px;
3+
}
4+
5+
form.migrateForm dl {
6+
margin-top: 25px;
7+
border: 0px;
8+
width: 800px;
9+
}
10+
11+
form.migrateForm dl dt {
12+
float: left;
13+
text-align: right;
14+
width: 200px;
15+
height: 25px;
16+
font-weight: bold;
17+
margin-top: 5px;
18+
padding-bottom: 5px;
19+
border-bottom: 1px solid #EEEEEE;
20+
}
21+
22+
form.migrateForm dl dd {
23+
float: left;
24+
width: 550px;
25+
display:inline;
26+
height: 25px;
27+
text-align: left;
28+
margin-left: 0px;
29+
margin-top: 5px;
30+
padding-left: 20px;
31+
padding-bottom: 5px;
32+
border-bottom: 1px solid #EEEEEE;
33+
}
34+
35+
#submit-label {
36+
border-bottom: 0px;
37+
}
38+
39+
#submit-element {
40+
border-bottom: 0px;
41+
}
42+
43+
.browse-button{
44+
position: relative;
45+
top: -32px;
46+
left: 630px;
47+
}

core/views/admin/migratemidas2.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.form.js');
44

55
$this->headLink()->appendStylesheet($this->coreWebroot.'/public/css/jquery/jquery.filetree.css');
6+
$this->headLink()->appendStylesheet($this->coreWebroot.'/public/css/admin/admin.migrate.css');
67
$this->headLink()->appendStylesheet($this->coreWebroot.'/public/css/assetstore/assetstore.add.css');
78
?>
89

9-
<h2>Migrating from MIDAS version 2 to MIDAS version 3</h2>
10+
<h2> Migrating from MIDAS version 2 to MIDAS version 3</h2>
1011
<?php echo $this->migrateForm; ?>
1112

1213

0 commit comments

Comments
 (0)