Thanks to Per’s packager (which will be integrated in v4) creating packages for umbraco is a very simple thing. The only part that can get a little tricky is if you need to update the database, or one of the config files.
The way to do this is to create a custom usercontrol, and this usercontrol gets fired at the last step of the package installation (you need to set this up in the package.xml file). I’ve created several packages so I thought I would just show the way I did these things.
Executing a SQL statement ( to create new tables )
StreamReader reader = new StreamReader(base.Server.MapPath(“/umbraco/plugins/nibble/demo/installer/demo.sql”));
string sqlStatement = reader.ReadToEnd();
reader.Close();
SqlHelper.ExecuteNonQuery(GlobalSettings.DbDSN, CommandType.Text, sqlStatement);
In this sample the statement is stored in a .sql file, then it is just read in and executed.
Updating xsltExtensions.config ( for xslt extensions )
XmlDocument document = new XmlDocument();
document.Load(base.Server.MapPath(“/config/xsltExtensions.config”));
XmlNode node = document.SelectSingleNode(“/XsltExtensions”);
if (node.SelectNodes(“/ext [@assembly = ‘/bin/Jesper.GoogleMaps’]”).Count == 0)
{
XmlNode newChild = document.CreateElement(“ext”);
XmlAttribute attribute = document.CreateAttribute(“assembly”);
attribute.Value = “/bin/Jesper.GoogleMaps”;
newChild.Attributes.Append(attribute);
XmlAttribute attribute2 = document.CreateAttribute(“type”);
attribute2.Value = “Jesper.GoogleMaps.Library”;
newChild.Attributes.Append(attribute2);
XmlAttribute attribute3 = document.CreateAttribute(“alias”);
attribute3.Value = “GoogleMaps.Library”;
newChild.Attributes.Append(attribute3);
node.AppendChild(newChild);
document.Save(base.Server.MapPath(“/config/xsltExtensions.config”));
}
this sample will add
<ext assembly=”/bin/Jesper.GoogleMaps” type=”Jesper.GoogleMaps.Library” alias=”GoogleMaps.Library” />
to the /config/xsltExtensions.config file
Updating restExtensions.config ( for base )
XmlDocument document = new XmlDocument();
document.Load(Server.MapPath(“/config/”) + “restExtensions.config”);
XmlNode newChild = document.CreateElement(“ext”);
XmlAttribute AtAssembly = document.CreateAttribute(“assembly”);
AtAssembly.Value = “/bin/xtraUmbracoStarRating”;
newChild.Attributes.Append(AtAssembly);
XmlAttribute atType = document.CreateAttribute(“type”);
atType.Value = “xtraUmbracoStarRating.StarRating”;
newChild.Attributes.Append(atType);
XmlAttribute atAlias = document.CreateAttribute(“alias”);
atAlias.Value = “StarRating”;
newChild.Attributes.Append(atAlias);
XmlNode permissionNode = document.CreateElement(“permission”);
newChild.AppendChild(permissionNode);
XmlAttribute atMethod = document.CreateAttribute(“method”);
atMethod.Value = “update”;
permissionNode.Attributes.Append(atMethod);
XmlAttribute atAllowAll = document.CreateAttribute(“allowAll”);
atAllowAll.Value = “true”;
permissionNode.Attributes.Append(atAllowAll);
document.DocumentElement.AppendChild(newChild);
document.Save(Server.MapPath(“/config/”) + “restExtensions.config”);
this sample will add
<ext assembly=”/bin/xtraUmbracoStarRating” type=”xtraUmbracoStarRating.StarRating” alias=”StarRating”>
<permission method=”update” allowAll=”true” />
</ext>
to the /config/restExtensions.config file
Updating dashboard.config ( to add usercontrols on the dashboard )
XmlDocument document = new XmlDocument();
document.Load(base.Server.MapPath(“/config/Dashboard.config”));
XmlNode node = document.SelectSingleNode(“/dashBoard”);
XmlNode sectionChild = document.CreateElement(“section”);
XmlNode areasChild = document.CreateElement(“areas”);
XmlNode areaChild = document.CreateElement(“area”);
areaChild.InnerText = “developer”;
XmlNode tabChild = document.CreateElement(“tab”);
XmlAttribute attribute = document.CreateAttribute(“caption”);
attribute.Value = “Nibble FX”;
tabChild.Attributes.Append(attribute);
XmlNode controlChild = document.CreateElement(“control”);
controlChild.InnerText = “/usercontrols/Nibble/NibbleFX.ascx”;
tabChild.AppendChild(controlChild);
areasChild.AppendChild(areaChild);
sectionChild.AppendChild(areasChild);
sectionChild.AppendChild(tabChild);
node.AppendChild(sectionChild);
document.Save(base.Server.MapPath(“/config/Dashboard.config”));
this sample will add
<section>
<areas>
<area>developer</area>
</areas>
<tab caption=”Nibble FX”>
<control>/usercontrols/Nibble/NibbleFX.ascx</control>
</tab>
</section>
to the /config/dashboard.config file