Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eran Meir 401 posts 543 karma points
    Feb 27, 2011 @ 13:29
    Eran Meir
    0

    No Document exists with Version '00000000-0000-0000-0000-000000000000' with umb 4.7 beta

    when i try at first creating a node i get the following error

    No Document exists with Version '00000000-0000-0000-0000-000000000000'
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.ArgumentException: No Document exists with Version '00000000-0000-0000-0000-000000000000'
    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:
    [ArgumentException: No Document exists with Version '00000000-0000-0000-0000-000000000000']
       umbraco.cms.businesslogic.web.Document.setupNode() +736
       umbraco.cms.businesslogic.web.Document..ctor(Int32 id) +19
       InfoCaster.Umbraco.DateFolders.DateFolders.Document_AfterSave(Document doc, SaveEventArgs e) +264
       umbraco.cms.businesslogic.web.SaveEventHandler.Invoke(Document sender, SaveEventArgs e) +0
       umbraco.cms.businesslogic.web.Document.Save() +336
       umbraco.cms.presentation.editContent.Save(Object sender, EventArgs e) +1596
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       umbraco.controls.ContentControl.saveClick(Object Sender, ImageClickEventArgs e) +348
       umbraco.controls.ContentControl.savePublish(Object Sender, ImageClickEventArgs e) +24
       System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +134
       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +165
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
    after i try creating the node again it appears to work, any suggestions?

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Feb 28, 2011 @ 10:17
    Stefan Kip
    0

    Could you try and debug this yourself by using the DataFolders sourcecode instead of the binary?
    Maybe you could tell me what line is causing the error?

  • Eran Meir 401 posts 543 karma points
    Feb 28, 2011 @ 13:14
    Eran Meir
    0

    i tryed working with the source code, it worked fine, got back to the binary, working great.

    wierd. :s

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Apr 19, 2011 @ 11:20
    Matt Brailsford
    0

    Did anybody find a fix for this? I'm getting the same problem, but i'm using Umb4.5.2 and it happens every time I create / save & publish a document.

    Matt

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Apr 20, 2011 @ 12:33
    Stefan Kip
    0

    Just did a test on a clean install and I do not get this error with umbraco 4.7 and DateFolders version 1.2...

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Apr 20, 2011 @ 12:36
    Matt Brailsford
    0

    Sorry, forgot to reply yesterday. My issue was that I hadn't created my Date Folder doc type yet, and hadn't setup the relations between them so I was getting that error. May be worth doing some checks and disaplying a more frienldy error?

    Cheers

    Matt

    PS I noticed a couple of other things which I've modified. 1) I prefer the month folders to be "03" rather than "3". I just updated the .ToString() calls to .ToString("00") 2) When you do the sortting of date folders you call Save() rather than SaveAndPublish() so in the backend it just creates a new version of the date folders rather than publishing them.

     

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Apr 20, 2011 @ 12:39
    Stefan Kip
    0

    I will take a look for some better error handling.

    Also I will implement your modifications :-) Thank you Matt!

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Apr 20, 2011 @ 15:12
    Stefan Kip
    2

    Just uploaded DateFolders version 1.3, see the changelog for changes :-) (hint; everything Matt noticed above + error handling)

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Apr 20, 2011 @ 15:13
    Matt Brailsford
    0

    =) Nice work!

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Apr 25, 2011 @ 16:55
    Tim
    0

    @Matt, what did you do to get it to work? I'm having the same error in 4.7. I have the following site structure:

    Home
    -- Blog
    ---- Posts

    I have a blogPost docType that's configured as the doc type to folder, dateFolder is my docType to create the date folder with, and postDate is my column to sort on. All docTypes are set up to allow the right docTypes (although that shouldn't matter as the Date Folders are added programatically, so allowed types doesn't get checked). Any ideas?

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Apr 25, 2011 @ 19:44
    Matt Brailsford
    0

    Hey Tim,

    For me it was just a case of missing Doc Type, but then I was using 4.5.2 aswell so doesn't sound like that's going to solve the problem for you. That said, you can easily delete the dll, and drop the .cs file in the App_Code folder and it works, so should be easy enough to debug.

    Cheers

    Matt

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Apr 26, 2011 @ 09:36
    Tim
    0

    Figured it out, it happens if you try and publish a page that was there before you set up the DateFolders DLL. I've posted a separate bug about it :P

  • Daniel.S 50 posts 135 karma points
    May 18, 2011 @ 15:34
    Daniel.S
    0

    I had this same issue on a 4.0.2 install that I'm in the process of upgrading to 4.7 and moving to the new schema. I installed the datefolders extension as the list of news articles was getting a bit unruly. I would then get the error "No document exists with version 000 etc" when trying to save existing content to trigger a move into the datefolder structure.

    I ended up uninstalling the extension and using the source in the app_code folder for troubleshooting. Turns out that DateFolders at v1.3 doesn't like existing content, and was walking further up the tree when looking for the month and year folders.

    I've tweaked the code to solve this, and also removed a bunch of the nested if sections and return early to clean up the code a bit. I've tested it with existing nodes, nodes that aren't in folders affected by DateFolders, but I haven't tested it in scenarios where the folder would be deleted.

    -Update: see my post below for the code.

  • Daniel.S 50 posts 135 karma points
    May 19, 2011 @ 06:10
    Daniel.S
    0

    Made a few more tweaks to this to solve the issue if content editors right-click on an existing datefolder to create new content. The modified version now doesn't care if the editor creates the new item at the parent level, or one of the {year} or {month} folders. There are still some bugs with the sorting, depending on where choose to create your new content item.

    /*
    DateFolders v1.3.1 for umbraco 4.5+
    Created by Stefan Kip (kipusoep), InfoCaster
    
    MIT license
    
    Copyright (c) 2010 Stefan Kip, InfoCaster
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    */
    
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Threading;
    using System.Web;
    using umbraco.BasePages;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.NodeFactory;
    
    namespace InfoCaster.Umbraco.DateFolders
    {
        public class DateFolders : ApplicationBase
        {
            readonly string[] _itemDocType;
            readonly string _itemDateProperty;
            readonly string _dateFolderDocType;
    
            static readonly object _syncer = new object();
    
            /* Configuration properties:
             * 
             * itemDocType
             * itemDateProperty
             * dateFolderDocType
             */
    
            public DateFolders()
            {
                _itemDocType = ConfigurationManager.AppSettings["itemDocType"].Split(',');
                _itemDateProperty = ConfigurationManager.AppSettings["itemDateProperty"];
                _dateFolderDocType = ConfigurationManager.AppSettings["dateFolderDocType"];
    
                if (_itemDocType.Length > 0 && !string.IsNullOrEmpty(_dateFolderDocType))
                {
                    Document.New += new Document.NewEventHandler(Document_New);
                    Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
                    Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
                    Document.AfterMoveToTrash += new Document.MoveToTrashEventHandler(Document_AfterMoveToTrash);
                }
            }
    
            void Document_BeforeMoveToTrash(Document doc, MoveToTrashEventArgs e)
            {
                if (_itemDocType.Contains(doc.ContentType.Alias))
                {
                    try
                    {
                        HttpContext.Current.Items.Add("monthId", doc.ParentId);
                        HttpContext.Current.Items.Add("yearId", doc.Parent.ParentId);
                    }
                    catch (Exception ex)
                    {
                        if (BasePage.Current != null)
                            BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "DateFolders Document_BeforeMoveToTrash exception", ex.Message);
                        umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1, string.Format("DateFolders Document_BeforeMoveToTrash exception: {0}", ex.Message));
    
    #if DEBUG
                        System.Diagnostics.Trace.TraceInformation(string.Format("DateFolders Document_BeforeMoveToTrash exception: {0}", ex.Message));
    #endif
                    }
                }
            }
    
            void Document_AfterMoveToTrash(Document doc, MoveToTrashEventArgs e)
            {
                if (_itemDocType.Contains(doc.ContentType.Alias))
                {
                    // Date item deleted
                    try
                    {
                        int monthId, yearId;
    
                        monthId = int.Parse(HttpContext.Current.Items["monthId"].ToString());
                        yearId = int.Parse(HttpContext.Current.Items["yearId"].ToString());
    
                        HttpContext.Current.Items.Remove("monthId");
                        HttpContext.Current.Items.Remove("yearId");
    
                        Node month = new Node(monthId);
                        if (month.Children.Count < 1)
                        {
                            new Document(monthId).DeleteCompletely();
    
                            Node year = new Node(yearId);
                            if (year.Children.Count < 1)
                                new Document(yearId).DeleteCompletely();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (BasePage.Current != null)
                            BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "DateFolders Document_AfterMoveToTrash exception", ex.Message);
                        umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1, string.Format("DateFolders Document_AfterMoveToTrash exception: {0}", ex.Message));
    #if DEBUG
                        System.Diagnostics.Trace.TraceInformation(string.Format("DateFolders Document_AfterMoveToTrash exception: {0}", ex.Message));
    #endif
                    }
                }
            }
    
            void Document_AfterSave(Document doc, SaveEventArgs e)
            {
                // Check if datefolder applies to the current document's doctype
                if (!_itemDocType.Contains(doc.ContentType.Alias))
                {
                    return;
                }
    
                // Check if the folder doctype is defined
                DocumentType folderDocType = DocumentType.GetByAlias(_dateFolderDocType);
                if (folderDocType == null)
                {
                    // Date folder doctype is null
                    if (BasePage.Current != null)
                        BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Configuration error", string.Format("The date folder doctype ('{0}') does not exist", _dateFolderDocType));
                    return;
                }
    
                // Check if the item has been created directly under the 'Content' root
                if (doc.ParentId < 0)
                {
                    // Item is created under 'Content' root, which is unsupported
                    if (BasePage.Current != null)
                        BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Unsupported", "Creating a datefolders item under 'Content' root is unsupported");
                    return;
                }
    
                // Date item saved
                DateTime date = default(DateTime);
                if (!string.IsNullOrEmpty(_itemDateProperty))
                {
                    string dateValue = doc.GetDatePropertyValue(_itemDateProperty);
                    if (!string.IsNullOrEmpty(dateValue))
                        DateTime.TryParse(dateValue, out date);
                }
                if (date == default(DateTime))
                    date = doc.CreateDateTime;
    
                Document parent = null, monthFolder = null, yearFolder = null, monthDoc = null, yearDoc = null;
    
                // Initialise these as true. If the parent folder isn't a datefolder, go on and create the datefolders
                bool yearChanged = true, monthChanged = true;
    
                switch (CheckFolderType(doc.Parent))
                {
                    case DateFolderType.NotDateFolder:
                        // current node isn't in a datefolder
                        parent = new Document(doc.ParentId);
                        break;
    
                    case DateFolderType.MonthFolder:
                        // current node is already contained within a datefolder
                        monthFolder = new Document(doc.ParentId);
                        yearFolder = new Document(monthFolder.ParentId);
                        parent = new Document(yearFolder.ParentId);
    
                        yearChanged = date.Year.ToString() != yearFolder.Text;
                        monthChanged = date.Month.ToString("00") != monthFolder.Text;
                        break;
    
                    case DateFolderType.YearFolder:
                        parent = new Document(doc.Parent.ParentId);
                        break;
                }
    
                if (!(yearChanged | monthChanged))
                {
                    // year and month haven't changed, do nothing
                    return;
                }
    
                if (parent == null) return;
    
                // Date changed
                Document newYearFolder = null, newMonthFolder = null;
                if (yearChanged)
                {
                    // Year changed
                    newYearFolder = parent.Children.FirstOrDefault(x => x.ContentType.Alias == _dateFolderDocType && x.Text == date.Year.ToString());
                    if (newYearFolder == null)
                    {
                        // Create year folder
                        newYearFolder = Document.MakeNew(date.Year.ToString(), DocumentType.GetByAlias(_dateFolderDocType), doc.User, parent.Id);
                    }
                }
                else
                    newYearFolder = yearFolder;
    
                // Month
                newMonthFolder = newYearFolder.Children.FirstOrDefault(x => x.ContentType.Alias == _dateFolderDocType && x.Text == date.Month.ToString("00"));
                if (newMonthFolder == null)
                {
                    // Create month folder
                    newMonthFolder = Document.MakeNew(date.Month.ToString("00"), DocumentType.GetByAlias(_dateFolderDocType), doc.User, newYearFolder.Id);
                }
    
                // Move
                doc.Move(newMonthFolder.Id);
                if (doc.Published)
                    doc.SaveAndPublish();
    
                //OrderChildrenByDateProperty(new Document(newMonthFolder.Id), "startDate");
                OrderChildrenByDateProperty(new Document(newMonthFolder.Id));
    
                if (newYearFolder != null)
                    newYearFolder.SaveAndPublish();
                if (newMonthFolder != null)
                    newMonthFolder.SaveAndPublish();
    
                // Delete if empty
                if (monthFolder != null)
                {
                    monthDoc = new Document(monthFolder.Id);
                    if (monthDoc.ChildCount < 1)
                    {
                        monthDoc.DeleteCompletely();
    
                        yearDoc = new Document(yearFolder.Id);
                        if (yearDoc.ChildCount < 1)
                            yearDoc.DeleteCompletely();
                    }
                }
    
                // Order
                ThreadPool.QueueUserWorkItem(delegate { OrderChildrenByName(new Document(parent.Id)); });
                ThreadPool.QueueUserWorkItem(delegate { OrderChildrenByName(new Document(newYearFolder.Id)); });
    
                doc = new Document(doc.Id);
    
                BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("editContent.aspx?id=", doc.Id));
            }
    
            void Document_New(Document doc, NewEventArgs e)
            {
                try
                {
                    DocumentType folderDocType = DocumentType.GetByAlias(_dateFolderDocType);
                    if (folderDocType == null)
                    {
                        // Date folder doctype is null
                        if (BasePage.Current != null)
                            BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Date folder property", string.Format("The date folder doctype does not exist ({0})", _dateFolderDocType));
                    }
    
                    Document parent = new Document(doc.ParentId);
    
                    if (!_itemDocType.Contains(doc.ContentType.Alias))
                    {
                        return; // node isn't one that is affected by the DateFolders settings
                    }
    
                    if (CheckFolderType(parent) == DateFolderType.MonthFolder || CheckFolderType(parent) == DateFolderType.YearFolder) return; // content is already in a date folder
    
                    // Date item created
                    DateTime now = DateTime.Now;
    
                    Document yearFolder = parent.Children.FirstOrDefault(x => x.ContentType.Alias == _dateFolderDocType && x.Text == now.Year.ToString());
                    if (yearFolder == null)
                    {
                        // Create year folder
                        yearFolder = Document.MakeNew(now.Year.ToString(), DocumentType.GetByAlias(_dateFolderDocType), doc.User, parent.Id);
                    }
    
                    Document monthFolder = yearFolder.Children.FirstOrDefault(x => x.ContentType.Alias == _dateFolderDocType && x.Text == now.Month.ToString("00"));
                    if (monthFolder == null)
                    {
                        // Create month folder
                        monthFolder = Document.MakeNew(now.Month.ToString("00"), DocumentType.GetByAlias(_dateFolderDocType), doc.User, yearFolder.Id);
                    }
    
                    doc.Move(monthFolder.Id);
                    doc.Save();
    
                    if (yearFolder != null)
                        yearFolder.SaveAndPublish();
                    if (monthFolder != null)
                        monthFolder.SaveAndPublish();
    
                    // Order
                    ThreadPool.QueueUserWorkItem(delegate { OrderChildrenByName(new Document(parent.Id)); });
                    ThreadPool.QueueUserWorkItem(delegate { OrderChildrenByName(new Document(yearFolder.Id)); });
    
    
                }
                catch { }
            }
    
            //static void OrderChildrenByDateProperty(Document parent, string propertyAlias)
            void OrderChildrenByDateProperty(Document parent)
            {
                lock (_syncer)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(_itemDateProperty))
                        {
                            DoOrder(parent.Children.OrderBy(x => x.CreateDateTime));
                        } else
                        {
                            DoOrder(parent.Children.OrderBy(x => DateTime.Parse(x.GetPropertyValueAsString(_itemDateProperty))));
                        }                  
                    }
                    catch (Exception ex)
                    {
                        if (BasePage.Current != null)
                            BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "DateFolders SortChildrenByDateProperty exception", ex.Message);
                        umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1, string.Format("DateFolders SortChildrenByDateProperty exception: {0}", ex.Message));
    #if DEBUG
                        System.Diagnostics.Trace.TraceInformation(string.Format("DateFolders SortChildrenByDateProperty exception: {0}", ex.Message));
    #endif
                    }
                }
            }
    
            void OrderChildrenByName(Document parent)
            {
                lock (_syncer)
                {
                    try
                    {
                        DoOrder(parent.Children.OrderBy(x => int.Parse(x.Text)));
                    }
                    catch (Exception ex)
                    {
                        umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1, string.Format("DateFolders SortChildrenByName exception: {0}", ex.Message));
    #if DEBUG
                        System.Diagnostics.Trace.TraceInformation(string.Format("DateFolders SortChildrenByName exception: {0}", ex.Message));
    #endif
                    }
                }
            }
    
            static void DoOrder(IEnumerable<Document> documents)
            {
                int iSortOrder = 0;
                foreach (Document objChild in documents)
                {
                    bool isAlreadyPublished = objChild.Published;
    
                    objChild.sortOrder = iSortOrder;
    
                    if (isAlreadyPublished)
                    {
                        objChild.SaveAndPublish();
                    }
                    else
                    {
                        objChild.Save();
                    }
    
                    iSortOrder++;
                }
            }
    
            /// <summary>
            /// Match a passed-in CMSNode's Text attribute to
            /// determine if it's a month or a year
            /// </summary>
            /// <param name="doc">Umbraco CMSNode object</param>
            /// <returns>True/False depending on whether the node is a DateFolder</returns>
            static DateFolderType CheckFolderType(CMSNode doc)
            {
                // Match month folders
                if (System.Text.RegularExpressions.Regex.IsMatch(doc.Text, @"^((0[1-9])|(1[0-2]))$"))
                {
                    return DateFolderType.MonthFolder;
                }
    
                // Match year folders
                if (System.Text.RegularExpressions.Regex.IsMatch(doc.Text, @"^((\d{4}))$"))
                {
                    return DateFolderType.YearFolder;
                }
    
                // Document name didn't match a possible DateFolder name
                return DateFolderType.NotDateFolder;
            }
        }
    
        enum DateFolderType
        {
            NotDateFolder,
            MonthFolder,
            YearFolder
        }
    
        static class UmbracoExtensions
        {
            /// <summary>
            /// Deletes a document completely
            /// </summary>
            /// <param name="document">The document to delete completely</param>
            public static void DeleteCompletely(this Document document)
            {
                if (document != null)
                {
                    if (document.Published)
                    {
                        document.UnPublish();
                        umbraco.library.UnPublishSingleNode(document.Id);
                    }
                    document.delete(true);
                }
            }
    
            /// <summary>
            /// Returns the value as string of the property with the given alias
            /// </summary>
            /// <param name="node">The document</param>
            /// <param name="propertyAlias">The alias of the property</param>
            /// <returns>The property's value</returns>
            public static string GetPropertyValueAsString(this Document document, string propertyAlias)
            {
                if (document.getProperty(propertyAlias) != null && document.getProperty(propertyAlias).Value != null)
                    return document.getProperty(propertyAlias).Value.ToString();
    
                return string.Empty;
            }
    
            /// <summary>
            /// Saves and publishes a document
            /// </summary>
            /// <param name="document">The document to save and publish</param>
            public static void SaveAndPublish(this Document document)
            {
                if (document != null)
                {
                    document.Save();
                    document.Publish(document.User);
                    umbraco.library.UpdateDocumentCache(document.Id);
                }
            }
    
            /// <summary>
            /// Gets the date property
            /// </summary>
            /// <param name="doc"></param>
            /// <returns></returns>
            public static string GetDatePropertyValue(this Document doc, string itemDateProperty)
            {
                if (string.IsNullOrEmpty(itemDateProperty))
                    return doc.CreateDateTime.ToString();
                return doc.GetPropertyValueAsString(itemDateProperty);
            }
        }
    }
Please Sign in or register to post replies

Write your reply to:

Draft