mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
More fixes for fresh_install. Don't create initial Groups in SQL
migrations, instead create them after DB is initialized
This commit is contained in:
@@ -1491,11 +1491,21 @@ public class Group extends DSpaceObject
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
public static void initDefaultGroupNames(Context context) throws SQLException, AuthorizeException {
|
||||
Group anonymousGroup = Group.find(context, 0);
|
||||
// Check for Anonymous group. If not found, create it
|
||||
Group anonymousGroup = Group.find(context, ANONYMOUS_ID);
|
||||
if(anonymousGroup==null)
|
||||
{
|
||||
anonymousGroup = Group.create(context);
|
||||
}
|
||||
anonymousGroup.setName("Anonymous");
|
||||
anonymousGroup.update();
|
||||
|
||||
Group adminGroup = Group.find(context, 1);
|
||||
// Check for Administrator group. If not found, create it
|
||||
Group adminGroup = Group.find(context, ADMIN_ID);
|
||||
if(adminGroup==null)
|
||||
{
|
||||
adminGroup = Group.create(context);
|
||||
}
|
||||
adminGroup.setName("Administrator");
|
||||
adminGroup.update();
|
||||
}
|
||||
|
@@ -25,24 +25,24 @@ import org.slf4j.LoggerFactory;
|
||||
* any Database migration occurs.
|
||||
* <P>
|
||||
* The reason this runs BEFORE a migration is to ensure that any new
|
||||
* metadata fields are FIRST added to our registries, so that the
|
||||
* metadata fields are FIRST added to our registries, so that the
|
||||
* migrations can make use of those new metadata fields, etc.
|
||||
* <P>
|
||||
* However, there is one exception. If this is a "fresh install" of DSpace,
|
||||
* However, there is one exception. If this is a "fresh install" of DSpace,
|
||||
* we'll need to wait until the necessary database tables are created. In
|
||||
* that scenario we will load registries AFTER the initial migration.
|
||||
*
|
||||
*
|
||||
* @author Tim Donohue
|
||||
*/
|
||||
public class DatabaseRegistryUpdater implements FlywayCallback
|
||||
{
|
||||
/** logging category */
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseRegistryUpdater.class);
|
||||
|
||||
|
||||
// Whether or not this is a fresh install of DSpace
|
||||
// This determines whether to update registries PRE or POST migration
|
||||
private boolean freshInstall = false;
|
||||
|
||||
|
||||
/**
|
||||
* Method to actually update our registries from latest configs
|
||||
*/
|
||||
@@ -53,11 +53,11 @@ public class DatabaseRegistryUpdater implements FlywayCallback
|
||||
{
|
||||
context = new Context();
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
|
||||
String base = ConfigurationManager.getProperty("dspace.dir")
|
||||
+ File.separator + "config" + File.separator
|
||||
+ "registries" + File.separator;
|
||||
|
||||
|
||||
// Load updates to Bitstream format registry (if any)
|
||||
log.info("Updating Bitstream Format Registry based on " + base + "bitstream-formats.xml");
|
||||
RegistryLoader.loadBitstreamFormats(context, base + "bitstream-formats.xml");
|
||||
@@ -96,91 +96,87 @@ public class DatabaseRegistryUpdater implements FlywayCallback
|
||||
context.abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void afterClean(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterEachMigrate(Connection connection, MigrationInfo info)
|
||||
{
|
||||
// If this is a fresh install, we must update registries AFTER the
|
||||
// initial migration runs (since the registry tables won't exist until
|
||||
// the initial migration are performed)
|
||||
if(freshInstall)
|
||||
{
|
||||
// As soon as the MetadataSchemaRegistry table exists, we can update the registries
|
||||
if(DatabaseUtils.tableExists(connection, "MetadataSchemaRegistry"))
|
||||
{
|
||||
updateRegistries();
|
||||
freshInstall = false;
|
||||
}
|
||||
}
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInfo(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInit(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterMigrate(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
// If this is a fresh install, we must update registries AFTER the
|
||||
// initial migrations (since the registry tables won't exist until the
|
||||
// initial migrations are performed)
|
||||
if(freshInstall)
|
||||
{
|
||||
updateRegistries();
|
||||
freshInstall = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterRepair(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterValidate(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeClean(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeEachMigrate(Connection connection, MigrationInfo info)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeInfo(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeInit(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeMigrate(Connection connection)
|
||||
{
|
||||
// Check if our MetadataSchemaRegistry table exists yet.
|
||||
// If it does NOT, then this is a fresh install & we'll need to
|
||||
// updateRegistries() AFTER migration
|
||||
// Check if our MetadataSchemaRegistry table exists yet.
|
||||
// If it does NOT, then this is a fresh install & we'll need to
|
||||
// updateRegistries() AFTER migration
|
||||
if(DatabaseUtils.tableExists(connection, "MetadataSchemaRegistry"))
|
||||
{
|
||||
// Ensure registries are updated BEFORE a database migration (upgrade)
|
||||
@@ -195,17 +191,16 @@ public class DatabaseRegistryUpdater implements FlywayCallback
|
||||
freshInstall = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeRepair(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeValidate(Connection connection)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,7 +16,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
|
||||
CREATE SEQUENCE fileextension_seq;
|
||||
CREATE SEQUENCE bitstream_seq;
|
||||
CREATE SEQUENCE eperson_seq;
|
||||
CREATE SEQUENCE epersongroup_seq START WITH 2; -- we reserve 0 and 1
|
||||
-- start group sequence at 0, since Anonymous group = 0
|
||||
CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
|
||||
CREATE SEQUENCE item_seq;
|
||||
CREATE SEQUENCE bundle_seq;
|
||||
CREATE SEQUENCE item2bundle_seq;
|
||||
@@ -551,12 +552,3 @@ SELECT Communities2Item.community_id, ItemsByDateAccessioned.*
|
||||
FROM ItemsByDateAccessioned, Communities2Item
|
||||
WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id
|
||||
;
|
||||
|
||||
|
||||
-------------------------------------------------------
|
||||
-- Create 'special' groups, for anonymous access
|
||||
-- and administrators
|
||||
-------------------------------------------------------
|
||||
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
|
||||
INSERT INTO epersongroup VALUES(0, 'Anonymous');
|
||||
INSERT INTO epersongroup VALUES(1, 'Administrator');
|
||||
|
@@ -16,8 +16,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
|
||||
CREATE SEQUENCE fileextension_seq;
|
||||
CREATE SEQUENCE bitstream_seq;
|
||||
CREATE SEQUENCE eperson_seq;
|
||||
CREATE SEQUENCE epersongroup_seq START WITH 2;
|
||||
-- we reserve 0 and 1
|
||||
-- start group sequence at 0, since Anonymous group = 0
|
||||
CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
|
||||
CREATE SEQUENCE item_seq;
|
||||
CREATE SEQUENCE bundle_seq;
|
||||
CREATE SEQUENCE item2bundle_seq;
|
||||
@@ -546,12 +546,3 @@ SELECT Communities2Item.community_id, ItemsByDateAccessioned.*
|
||||
FROM ItemsByDateAccessioned, Communities2Item
|
||||
WHERE ItemsByDateAccessioned.item_id = Communities2Item.item_id
|
||||
;
|
||||
|
||||
|
||||
-------------------------------------------------------
|
||||
-- Create 'special' groups, for anonymous access
|
||||
-- and administrators
|
||||
-------------------------------------------------------
|
||||
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
|
||||
INSERT INTO epersongroup VALUES(0, 'Anonymous');
|
||||
INSERT INTO epersongroup VALUES(1, 'Administrator');
|
||||
|
@@ -54,7 +54,8 @@ CREATE SEQUENCE bitstreamformatregistry_seq;
|
||||
CREATE SEQUENCE fileextension_seq;
|
||||
CREATE SEQUENCE bitstream_seq;
|
||||
CREATE SEQUENCE eperson_seq;
|
||||
CREATE SEQUENCE epersongroup_seq;
|
||||
-- start group sequence at 0, since Anonymous group = 0
|
||||
CREATE SEQUENCE epersongroup_seq MINVALUE 0 START WITH 0;
|
||||
CREATE SEQUENCE item_seq;
|
||||
CREATE SEQUENCE bundle_seq;
|
||||
CREATE SEQUENCE item2bundle_seq;
|
||||
@@ -563,12 +564,3 @@ SELECT Community2Item.community_id, ItemsByDateAccessioned.*
|
||||
FROM ItemsByDateAccessioned, Community2Item
|
||||
WHERE ItemsByDateAccessioned.item_id = Community2Item.item_id
|
||||
;
|
||||
|
||||
|
||||
-------------------------------------------------------
|
||||
-- Create 'special' groups, for anonymous access
|
||||
-- and administrators
|
||||
-------------------------------------------------------
|
||||
-- We don't use getnextid() for 'anonymous' since the sequences start at '1'
|
||||
INSERT INTO epersongroup VALUES(0, 'Anonymous');
|
||||
INSERT INTO epersongroup VALUES(getnextid('epersongroup'), 'Administrator');
|
||||
|
Reference in New Issue
Block a user