Duarte Nobrega
 

Birthday webpart "datenoyear" issues

29

Jan

We built a Birthday webpart that returns the first x birthdays starting today.

The Birthday profile field, is type "datenoyear". What I noticed is that this field includes the year that you fill in the birthday date. For instance for "18 January" it will fill in 1/18/2009.

The problems lays on birthdays that the users inserted back in 2007 & 2008. Their birthdays are queried according to the query below:

            query.Append(birthdayField);
            query.Append("\" >= GETGMTDATE() ) ");
            query.Append("ORDER BY \"");
            query.Append(birthdayField);
            query.Append( "\"</QueryText>" );

Because some functions like MONTH() or DAY(), do not work in MOSS FullTextSqlQuery, one of the ways to get around this was creating a scheduled task that updates birthdays every week, before a full indexing crawll happens.

This script was developed by a colleague at TamTam (Peter Geritsen), I added code, to update to the following year birthdays previously to the current day, so that in the last months of a year shows birthdays of the following year.

CODE (posible to download, see BrithdayReset_SourceCode.zip file in this post):

..

UserProfileManager profileManager = new UserProfileManager(context);
                    IEnumerator profileEnumerator = profileManager.GetEnumerator();
                    int countUpdated = 0;
                    while (profileEnumerator.MoveNext())
                    {
                        UserProfile profile = profileEnumerator.Current as UserProfile;

                        if (profile[birthdayFieldName].Count != 0)
                        {
                            DateTime birthday = (DateTime)profile[birthdayFieldName].Value;

                            //if (birthday <= DateTime.Now.AddDays(-1))
                            int yearDiff = DateTime.Now.Year - birthday.Year;
                            if (yearDiff != 0)
                            {
                                // set year to this year
                                birthday = birthday.AddYears(yearDiff);
                                profile[birthdayFieldName].Value = birthday;
                                Console.WriteLine("Birthday of {0} changed to: {1}", profile["PreferredName"].Value, birthday.ToShortDateString() + " : " + birthday.ToString());
                                countUpdated++;
                            }

                            //if the birthday has already been, must update it to the following year.
                            //This prevents from birthdays of the following next year by the last weeks of the year not showing.
                            if(DateTime.Compare(birthday, DateTime.Now)<0)
                            {
                                birthday = birthday.AddYears(1);
                                profile[birthdayFieldName].Value = birthday;
                                Console.WriteLine("Birthday of {0} changed to: {1}", profile["PreferredName"].Value, birthday.ToShortDateString() + " : " + birthday.ToString());
                                countUpdated++;
                            }

                            profile.Commit();   
                        }
                    }

...

 

Run the script:

BirthdayReset fieldName PortalURL

You can make it a scheduled task in Control Panel to happen periodically

NOTE:

Architecturaly it is more "elegant" to create a TimerJob that will run this code periodically.

Download Source Code:

BirthdayReset_SourceCode.zip (1.3 MB)

Duarte Nobrega schreef

Comments (0)

Duarte Nobrega

Search DB is too large after Reset all crawled content

16

Jan

Sometimes the Indexing generates an unsual big size mdf file for the search database. If you have disk space shortage this article might help you.

Once you reset the all cralled content in the Shared Services > Search Settings, if the Search DB is too large and you have disk space issue sin your DB server you must do the following:

1. Go to Shared Services > Search

2. Go to Content Sources and crawll schedules.

3. Stop all search crawls.

   Note: Stopping the search crawlls usually generates big LOG files that can clog your DB server if it is already struggling with lack of space.

4. Reset all crawlled content (Shared Services > Search Settings)

3. Go to the DB server and open SQL 2005.

4. Now the search DB must be shrunk:

5. Right click the search DB go to All Tasks > Shrink > Database, follow the image below (you must check "reorganize files..."):

 

6. Right click the search DB go to All Tasks > Shrink > Files, with default settings:

 

7. This should be enough to release space from your DB server. Good luck! :)

Share:

Duarte Nobrega schreef

Comments (1)

Duarte Nobrega

Zoeken

Categorie

Archief


Sign In