it seems that I can not set default value for RegistrationSettingsPartRecord table

Topics: Core, General
Jun 13, 2012 at 11:53 PM
this time I go to Orchard.users to change the value, but 
Users can create new accounts on the site 
and 
Display a link to enable users to reset their password
still be unchecked under user setting.

pls  notice that :
.Column<bool>("UsersCanRegister", c => c.WithDefault(true))
and
.Column<bool>("EnableLostPassword", c => c.WithDefault(true))

in the following code:
===============================

using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;
using Orchard.Core.Contents.Extensions;
 
namespace Orchard.Users {
    public class UsersDataMigration : DataMigrationImpl {
 
        public int Create() {
            SchemaBuilder.CreateTable("UserPartRecord", 
                table => table
                    .ContentPartRecord()
                    .Column<string>("UserName")
                    .Column<string>("Email")
                    .Column<string>("NormalizedUserName")
                    .Column<string>("Password")
                    .Column<string>("PasswordFormat")
                    .Column<string>("HashAlgorithm")
                    .Column<string>("PasswordSalt")
                    .Column<string>("RegistrationStatus", c => c.WithDefault("Approved"))
                    .Column<string>("EmailStatus", c => c.WithDefault("Approved"))
                    .Column<string>("EmailChallengeToken")
                );
 
            SchemaBuilder.CreateTable("RegistrationSettingsPartRecord", 
                table => table
                    .ContentPartRecord()
                    .Column<bool>("UsersCanRegister", c => c.WithDefault(true))
                    .Column<bool>("UsersMustValidateEmail", c => c.WithDefault(false))
                    .Column<string>("ValidateEmailRegisteredWebsite", c => c.WithLength(255))
                    .Column<string>("ValidateEmailContactEMail", c => c.WithLength(255))
                    .Column<bool>("UsersAreModerated", c => c.WithDefault(false))
                    .Column<bool>("NotifyModeration", c => c.WithDefault(false))
                    .Column<string>("NotificationsRecipients", c => c.Unlimited())
                    .Column<bool>("EnableLostPassword", c => c.WithDefault(true))
                );
 
            return 1;
        }
 
        public int UpdateFrom1() {
            ContentDefinitionManager.AlterTypeDefinition("User", cfg => cfg.Creatable(false));
 
            return 2;
        }
    }
}
Coordinator
Jun 14, 2012 at 5:59 AM

I don't see a question in here. What do you mean?

Jun 14, 2012 at 6:30 AM

because .Column<bool>("UsersCanRegister", c => c.WithDefault(true))----it is  " true"

Users can create new accounts on the site should be "tick", but it is not.
Coordinator
Jun 14, 2012 at 7:03 AM

So what's your question?

Jun 14, 2012 at 4:32 PM
Edited Jun 14, 2012 at 4:34 PM

I think he means that while the 'default' for the database column 'UsersCanRegister' is true, the option seems to be disabled by default.

I just checked my own orchard setup, and while I never unchecked the option before (afaik) the checkbox is not checked as you would expect based on the 'WithDefault(true)'

edit: that being said, in my code (1.4.2) the default is set to false not true.

infofromca, did you 'just' modify this value to 'true' after you 'installed' orchard or before? Or was that option on true on older Orchard versions?

Jun 14, 2012 at 4:47 PM
AimOrchard wrote:

I think he means that while the 'default' for the database column 'UsersCanRegister' is true, the option seems to be disabled by default.

I just checked my own orchard setup, and while I never unchecked the option before (afaik) the checkbox is not checked as you would expect based on the 'WithDefault(true)'

edit: that being said, in my code (1.4.2) the default is set to false not true.

infofromca, did you 'just' modify this value to 'true' after you 'installed' orchard or before? Or was that option on true on older Orchard versions?

thanks , that is what i mean.

did you 'just' modify this value to 'true' after you 'installed' orchard or before?-----YES, I MODIFIED IT BEFORE  'installed' orchard 

Or was that option on true on older Orchard versions?------NO

Oct 29, 2012 at 6:31 AM

orchard 1.6

on migration.cs, i set :

 SchemaBuilder.CreateTable("FormHiddenPartRecord", table => table.ContentPartVersionRecord() .Column<string>("ContentType", c => c.WithDefault("Page")  )

but i got 'part.ContentType' threw an exception of type 'System.NullReferenceException'

this time , i make sure the problem is  .WithDefault() 

 

Coordinator
Oct 29, 2012 at 6:44 AM

WithDefault is applied if the column is null. With a boolean it's never the case. You need a bool? in this case. But as you can't change it you need to register on OnInitialized in a handler.

Oct 29, 2012 at 6:51 AM

i saw this  .Column<bool>("UseCustomPattern", c=> c.WithDefault(false)) does not use bool?

using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Orchard.Autoroute {
    public class Migrations : DataMigrationImpl {
        public int Create() {
            SchemaBuilder.CreateTable("AutoroutePartRecord",
                table => table
                    .ContentPartVersionRecord()
                            .Column<string>("CustomPattern", c => c.WithLength(2048))
                            .Column<bool>("UseCustomPattern", c=> c.WithDefault(false))
                            .Column<string>("DisplayAlias", c => c.WithLength(2048)));

            ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part.Attachable());

            return 1;
        }
    }
}
Oct 29, 2012 at 7:04 AM

that is ok for OnInitialized by  part.Record.ContentType = "Page";

but it is called many time and influence performance.

---------------------------------------------------------------------------------------------------------

but i still can not set ContentType  to be "Page"   by       migration "ContentType", c => c.WithDefault("Page")

Coordinator
Oct 29, 2012 at 6:36 PM

Do you have evidence for the performance claim?

I don't understand what you are trying to do with a default on content type.