Ejemplo n.º 1
0
        /// <summary>
        /// Given the protected modifier the CMSNode.MakeNew method can only be accessed by
        /// derived classes &gt; who by definition knows of its own objectType.
        /// </summary>
        /// <param name="parentId">The newParent CMSNode id</param>
        /// <param name="objectType">The objecttype identifier</param>
        /// <param name="userId">Creator</param>
        /// <param name="level">The level in the tree hieararchy</param>
        /// <param name="text">The name of the CMSNode</param>
        /// <param name="uniqueID">The unique identifier</param>
        /// <returns></returns>
        protected static CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID)
        {
            CMSNode parent    = null;
            string  path      = "";
            int     sortOrder = 0;

            if (level > 0)
            {
                parent    = new CMSNode(parentId);
                sortOrder = GetNewDocumentSortOrder(parentId);
                path      = parent.Path;
            }
            else
            {
                path = "-1";
            }

            // Ruben 8/1/2007: I replace this with a parameterized version.
            // But does anyone know what the 'level++' is supposed to be doing there?
            // Nothing obviously, since it's a postfix.

            SqlHelper.ExecuteNonQuery("INSERT INTO umbracoNode(trashed, parentID, nodeObjectType, nodeUser, level, path, sortOrder, uniqueID, text, createDate) VALUES(@trashed, @parentID, @nodeObjectType, @nodeUser, @level, @path, @sortOrder, @uniqueID, @text, @createDate)",
                                      SqlHelper.CreateParameter("@trashed", 0),
                                      SqlHelper.CreateParameter("@parentID", parentId),
                                      SqlHelper.CreateParameter("@nodeObjectType", objectType),
                                      SqlHelper.CreateParameter("@nodeUser", userId),
                                      SqlHelper.CreateParameter("@level", level++),
                                      SqlHelper.CreateParameter("@path", path),
                                      SqlHelper.CreateParameter("@sortOrder", sortOrder),
                                      SqlHelper.CreateParameter("@uniqueID", uniqueID),
                                      SqlHelper.CreateParameter("@text", text),
                                      SqlHelper.CreateParameter("@createDate", DateTime.Now));

            CMSNode retVal = new CMSNode(uniqueID);

            retVal.Path = path + "," + retVal.Id.ToString();

            // NH 4.7.1 duplicate permissions because of refactor
            if (parent != null)
            {
                IEnumerable <Permission> permissions = Permission.GetNodePermissions(parent);
                foreach (Permission p in permissions)
                {
                    Permission.MakeNew(User.GetUser(p.UserId), retVal, p.PermissionId);
                }
            }

            //event
            NewEventArgs e = new NewEventArgs();

            retVal.FireAfterNew(e);

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Given the protected modifier the CMSNode.MakeNew method can only be accessed by
        /// derived classes &gt; who by definition knows of its own objectType.
        /// </summary>
        /// <param name="parentId">The newParent CMSNode id</param>
        /// <param name="objectType">The objecttype identifier</param>
        /// <param name="userId">Creator</param>
        /// <param name="level">The level in the tree hieararchy</param>
        /// <param name="text">The name of the CMSNode</param>
        /// <param name="uniqueID">The unique identifier</param>
        /// <returns></returns>
        protected static CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID)
        {
            CMSNode parent    = null;
            string  path      = "";
            int     sortOrder = 0;

            if (level > 0)
            {
                parent    = new CMSNode(parentId);
                sortOrder = GetNewDocumentSortOrder(parentId);
                path      = parent.Path;
            }
            else
            {
                path = "-1";
            }

            Database.Execute(
                "INSERT INTO umbracoNode(trashed, parentID, nodeObjectType, nodeUser, level, path, sortOrder, uniqueID, text, createDate) VALUES(@trashed, @parentID, @nodeObjectType, @nodeUser, @level, @path, @sortOrder, @uniqueID, @text, @createDate)",
                new
            {
                trashed        = false,
                parentID       = parentId,
                nodeObjectType = objectType,
                nodeUser       = userId,
                level,
                path,
                sortOrder,
                uniqueID,
                text,
                createDate = DateTime.Now
            });

            CMSNode retVal = new CMSNode(uniqueID);

            retVal.Path = path + "," + retVal.Id;

            // NH 4.7.1 duplicate permissions because of refactor
            if (parent != null)
            {
                IEnumerable <Permission> permissions = Permission.GetNodePermissions(parent);
                foreach (Permission p in permissions)
                {
                    Permission.MakeNew(User.GetUser(p.UserId), retVal, p.PermissionId);
                }
            }

            //event
            NewEventArgs e = new NewEventArgs();

            retVal.FireAfterNew(e);

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all descendant nodes from this node.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// This doesn't return a strongly typed IEnumerable object so that we can override in in super clases
        /// and since this class isn't a generic (thought it should be) this is not strongly typed.
        /// </remarks>
        public virtual IEnumerable GetDescendants()
        {
            var descendants = new List <CMSNode>();

            using (IRecordsReader dr = SqlHelper.ExecuteReader(string.Format(SqlDescendants, Id)))
            {
                while (dr.Read())
                {
                    var node = new CMSNode(dr.GetInt("id"), true);
                    node.PopulateCMSNodeFromReader(dr);
                    descendants.Add(node);
                }
            }
            return(descendants);
        }
        public static void MakeNew(umbraco.BusinessLogic.UserType userType, umbraco.cms.businesslogic.CMSNode Node, char PermissionKey)
        {
            IParameter[] parameters = new IParameter[] { SqlHelper.CreateParameter("@userTypeId", userType.Id),
                                                         SqlHelper.CreateParameter("@nodeId", Node.Id),
                                                         SqlHelper.CreateParameter("@permission", PermissionKey.ToString()) };

            // Method is synchronized so exists remains consistent (avoiding race condition)
            bool exists = SqlHelper.ExecuteScalar <int>("SELECT COUNT(userTypeId) FROM UserGroupPermissions_UserType2NodePermission WHERE userTypeId = @userTypeId AND nodeId = @nodeId AND permission = @permission",
                                                        parameters) > 0;

            if (!exists)
            {
                SqlHelper.ExecuteNonQuery("INSERT INTO UserGroupPermissions_UserType2NodePermission (userTypeId, nodeId, permission) VALUES (@userTypeId, @nodeId, @permission)",
                                          parameters);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Given the protected modifier the CMSNode.MakeNew method can only be accessed by
        /// derived classes &gt; who by definition knows of its own objectType.
        /// </summary>
        /// <param name="parentId">The parent CMSNode id</param>
        /// <param name="objectType">The objecttype identifier</param>
        /// <param name="userId">Creator</param>
        /// <param name="level">The level in the tree hieararchy</param>
        /// <param name="text">The name of the CMSNode</param>
        /// <param name="uniqueID">The unique identifier</param>
        /// <returns></returns>
        protected static CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID)
        {
            CMSNode parent;
            string  path      = "";
            int     sortOrder = 0;

            if (level > 0)
            {
                parent    = new CMSNode(parentId);
                sortOrder = parent.ChildCount + 1;
                path      = parent.Path;
            }
            else
            {
                path = "-1";
            }

            // Ruben 8/1/2007: I replace this with a parameterized version.
            // But does anyone know what the 'level++' is supposed to be doing there?
            // Nothing obviously, since it's a postfix.

            SqlHelper.ExecuteNonQuery("INSERT INTO umbracoNode(trashed, parentID, nodeObjectType, nodeUser, level, path, sortOrder, uniqueID, text, createDate) VALUES(@trashed, @parentID, @nodeObjectType, @nodeUser, @level, @path, @sortOrder, @uniqueID, @text, @createDate)",
                                      SqlHelper.CreateParameter("@trashed", 0),
                                      SqlHelper.CreateParameter("@parentID", parentId),
                                      SqlHelper.CreateParameter("@nodeObjectType", objectType),
                                      SqlHelper.CreateParameter("@nodeUser", userId),
                                      SqlHelper.CreateParameter("@level", level++),
                                      SqlHelper.CreateParameter("@path", path),
                                      SqlHelper.CreateParameter("@sortOrder", sortOrder),
                                      SqlHelper.CreateParameter("@uniqueID", uniqueID),
                                      SqlHelper.CreateParameter("@text", text),
                                      SqlHelper.CreateParameter("@createDate", DateTime.Now));

            CMSNode retVal = new CMSNode(uniqueID);

            retVal.Path = path + "," + retVal.Id.ToString();

            //event
            NewEventArgs e = new NewEventArgs();

            retVal.FireAfterNew(e);

            return(retVal);
        }
Ejemplo n.º 6
0
        public virtual void Move(int newParentId)
        {
            CMSNode parent = new CMSNode(newParentId);

            Move(parent);
        }
Ejemplo n.º 7
0
        private void Move(CMSNode newParent)
        {
            MoveEventArgs e = new MoveEventArgs();

            FireBeforeMove(e);

            if (!e.Cancel)
            {
                //first we need to establish if the node already exists under the newParent node
                //var isNewParentInPath = (Path.Contains("," + newParent.Id + ","));

                //if it's the same newParent, we can save some SQL calls since we know these wont change.
                //level and path might change even if it's the same newParent because the newParent could be moving somewhere.
                if (ParentId != newParent.Id)
                {
                    int maxSortOrder = SqlHelper.ExecuteScalar <int>("select coalesce(max(sortOrder),0) from umbracoNode where parentid = @parentId",
                                                                     SqlHelper.CreateParameter("@parentId", newParent.Id));

                    this.Parent    = newParent;
                    this.sortOrder = maxSortOrder + 1;
                }

                //detect if we have moved, then update the level and path
                // issue: http://issues.umbraco.org/issue/U4-1579
                if (this.Path != newParent.Path + "," + this.Id.ToString())
                {
                    this.Level = newParent.Level + 1;
                    this.Path  = newParent.Path + "," + this.Id.ToString();
                }

                //this code block should not be here but since the class structure is very poor and doesn't use
                //overrides (instead using shadows/new) for the Children property, when iterating over the children
                //and calling Move(), the super classes overridden OnMove or Move methods never get fired, so
                //we now need to hard code this here :(

                if (Path.Contains("," + ((int)RecycleBin.RecycleBinType.Content).ToString() + ",") ||
                    Path.Contains("," + ((int)RecycleBin.RecycleBinType.Media).ToString() + ","))
                {
                    //if we've moved this to the recyle bin, we need to update the trashed property
                    if (!IsTrashed)
                    {
                        IsTrashed = true;             //don't update if it's not necessary
                    }
                }
                else
                {
                    if (IsTrashed)
                    {
                        IsTrashed = false;            //don't update if it's not necessary
                    }
                }

                //make sure the node type is a document/media, if it is a recycle bin then this will not be equal
                if (!IsTrashed && newParent.nodeObjectType == Document._objectType)
                {
                    // regenerate the xml of the current document
                    var movedDocument = new Document(this.Id);
                    movedDocument.XmlGenerate(new XmlDocument());

                    //regenerate the xml for the newParent node
                    var parentDocument = new Document(newParent.Id);
                    parentDocument.XmlGenerate(new XmlDocument());
                }
                else if (!IsTrashed && newParent.nodeObjectType == Media._objectType)
                {
                    //regenerate the xml for the newParent node
                    var m = new Media(newParent.Id);
                    m.XmlGenerate(new XmlDocument());
                }

                var children = this.Children;
                foreach (CMSNode c in children)
                {
                    c.Move(this);
                }

                //TODO: Properly refactor this, we're just clearing the cache so the changes will also be visible in the backoffice
                InMemoryCacheProvider.Current.Clear();

                FireAfterMove(e);
            }
        }