예제 #1
0
        public override void delete()
        {
            // don't allow template deletion if it has child templates
            if (this.HasChildren)
            {
                Log.Add(LogTypes.Error, this.Id, "Can't delete a master template. Remove any bindings from child templates first.");
                throw new InvalidOperationException("Can't delete a master template. Remove any bindings from child templates first.");
            }

            // NH: Changed this; if you delete a template we'll remove all references instead of
            // throwing an exception
            if (DocumentType.GetAllAsList().Where(x => x.allowedTemplates.Select(t => t.Id).Contains(this.Id)).Count() > 0)
            {
                // the uncommented code below have been refactored into removeAllReferences method that clears template
                // from documenttypes, subtemplates and documents.
                RemoveAllReferences();

                /*
                 *
                 * // Added to remove template doctype relationship
                 * SqlHelper.ExecuteNonQuery("delete from cmsDocumentType where templateNodeId =" + this.Id);
                 *
                 * // Need to update any other template that references this one as it's master to NULL
                 * SqlHelper.ExecuteNonQuery("update cmsTemplate set [master] = NULL where [master] = " + this.Id);
                 */

                // don't allow template deletion if it is in use
                // (get all doc types and filter based on any that have the template id of this one)

                /*
                 * Log.Add(LogTypes.Error, this.Id, "Can't delete a template that is assigned to existing content");
                 * throw new InvalidOperationException("Can't delete a template that is assigned to existing content");
                 */
            }

            DeleteEventArgs e = new DeleteEventArgs();

            FireBeforeDelete(e);

            if (!e.Cancel)
            {
                //re-set the template aliases
                _templateAliasesInitialized = false;
                initTemplateAliases();

                //delete the template
                SqlHelper.ExecuteNonQuery("delete from cmsTemplate where NodeId =" + this.Id);

                base.delete();

                // remove masterpages
                if (System.IO.File.Exists(MasterPageFile))
                {
                    System.IO.File.Delete(MasterPageFile);
                }

                if (System.IO.File.Exists(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this.Alias))))
                {
                    System.IO.File.Delete(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this.Alias)));
                }

                FireAfterDelete(e);
            }
        }
예제 #2
0
        protected override void setupNode()
        {
            base.setupNode();

            IRecordsReader dr      = SqlHelper.ExecuteReader("Select alias,design,master from cmsTemplate where nodeId = " + this.Id);
            bool           hasRows = dr.Read();

            if (hasRows)
            {
                _alias  = dr.GetString("alias");
                _design = dr.GetString("design");
                //set the master template to zero if it's null
                _mastertemplate = dr.IsNull("master") ? 0 : dr.GetInt("master");
            }
            dr.Close();

            if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc && ViewHelper.ViewExists(this))
            {
                _design = ViewHelper.GetFileContents(this);
            }
            else
            {
                _design = MasterPageHelper.GetFileContents(this);
            }
        }