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

Commit 6c2b5fd

Browse files
author
Charles Marion
committed
ENH: added uuid in tables
1 parent 95c0da5 commit 6c2b5fd

21 files changed

+196
-287
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/** UuidComponent componenet */
3+
class UuidComponent extends AppComponent
4+
{
5+
6+
/** Get using id*/
7+
public function getByUid($uuid)
8+
{
9+
$loader = new MIDAS_ModelLoader();
10+
$model = $loader->loadModel('Community');
11+
$dao = $model->getByUuid($uuid);
12+
if($dao != false)
13+
{
14+
$dao->resourceType = MIDAS_RESOURCE_COMMUNITY;
15+
return $dao;
16+
}
17+
18+
$model = $loader->loadModel('Folder');
19+
$dao = $model->getByUuid($uuid);
20+
if($dao != false)
21+
{
22+
$dao->resourceType = MIDAS_RESOURCE_FOLDER;
23+
return $dao;
24+
}
25+
26+
$model = $loader->loadModel('Item');
27+
$dao = $model->getByUuid($uuid);
28+
if($dao != false)
29+
{
30+
$dao->resourceType = MIDAS_RESOURCE_ITEM;
31+
return $dao;
32+
}
33+
34+
$model = $loader->loadModel('ItemRevision');
35+
$dao = $model->getByUuid($uuid);
36+
if($dao != false)
37+
{
38+
$dao->resourceType = MIDAS_RESOURCE_REVISION;
39+
return $dao;
40+
}
41+
42+
$model = $loader->loadModel('User');
43+
$dao = $model->getByUuid($uuid);
44+
if($dao != false)
45+
{
46+
$dao->resourceType = MIDAS_RESOURCE_USER;
47+
return $dao;
48+
}
49+
return false;
50+
}
51+
} // end class

core/database/upgrade/3.0.12.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
class Upgrade_3_0_12 extends MIDASUpgrade
4+
{
5+
public function preUpgrade()
6+
{
7+
8+
}
9+
10+
public function mysql()
11+
{
12+
$sql = "DROP TABLE uniqueidentifier ; ";
13+
$this->db->query($sql);
14+
}
15+
16+
17+
public function pgsql()
18+
{
19+
$sql = "DROP TABLE uniqueidentifier; ";
20+
$this->db->query($sql);
21+
}
22+
23+
public function postUpgrade()
24+
{
25+
$this->AddTableField('community', 'uuid', 'varchar(255)', ' character varying(512)', null);
26+
$this->AddTableField('user', 'uuid', 'varchar(255)', ' character varying(512)', null);
27+
$this->AddTableField('item', 'uuid', 'varchar(255)', ' character varying(512)', null);
28+
$this->AddTableField('folder', 'uuid', 'varchar(255)', ' character varying(512)', null);
29+
$this->AddTableField('itemrevision', 'uuid', 'varchar(255)', ' character varying(512)', null);
30+
31+
}
32+
}
33+
?>
34+
35+

core/models/base/AssetstoreModelBase.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ abstract function getAll();
2727
public function save($dao)
2828
{
2929
parent::save($dao);
30-
$modelLoad = new MIDAS_ModelLoader();
31-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
32-
$uuModel->newUUID($dao);
3330
}
3431

3532
/** delete an assetstore (and all the items in it)*/
@@ -64,13 +61,6 @@ public function delete($dao)
6461
{
6562
$item_model->delete($item);
6663
}
67-
$modelLoad = new MIDAS_ModelLoader();
68-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
69-
$uudao = $uuModel->getIndentifier($dao);
70-
if($uudao)
71-
{
72-
$uuModel->delete($uudao);
73-
}
7464
parent::delete($dao);
7565
}// delete
7666

core/models/base/BitstreamModelBase.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ abstract function getByChecksum($checksum);
3333
public function save($dao)
3434
{
3535
parent::save($dao);
36-
$modelLoad = new MIDAS_ModelLoader();
37-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
38-
$uuModel->newUUID($dao);
3936
}
4037

4138
/** delete a Bitstream*/
@@ -48,13 +45,6 @@ function delete($bitstream)
4845
$checksum = $bitstream->getChecksum();
4946
$path = $bitstream->getFullPath();
5047
$assetstore = $bitstream->getAssetstore();
51-
$modelLoad = new MIDAS_ModelLoader();
52-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
53-
$uudao = $uuModel->getIndentifier($bitstream);
54-
if($uudao)
55-
{
56-
$uuModel->delete($uudao);
57-
}
5848
parent::delete($bitstream);
5949
if($assetstore->getType() != MIDAS_ASSETSTORE_REMOTE && $this->getByChecksum($checksum) == false)
6050
{

core/models/base/CommunityModelBase.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct()
2222
'membergroup_id' => array('type' => MIDAS_DATA),
2323
'can_join' => array('type' => MIDAS_DATA),
2424
'view' => array('type' => MIDAS_DATA),
25+
'uuid' => array('type' => MIDAS_DATA),
2526
'folder' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Folder', 'parent_column' => 'folder_id', 'child_column' => 'folder_id'),
2627
'public_folder' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Folder', 'parent_column' => 'publicfolder_id', 'child_column' => 'folder_id'),
2728
'private_folder' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Folder', 'parent_column' => 'privatefolder_id', 'child_column' => 'folder_id'),
@@ -40,19 +41,21 @@ abstract function getPublicCommunities($limit = 20);
4041
abstract function getByName($name);
4142
/** get All*/
4243
abstract function getAll();
44+
abstract function getByUuid($uuid);
4345

4446
/** save */
4547
public function save($dao)
4648
{
49+
if(!isset($dao->uuid) || empty($dao->uuid))
50+
{
51+
$dao->setUuid(uniqid() . md5(mt_rand()));
52+
}
4753
$name = $dao->getName();
4854
if(empty($name))
4955
{
5056
throw new Zend_Exception("Please set a name.");
5157
}
5258
parent::save($dao);
53-
$modelLoad = new MIDAS_ModelLoader();
54-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
55-
$uuModel->newUUID($dao);
5659
}
5760

5861
/** plus one view*/
@@ -192,12 +195,6 @@ function delete($communityDao)
192195
$feed_model->delete($feed);
193196
}
194197
$modelLoad = new MIDAS_ModelLoader();
195-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
196-
$uudao = $uuModel->getIndentifier($communityDao);
197-
if($uudao)
198-
{
199-
$uuModel->delete($uudao);
200-
}
201198

202199
$ciModel = $modelLoad->loadModel('CommunityInvitation');
203200
$invitations = $communityDao->getInvitations();

core/models/base/FolderModelBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct()
2222
'view' => array('type' => MIDAS_DATA),
2323
'teaser' => array('type' => MIDAS_DATA),
2424
'privacy_status' => array('type' => MIDAS_DATA),
25+
'uuid' => array('type' => MIDAS_DATA),
2526
'items' => array('type' => MIDAS_MANY_TO_MANY, 'model' => 'Item', 'table' => 'item2folder', 'parent_column' => 'folder_id', 'child_column' => 'item_id'),
2627
'folderpolicygroup' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Folderpolicygroup', 'parent_column' => 'folder_id', 'child_column' => 'folder_id'),
2728
'folderpolicyuser' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Folderpolicyuser', 'parent_column' => 'folder_id', 'child_column' => 'folder_id'),
@@ -42,6 +43,7 @@ abstract function move($folder, $parent);
4243
abstract function removeItem($folder, $item);
4344
abstract function policyCheck($folderDao, $userDao = null, $policy = 0);
4445
abstract function getFolderExists($name, $description);
46+
abstract function getByUuid($uuid);
4547

4648
/** Increment the view count */
4749
function incrementViewCount($folder)

core/models/base/ItemModelBase.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct()
2020
'view' => array('type' => MIDAS_DATA),
2121
'download' => array('type' => MIDAS_DATA),
2222
'privacy_status' => array('type' => MIDAS_DATA),
23+
'uuid' => array('type' => MIDAS_DATA),
2324
'folders' => array('type' => MIDAS_MANY_TO_MANY, 'model' => 'Folder', 'table' => 'item2folder', 'parent_column' => 'item_id', 'child_column' => 'folder_id'),
2425
'revisions' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'ItemRevision', 'parent_column' => 'item_id', 'child_column' => 'item_id'),
2526
'keywords' => array('type' => MIDAS_MANY_TO_MANY, 'model' => 'ItemKeyword', 'table' => 'item2keyword', 'parent_column' => 'item_id', 'child_column' => 'keyword_id'),
@@ -38,10 +39,11 @@ abstract function getLastRevision($itemdao);
3839
/** save */
3940
public function save($dao)
4041
{
42+
if(!isset($dao->uuid) || empty($dao->uuid))
43+
{
44+
$dao->setUuid(uniqid() . md5(mt_rand()));
45+
}
4146
parent::save($dao);
42-
$modelLoad = new MIDAS_ModelLoader();
43-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
44-
$uuModel->newUUID($dao);
4547
}
4648

4749
/** copy parent folder policies*/

core/models/base/ItemRevisionModelBase.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/** ItemRevisionModelBase*/
3-
class ItemRevisionModelBase extends AppModel
3+
abstract class ItemRevisionModelBase extends AppModel
44
{
55
/** Constructor */
66
public function __construct()
@@ -20,21 +20,24 @@ public function __construct()
2020
'changes' => array('type' => MIDAS_DATA),
2121
'user_id' => array('type' => MIDAS_DATA),
2222
'license' => array('type' => MIDAS_DATA),
23+
'uuid' => array('type' => MIDAS_DATA),
2324
'bitstreams' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Bitstream', 'parent_column' => 'itemrevision_id', 'child_column' => 'itemrevision_id'),
2425
'item' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Item', 'parent_column' => 'item_id', 'child_column' => 'item_id'),
2526
'user' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'User', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
2627
);
2728
$this->initialize(); // required
2829
} // end __construct()
2930

31+
abstract function getByUuid($uuid);
3032

3133
/** save */
3234
public function save($dao)
3335
{
36+
if(!isset($dao->uuid) || empty($dao->uuid))
37+
{
38+
$dao->setUuid(uniqid() . md5(mt_rand()));
39+
}
3440
parent::save($dao);
35-
$modelLoad = new MIDAS_ModelLoader();
36-
$uuModel = $modelLoad->loadModel('Uniqueidentifier');
37-
$uuModel->newUUID($dao);
3841
}
3942

4043

core/models/base/UniqueidentifierModelBase.php

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)