Exemple #1
0
 /// <summary>
 /// The run once.
 /// </summary>
 public override void RunOnce()
 {
     try
     {
         this.Logger.Info(
             "Starting Forum Update||Add Task for ForumID {0}, {1} CategoryID, ParentID {2}.",
             this.ForumId, this.CategoryId, this.ParentId);
         _forumOut = LegacyDb.forum_save(this.ForumId, this.CategoryId, this.ParentId, this.Name,
                                         this.Description,
                                         this.SortOrder, this.Locked, this.Hidden, this.IsTest, this.Moderated,
                                         this.AccessMaskId, this.RemoteURL, this.ThemeURL, this.ImageURL,
                                         this.Styles,
                                         this.Dummy);
         this.Logger.Info("Forum Update||Add Task is completed. Handled forum {0}.", _forumOut);
     }
     catch (Exception x)
     {
         _forumOut = -1;
         this.Logger.Error(x, "Error In Forum Update||Add Task: {0}", x);
     }
 }
Exemple #2
0
        /// <summary>
        /// Handles the Click event of the Save control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.CategoryList.SelectedValue.Trim().Length == 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_CATEGORY"), MessageTypes.warning);
                return;
            }

            if (this.Name.Text.Trim().Length == 0)
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITFORUM", "MSG_NAME_FORUM"),
                    MessageTypes.warning);
                return;
            }

            if (this.SortOrder.Text.Trim().Length == 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_VALUE"), MessageTypes.warning);
                return;
            }

            short sortOrder;

            if (!ValidationHelper.IsValidPosShort(this.SortOrder.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITFORUM", "MSG_POSITIVE_VALUE"),
                    MessageTypes.warning);
                return;
            }

            if (!short.TryParse(this.SortOrder.Text.Trim(), out sortOrder))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_NUMBER"), MessageTypes.warning);
                return;
            }

            if (this.remoteurl.Text.IsSet())
            {
                // add http:// by default
                if (!Regex.IsMatch(this.remoteurl.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*"))
                {
                    this.remoteurl.Text = "http://" + this.remoteurl.Text.Trim();
                }

                if (!ValidationHelper.IsValidURL(this.remoteurl.Text))
                {
                    this.PageContext.AddLoadMessage(
                        this.GetText("ADMIN_EDITFORUM", "MSG_INVALID_URL"),
                        MessageTypes.warning);
                    return;
                }
            }

            // Forum
            // vzrus: it's stored in the DB as int
            var forumId     = this.GetQueryStringAsInt("fa");
            var forumCopyId = this.GetQueryStringAsInt("copy");

            object parentId = null;

            if (this.ParentList.SelectedValue.Length > 0)
            {
                parentId = this.ParentList.SelectedValue;
            }

            // parent selection check.
            if (parentId != null && parentId.ToString() == this.Request.QueryString.GetFirstOrDefault("fa"))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_PARENT_SELF"));
                return;
            }

            // The picked forum cannot be a child forum as it's a parent
            // If we update a forum ForumID > 0
            if (forumId.HasValue && parentId != null)
            {
                var dependency = LegacyDb.forum_save_parentschecker(forumId.Value, parentId);
                if (dependency > 0)
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_CHILD_PARENT"));
                    return;
                }
            }

            // inital access mask
            if (!forumId.HasValue && !forumCopyId.HasValue)
            {
                if (this.AccessMaskID.SelectedValue.Length == 0)
                {
                    this.PageContext.AddLoadMessage(
                        this.GetText("ADMIN_EDITFORUM", "MSG_INITAL_MASK"),
                        MessageTypes.warning);
                    return;
                }
            }

            // duplicate name checking...
            if (!forumId.HasValue)
            {
                var forumList = LegacyDb.forum_list(this.PageContext.PageBoardID, null).AsEnumerable();

                if (forumList.Any() && !this.Get <YafBoardSettings>().AllowForumsWithSameName &&
                    forumList.Any(dr => dr.Field <string>("Name") == this.Name.Text.Trim()))
                {
                    this.PageContext.AddLoadMessage(
                        this.GetText("ADMIN_EDITFORUM", "MSG_FORUMNAME_EXISTS"),
                        MessageTypes.warning);
                    return;
                }
            }

            object themeUrl = null;

            if (this.ThemeList.SelectedValue.Length > 0)
            {
                themeUrl = this.ThemeList.SelectedValue;
            }

            var newForumId = LegacyDb.forum_save(
                forumId,
                this.CategoryList.SelectedValue,
                parentId,
                this.Name.Text.Trim(),
                this.Description.Text.Trim(),
                sortOrder,
                this.Locked.Checked,
                this.HideNoAccess.Checked,
                this.IsTest.Checked,
                this.Moderated.Checked,
                this.ModerateAllPosts.Checked ? null : this.ModeratedPostCount.Text,
                this.ModerateNewTopicOnly.Checked,
                this.AccessMaskID.SelectedValue,
                IsNull(this.remoteurl.Text),
                themeUrl,
                this.ForumImages.SelectedIndex > 0 ? this.ForumImages.SelectedValue.Trim() : null,
                this.Styles.Text,
                false);

            // empty out access table(s)
            this.GetRepository <Active>().DeleteAll();
            this.GetRepository <ActiveAccess>().DeleteAll();

            // Access
            if (forumId.HasValue || forumCopyId.HasValue)
            {
                foreach (var item in this.AccessList.Items.OfType <RepeaterItem>())
                {
                    var groupId = int.Parse(item.FindControlAs <Label>("GroupID").Text);

                    LegacyDb.forumaccess_save(
                        newForumId,
                        groupId,
                        item.FindControlAs <DropDownList>("AccessmaskID").SelectedValue);
                }
            }

            this.ClearCaches();

            if (forumId.HasValue)
            {
                YafBuildLink.Redirect(ForumPages.admin_forums);
            }
            else
            {
                YafBuildLink.Redirect(ForumPages.admin_editforum, "fa={0}", newForumId);
            }
        }
Exemple #3
0
        /// <summary>
        /// Create forums from Categories
        /// </summary>
        /// <param name="categoryID">
        /// </param>
        /// <param name="parentID">
        /// The parent ID.
        /// </param>
        /// <param name="numForums">
        /// The num Forums.
        /// </param>
        /// <param name="_topicsToCreate">
        /// Number of topics to create.
        /// </param>
        /// <param name="_messagesToCreate">
        /// Number of messages to create.
        /// </param>
        /// <returns>
        /// The create forums.
        /// </returns>
        private int CreateForums(
            int categoryID, [NotNull] object parentID, int numForums, int _topicsToCreate, int _messagesToCreate)
        {
            bool countMessagesInStatistics = this.ForumsCountMessages.Text.Trim().IsNotSet();

            bool isHiddenIfNoAccess = this.ForumsHideNoAccess.Text.Trim().IsNotSet();

            isHiddenIfNoAccess = true;

            // ForumsCategory.Items.FindByValue("0").Selected = true;
            long uniqueForum = 0;
            int  iforums;

            for (iforums = 0; iforums < numForums; iforums++)
            {
                long _forumID = 0;
                this.randomGuid = Guid.NewGuid().ToString();
                DataTable _accessForumList = LegacyDb.forumaccess_list(_forumID);
                _forumID = LegacyDb.forum_save(
                    _forumID,
                    categoryID,
                    parentID,
                    this.ForumPrefixTB.Text.Trim() + this.randomGuid,
                    "Description of " + this.ForumPrefixTB.Text.Trim() + this.randomGuid,
                    100,
                    false,
                    isHiddenIfNoAccess,
                    countMessagesInStatistics,
                    false,
                    this.ForumsStartMask.SelectedValue,
                    null,
                    null,
                    null,
                    null,
                    false);

                if (_forumID <= 0)
                {
                    continue;
                }

                for (int i1 = 0; i1 < _accessForumList.Rows.Count; i1++)
                {
                    LegacyDb.forumaccess_save(
                        _forumID,
                        _accessForumList.Rows[i1]["GroupID"],
                        _accessForumList.Rows[i1]["AccessMaskID"].ToType <int>());
                }

                LegacyDb.forumaccess_save(_forumID, this.ForumsGroups.SelectedValue, this.ForumsAdminMask.SelectedValue);

                if (_topicsToCreate <= 0)
                {
                    continue;
                }

                if (uniqueForum == _forumID)
                {
                    continue;
                }

                this.CreateTopics(_forumID.ToType <int>(), _topicsToCreate, _messagesToCreate);
                uniqueForum = _forumID;
            }

            return(iforums);
        }
Exemple #4
0
        /// <summary>
        /// Create forums from Categories
        /// </summary>
        /// <param name="categoryID">
        /// </param>
        /// <param name="parentID">
        /// The parent ID.
        /// </param>
        /// <param name="numForums">
        /// The num Forums.
        /// </param>
        /// <param name="_topicsToCreate">
        /// Number of topics to create.
        /// </param>
        /// <param name="_messagesToCreate">
        /// Number of messages to create.
        /// </param>
        /// <returns>
        /// The create forums.
        /// </returns>
        private int CreateForums(
            int categoryID, [NotNull] object parentID, int numForums, int _topicsToCreate, int _messagesToCreate)
        {
            var countMessagesInStatistics = this.ForumsCountMessages.Text.Trim().IsNotSet();

            var isHiddenIfNoAccess = this.ForumsHideNoAccess.Text.Trim().IsNotSet();

            isHiddenIfNoAccess = true;

            // ForumsCategory.Items.FindByValue("0").Selected = true;
            long uniqueForum = 0;
            int  iforums;

            for (iforums = 0; iforums < numForums; iforums++)
            {
                long _forumID = 0;
                this.randomGuid = Guid.NewGuid().ToString();
                var accessForumList = this.GetRepository <ForumAccess>().GetForumAccessList(_forumID.ToType <int>());
                _forumID = LegacyDb.forum_save(
                    _forumID,
                    categoryID,
                    parentID,
                    this.ForumPrefixTB.Text.Trim() + this.randomGuid,
                    "Description of " + this.ForumPrefixTB.Text.Trim() + this.randomGuid,
                    100,
                    false,
                    isHiddenIfNoAccess,
                    countMessagesInStatistics,
                    false,
                    null,
                    false,
                    this.ForumsStartMask.SelectedValue,
                    null,
                    null,
                    null,
                    null,
                    false);

                if (_forumID <= 0)
                {
                    continue;
                }

                foreach (var access in accessForumList)
                {
                    this.GetRepository <ForumAccess>().Save(
                        _forumID.ToType <int>(),
                        access.GroupID,
                        access.AccessMaskID);
                }

                this.GetRepository <ForumAccess>().Save(
                    _forumID.ToType <int>(),
                    this.ForumsGroups.SelectedValue.ToType <int>(),
                    this.ForumsAdminMask.SelectedValue.ToType <int>());

                if (_topicsToCreate <= 0)
                {
                    continue;
                }

                if (uniqueForum == _forumID)
                {
                    continue;
                }

                this.CreateTopics(_forumID.ToType <int>(), _topicsToCreate, _messagesToCreate);
                uniqueForum = _forumID;
            }

            return(iforums);
        }