Create Sitecore Database User

Published by on
Tags:

This script creates a SQL Server database user for the Sitecore 6.2 databases manually. You will need to find and replace %username% and %password% with your values.

CREATE LOGIN %username% WITH PASSWORD = '%password%'

USE Sitecore_Master
GO

CREATE USER %username% FOR LOGIN %username%
GO

GRANT EXECUTE TO %username%
GO

sp_addrolemember 'db_datareader', '%username%'
GO

sp_addrolemember 'db_datawriter', '%username%'
GO

USE Sitecore_Web
GO

CREATE USER %username% FOR LOGIN %username%
GO

GRANT EXECUTE TO %username%
GO

sp_addrolemember 'db_datareader', '%username%'
GO

sp_addrolemember 'db_datawriter', '%username%'
GO

USE Sitecore_Master
GO

CREATE USER %username% FOR LOGIN %username%
GO

GRANT EXECUTE TO %username%
GO

sp_addrolemember 'db_datareader', '%username%'
GO

sp_addrolemember 'db_datawriter', '%username%'
GO

Get all XML attributes using XSLT

Published by on
Tags:

If you want to be able to get all the attributes on an XML element including their names you can use the following XSTL:


	 - 
	

Sitecore 6 XHTML Validation and the Embed HTML Element

Published by on
Tags:

The embed HTML element is not a valid XHTML element, this creates a problem when you want to insert objects into your Rich Text fields such as You Tube videos. To validate XHTML sitecore uses the file /sitecore/shell/schemas/sitecore xhtml.xsd. By editing this file we can allow usage of the embed element.

Beneath the /xs:schema node add a definition for the embed element:

 <xs:element name="embed">
    <xs:complexType mixed="true">
      <!-- from http://www.htmlref.com/Reference/AppA/tag_embed.htm -->
      <xs:attribute name="align" type="xs:string" />
      <xs:attribute name="alt" type="xs:string" />
      <xs:attribute name="class" type="xs:string" />
      <xs:attribute name="code" type="xs:string" />
      <xs:attribute name="codebase" type="xs:string" />
      <xs:attribute name="height" type="xs:string" />
      <xs:attribute name="hspace" type="xs:string" />
      <xs:attribute name="id" type="xs:string" />
      <xs:attribute name="language" type="xs:string" />
      <xs:attribute name="name" type="xs:string" />
      <xs:attribute name="src" type="xs:string" />
      <xs:attribute name="style" type="xs:string" />
      <xs:attribute name="title" type="xs:string" />
      <xs:attribute name="unselectable" type="xs:string" />
      <xs:attribute name="vspace" type="xs:string" />
      <xs:attribute name="width" type="xs:string" /
      <!-- used by you tube -->
      <xs:attribute name="type" type="xs:string" />
      <xs:attribute name="allowscriptaccess" type="xs:string" />
      <xs:attribute name="allowfullscreen" type="xs:string" />
    </xs:complexType>
  </xs:element>

This definition was created based on the attributes list at http://www.htmlref.com/Reference/AppA/tag_embed.htm and some attributes used by You Tube. You may need to define additional attributes as needed.

Next we need to add a reference to the new embed definition in the object definition. Find the definition and replace the first part with the following which has the embed reference:

  <xs:element name="object">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="embed" />
        <xs:element ref="param" />
        <xs:group ref="block" />
        <xs:element ref="form" />
        <xs:group ref="inline" />
        <xs:group ref="misc" />
      </xs:choice>
   ...

Save the file and your embed element problems should disappear. Remember however that doing this will mean that your site is no longer XHTML strict.

Sitecore 6 Cache Clearing and Links

Published by on
Tags:

After editing content and publishing it the HTML cache is cleared so that the changes can be seen. The clearing of the cache is performed by the HtmlCacheClearer class that is configured as a handler on the publish end event:

      
        
          
            website
          
        
      

So what does this mean? Well in Sitecore 6 the links to items are managed differently; in early versions if you added a link in the Rich Text editor it would enter the URL to the item. This mean if you later moved an item in the content tree any links to it would break. However in Sitecore 6 it inserts a specially formatted link that contains the Guid of the item you want to link to, then when the item is rendered the special link is replaced with the actual link to the item.

To speed up the replacing of the special link with the actual item URL Sitecore creates a cache of the item Guid's and URL;s called the PathCache. However when you publish this cache is not cleared, this means that if you move any items in the content tree and then publish any links to that item will break because the page will render the cached paths and not the new paths. This will happen until the application pool is restarted.

The solution is to create our own cache clearing method that clears both the path and html caches:

    public class CacheClearer : Sitecore.Publishing.HtmlCacheClearer
    {
        new public void ClearCache(object sender, EventArgs args)
        {

            Sites.Cast().ToList().ForEach(x =>
            {
                Sitecore.Sites.SiteContext site = Sitecore.Configuration.Factory.GetSite(x);
                if (site != null)
                {
                    Sitecore.Caching.PathCache cache = Sitecore.Caching.CacheManager.GetPathCache(site.Database);
                    if(cache != null)
                        cache.Clear();

                }
            });

            base.ClearCache(sender, args);
        }

    }

Then alter the web.config to use our new class instead of Sitecore's:

      
        
          
            website
          
        
      

I hope this helps someone because this seems to be an oversight on Sitecore's part.

Sitecore Get List of Referrers

Published by on
Tags:

Sitecore now has a very nice method for getting a list of items that refer to an item, i.e. items that have been selected in multi-lists, as a link or lookup.

Once you have a list of items that link to an item you can see if the link comes from a particular field using the SourceFieldId property of the ItemLink class.

You can find more information on Neil P's blog.

 

Projects

Have you read?

Sitecore Sheer XAML Applications - Part 1



Blogs by date