/// <summary> /// Rebuild click. /// </summary> protected void Rebuild() { if (sii != null) { if (DataHelper.DataSourceIsEmpty(sii.IndexSettings.GetAll()) && (sii.IndexType.ToLowerCSafe() != PredefinedObjectType.USER)) { ShowError(GetString("index.nocontent")); return; } if ((sii.IndexType.ToLowerCSafe() == PredefinedObjectType.DOCUMENT) || (sii.IndexType == SearchHelper.DOCUMENTS_CRAWLER_INDEX)) { DataSet ds = SearchIndexCultureInfoProvider.GetSearchIndexCultures("IndexID = " + sii.IndexID, null, 0, "IndexID, IndexCultureID"); if (DataHelper.DataSourceIsEmpty(ds)) { ShowError(GetString("index.noculture")); return; } } SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } ShowInformation(GetString("srch.index.rebuildstarted")); // Reload info panel Thread.Sleep(100); ReloadInfoPanel(); }
/// <summary> /// Starts the search index optimization task. /// </summary> private void Optimize() { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Optimize, null, null, SearchIndex.IndexName, SearchIndex.IndexID); RaiseAsyncIndexTaskStarted(); ShowInformation(GetString("srch.index.optimizestarted")); }
public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Get search index info SearchIndexInfo sii = null; if (this.ItemID > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.ItemID); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; // Reload info panel System.Threading.Thread.Sleep(100); ReloadInfoPanel(); } }
/// <summary> /// Rebuild click. /// </summary> protected void btnRebuild_Click(object sender, EventArgs e) { if (sii != null) { if ((sii.IndexType.ToLower() == PredefinedObjectType.DOCUMENT) || (sii.IndexType == SearchHelper.DOCUMENTS_CRAWLER_INDEX)) { DataSet ds = SearchIndexCultureInfoProvider.GetSearchIndexCultures("IndexID = " + sii.IndexID, null, 0, "IndexID, IndexCultureID"); if (SqlHelperClass.DataSourceIsEmpty(ds)) { lblInfo.Text = GetString("index.noculture"); lblInfo.Visible = true; return; } // Test content DataSet result = sii.IndexSettings.GetAll(); if (DataHelper.DataSourceIsEmpty(result)) { lblInfo.Text = GetString("index.nocontent"); lblInfo.Visible = true; return; } } SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; // Reload info panel System.Threading.Thread.Sleep(100); ReloadInfoPanel(); }
private static void RebuildIndex(SearchIndexInfo index) { try { // After installation or deployment the index is new but no web farm task is issued // to rebuild the index. This will ensure that index is rebuilt on instance upon first request. if (index.IndexStatusLocal == IndexStatusEnum.NEW) { var taskCreationParameters = new SearchTaskCreationParameters { TaskType = SearchTaskTypeEnum.Rebuild, TaskValue = index.IndexName, RelatedObjectID = index.IndexID }; taskCreationParameters.TargetServers.Add(WebFarmHelper.ServerName); SearchTaskInfoProvider.CreateTask(taskCreationParameters, true); } } catch (SearchIndexException ex) { Service.Resolve <IEventLogService>().LogException("SmartSearch", "INDEX REBUILD", ex); } }
private void Update_After(object sender, ObjectEventArgs e) { if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX)) { return; } var fileInfo = e.Object as MediaFileInfo; if (fileInfo == null) { return; } var taskInfo = new SearchTaskInfo { SearchTaskObjectType = SearchHelper.INDEX_TYPE, SearchTaskValue = fileInfo.FileID.ToString(), SearchTaskPriority = 0, SearchTaskType = SearchTaskTypeEnum.Update, SearchTaskStatus = SearchTaskStatusEnum.Ready }; SearchTaskInfoProvider.SetSearchTaskInfo(taskInfo); }
private void SaveData() { if (node != null) { // Update fields node.NodeBodyElementAttributes = txtBodyCss.Text; node.NodeDocType = txtDocType.Text; node.NodeHeadTags = txtHeadTags.Value.ToString(); // Update the node node.Update(); // Update search index if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); RegisterRefreshScript(); // Empty variable for exitwithoutchanges dialog ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "SubmitAction", ScriptHelper.GetScript("NotChanged();")); // Clear cache PageInfoProvider.RemoveAllPageInfosFromCache(); ShowChangesSaved(); } }
/// <summary> /// Handles click on rebuild link (after sites are saved). /// </summary> /// <param name="eventArgument"></param> public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Check permissions if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY)) { RedirectToAccessDenied("cms.searchindex", CMSAdminControl.PERMISSION_MODIFY); } // Get search index info SearchIndexInfo sii = null; if (this.indexId > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(this.indexId); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
/// <summary> /// Apply control settings. /// </summary> public bool ApplySettings() { if (MasterTemplateId <= 0) { lblError.Text = GetString("TemplateSelection.SelectTemplate"); return(false); } else { // Update all culture versions TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); DataSet ds = tree.SelectNodes(SiteName, "/", TreeProvider.ALL_CULTURES, false, "CMS.Root", null, null, -1, false); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { // Update the document TreeNode node = TreeNode.New(dr, "CMS.Root", tree); node.SetDefaultPageTemplateID(MasterTemplateId); node.Update(); // Update search index for node if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); } } } } return(true); }
private void SaveData() { if (node != null) { // Update fields node.NodeBodyElementAttributes = txtBodyCss.Text; node.NodeDocType = txtDocType.Text; node.NodeHeadTags = txtHeadTags.Value.ToString(); // Update the node node.Update(); // Update search index if (DocumentHelper.IsSearchTaskCreationAllowed(node)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, TreeNode.OBJECT_TYPE, SearchFieldsConstants.ID, node.GetSearchID(), node.DocumentID); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); RegisterRefreshScript(); // Empty variable for exitwithoutchanges dialog ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "SubmitAction", "CMSContentManager.changed(false);", true); // Clear cache PageInfoProvider.RemoveAllPageInfosFromCache(); ShowChangesSaved(); // Clear content changed flag DocumentManager.ClearContentChanged(); } }
/// <summary> /// Apply control settings. /// </summary> public bool ApplySettings() { if (MasterTemplateId <= 0) { lblError.Text = GetString("TemplateSelection.SelectTemplate"); return(false); } else { // Update all culture versions TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); DataSet ds = tree.SelectNodes(SiteName, "/", TreeProvider.ALL_CULTURES, false, SystemDocumentTypes.Root, null, null, -1, false); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { // Update the document TreeNode node = TreeNode.New(SystemDocumentTypes.Root, dr, tree); node.SetDefaultPageTemplateID(MasterTemplateId); node.Update(); // Update search index for node if (DocumentHelper.IsSearchTaskCreationAllowed(node)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, TreeNode.OBJECT_TYPE, SearchFieldsConstants.ID, node.GetSearchID(), node.DocumentID); } } } } return(true); }
public void RaisePostBackEvent(string eventArgument) { // Rebuild search index if (SearchIndexInfoProvider.SearchEnabled) { SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId); if (si != null) { // Get all indexes depending on given site DataSet result = SearchIndexSiteInfoProvider.GetSiteSearchIndexes(si.SiteID); if (!DataHelper.DataSourceIsEmpty(result)) { List <string> items = new List <string>(); SearchIndexInfo sii = null; // Add all indexes to rebuild queue foreach (DataRow dr in result.Tables[0].Rows) { sii = SearchIndexInfoProvider.GetSearchIndexInfo((int)dr["IndexID"]); if (sii != null) { items.Add(sii.IndexName); } } // Rebuild all indexes SearchTaskInfoProvider.CreateMultiTask(SearchTaskTypeEnum.Rebuild, null, null, items, true); } } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
/// <summary> /// Get the transformation to interpret task related object data. /// </summary> /// <param name="row">Grid row</param> /// <returns>Transformation that displays object identified by object type and ID.</returns> private object RenderRelatedObject(DataRowView row) { if (row == null) { return(String.Empty); } int objectId = ValidationHelper.GetInteger(row.Row["SearchTaskRelatedObjectID"], 0); string taskTypeRaw = ValidationHelper.GetString(row.Row["SearchTaskType"], ""); SearchTaskTypeEnum taskType; string objectType = null; // try to get search task type. Type doesn't have a default value. try { taskType = ValidationHelper.GetString(taskTypeRaw, "").ToEnum <SearchTaskTypeEnum>(); } catch (Exception ex) { EventLogProvider.LogEvent( EventType.ERROR, "Smart search", "LISTSEARCHTASKS", "Unknown search task type: " + taskTypeRaw + ". Original exception:" + Environment.NewLine + EventLogProvider.GetExceptionLogMessage(ex) ); return(String.Empty); } // Object type objectType = SearchTaskInfoProvider.GetSearchTaskRelatedObjectType(ValidationHelper.GetString(row.Row["SearchTaskObjectType"], ""), taskType); // Object cannot be interpreted if (String.IsNullOrEmpty(objectType) || (objectId == 0)) { return(String.Empty); } // create transformation ObjectTransformation transformation = new ObjectTransformation(objectType, objectId); transformation.Transformation = String.Format("{{% Object.GetFullObjectName(false, true) %}}"); ObjectTypeInfo typeInfo = ObjectTypeManager.GetTypeInfo(objectType); if (typeInfo != null) { transformation.NoDataTransformation = LocalizationHelper.GetStringFormat("smartsearch.searchtaskrelatedobjectnotexist", typeInfo.GetNiceObjectTypeName(), objectId); } return(transformation); }
/// <summary> /// Rebuilds the search index. Called when the "Rebuild index" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool RebuildIndex() { // Get the search index SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex"); if (index != null) { // Create rebuild task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, index.IndexType, null, index.IndexName); return(true); } return(false); }
/// <summary> /// Optimize click. /// </summary> protected void Optimize() { // Rebuild search index info if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Optimize, sii.IndexType, null, sii.IndexName); } ShowConfirmation(GetString("srch.index.optimizestarted")); // Reload info panel Thread.Sleep(100); ReloadInfoPanel(); }
/// <summary> /// Optimize click. /// </summary> protected void btnOptimize_Click(object sender, EventArgs e) { // Rebuild search index info if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Optimize, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.optimizestarted"); lblInfo.Visible = true; // Reload info panel System.Threading.Thread.Sleep(100); ReloadInfoPanel(); }
/// <summary> /// Creates or rebuild department content search index. /// </summary> /// <param name="departmentNode">Department node</param> private void CreateDepartmentContentSearchIndex(TreeNode departmentNode) { string codeName = "default_department_" + departmentNode.NodeGUID; string departmentName = departmentNode.GetDocumentName(); SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = TreeNode.OBJECT_TYPE; sii.IndexIsCommunityGroup = false; sii.IndexProvider = SearchIndexInfo.LUCENE_SEARCH_PROVIDER; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = departmentNode.NodeAliasPath + "/%"; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assign to current website SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); } // Add current culture to search index CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture); SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); // Rebuild search index SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID); }
/// <summary> /// Creates content search index. /// </summary> /// <param name="group">Particular group info object</param> private void CreateGroupContentSearchIndex(GroupInfo group) { string codeName = "default_group_" + group.GroupGUID; SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName); if (sii == null) { // Create search index info sii = new SearchIndexInfo(); sii.IndexName = codeName; const string suffix = " - Default"; sii.IndexDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, string.Empty) + suffix; sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer; sii.IndexType = TreeNode.OBJECT_TYPE; sii.IndexIsCommunityGroup = false; sii.IndexProvider = SearchIndexInfo.LUCENE_SEARCH_PROVIDER; // Create search index settings info SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo(); sisi.ID = Guid.NewGuid(); sisi.Path = mGroupTemplateTargetAliasPath + "/" + group.GroupName + "/%"; sisi.SiteName = SiteContext.CurrentSiteName; sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED; sisi.ClassNames = ""; // Create settings item SearchIndexSettings sis = new SearchIndexSettings(); // Update settings item sis.SetSearchIndexSettingsInfo(sisi); // Update xml value sii.IndexSettings = sis; SearchIndexInfoProvider.SetSearchIndexInfo(sii); // Assign to current website and current culture SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID); CultureInfo ci = DocumentContext.CurrentDocumentCulture; if (ci != null) { SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID); } // Register rebuild index action SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID); } }
private void Delete_After(object sender, ObjectEventArgs e) { if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX)) { return; } var fileInfo = e.Object as MediaFileInfo; if (fileInfo == null) { return; } SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Delete, CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX, SearchFieldsConstants.ID, fileInfo.FileID.ToString(), 0); }
protected void btnSave_Click(object sender, EventArgs ea) { // Check modify permissions CurrentUserInfo ui = CMSContext.CurrentUser; if (node != null) { // Check permissions if (ui.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied) { RedirectToAccessDenied(String.Format(GetString("cmsdesk.notauthorizedtoreaddocument"), node.NodeAliasPath)); } string conversionValue = ValidationHelper.GetString(ucConversionSelector.Value, String.Empty).Trim(); if (!ucConversionSelector.IsValid()) { lblError.Text = ucConversionSelector.ValidationError; lblError.Visible = true; return; } if (!usSelectCampaign.IsValid()) { lblError.Visible = true; lblError.Text = usSelectCampaign.ValidationError; return; } node.DocumentCampaign = ValidationHelper.GetString(usSelectCampaign.Value, String.Empty).Trim(); node.DocumentConversionValue = txtConversionValue.Text; node.DocumentTrackConversionName = conversionValue; node.Update(); lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); // Update search index if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); } }
public string Execute(TaskInfo task) { var customSearchIndexes = SearchIndexInfoProvider.GetSearchIndexes() .WhereEquals(nameof(SearchIndexInfo.IndexType), CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX); var searchIndex = customSearchIndexes.SingleOrDefault(i => SearchHelper.GetCustomSearchIndexClassName(i) == typeof(SearchIndex).FullName); if (searchIndex == null) { return($"Search index of type {SearchHelper.INDEX_TYPE} was not found."); } var provider = SearchTaskInfoProvider.GetSearchTasks() .WhereEquals(nameof(SearchTaskInfo.SearchTaskObjectType), SearchHelper.INDEX_TYPE) .WhereEquals(nameof(SearchTaskInfo.SearchTaskStatus), SearchTaskStatusEnum.Ready.ToString()) .WhereEquals(nameof(SearchTaskInfo.SearchTaskType), SearchTaskTypeEnum.Update.ToString()); if (searchIndex.IndexBatchSize > 0) { provider = provider.TopN(searchIndex.IndexBatchSize); } var lastId = 0; List <SearchTaskInfo> searchTasks; List <ISearchDocument> searchDocuments = new List <ISearchDocument>(); while ((searchTasks = provider.WhereGreaterThan(nameof(SearchTaskInfo.SearchTaskID), lastId).OrderBy(nameof(SearchTaskInfo.SearchTaskID)).ToList()).Any()) { var mediaFilesIds = searchTasks.Select(t => Convert.ToInt32(t.SearchTaskValue)).ToList(); var mediaFiles = MediaFileInfoProvider.GetMediaFiles().WhereIn(nameof(MediaFileInfo.FileID), mediaFilesIds); foreach (var searchTask in searchTasks) { searchDocuments.Add(SearchHelper.GetSearchDocument(mediaFiles.Single(f => f.FileID == Convert.ToInt32(searchTask.SearchTaskValue)), searchIndex)); } lastId = searchTasks.Last().SearchTaskID; SearchTaskInfoProvider.ProviderObject.BulkDelete(new WhereCondition(SqlHelper.GetWhereInCondition(nameof(SearchTaskInfo.SearchTaskID), searchTasks.Select(s => s.SearchTaskID).ToList(), false, false))); } searchDocuments.ForEach(doc => CMS.Search.SearchHelper.Update(doc, searchIndex)); return($"Processed {searchDocuments.Count} files."); }
/// <summary> /// Adds search index to site. Called when the "Add index to site" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool UpdateIndex() { // Tree provider TreeProvider provider = new TreeProvider(MembershipContext.AuthenticatedUser); // Get document of specified site, aliaspath and culture TreeNode node = provider.SelectSingleNode(SiteContext.CurrentSiteName, "/", "en-us"); // If node exists if ((node != null) && DocumentHelper.IsSearchTaskCreationAllowed(node)) { // Edit and save document node node.NodeDocType += " changed"; node.Update(); // Create update task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, TreeNode.OBJECT_TYPE, SearchFieldsConstants.ID, node.GetSearchID(), node.DocumentID); return(true); } return(false); }
public void RaisePostBackEvent(string eventArgument) { if (eventArgument == "saved") { // Get search index info SearchIndexInfo sii = null; if (IndexID > 0) { sii = SearchIndexInfoProvider.GetSearchIndexInfo(IndexID); } // Create rebuild task if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); } lblInfo.Text = GetString("srch.index.rebuildstarted"); lblInfo.Visible = true; } }
/// <summary> /// Adds search index to site. Called when the "Add index to site" button is pressed. /// Expects the CreateSearchIndex method to be run first. /// </summary> private bool UpdateIndex() { // Tree provider TreeProvider provider = new TreeProvider(CMSContext.CurrentUser); // Get document of specified site, aliaspath and culture TreeNode node = provider.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us"); // If node exists if ((node != null) && (node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { // Edit and save document node node.NodeDocType += " changed"; node.Update(); // Create update task SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); return(true); } return(false); }
protected void chkMarkDocAsProd_CheckedChanged(object sender, EventArgs e) { if (!IsAuthorizedToModifyDocument()) { RedirectToAccessDenied("CMS.Content", "Modify"); } this.Node.NodeSKUID = 0; this.Node.Update(); // Update search index for node if ((this.Node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, this.Node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(this.Node, TaskTypeEnum.UpdateDocument, this.Node.TreeProvider); ScriptHelper.RegisterStartupScript(Page, typeof(string), "FirstTabSelection", ScriptHelper.GetScript(" parent.window.location = '" + URLHelper.ResolveUrl("~/CMSModules/Ecommerce/Pages/Content/Product/Product_Selection.aspx") + "?nodeid=" + this.NodeID + "&productid=" + productId + "' ")); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void UniGrid_OnAction(string actionName, object actionArgument) { switch (actionName) { case "edit": this.SelectedItemID = Convert.ToInt32(actionArgument); RaiseOnEdit(); break; case "delete": // Delete search index info object from database with it's dependencies SearchIndexInfoProvider.DeleteSearchIndexInfo(Convert.ToInt32(actionArgument)); break; case "rebuild": if (SearchIndexInfoProvider.SearchEnabled) { // Rebuild search index info SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(Convert.ToInt32(actionArgument)); if (sii != null) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, sii.IndexType, null, sii.IndexName); // Sleep System.Threading.Thread.Sleep(100); } lblInfo.ResourceString = "srch.index.rebuildstarted"; lblInfo.Visible = true; } else { lblError.ResourceString = "srch.index.searchdisabled"; lblError.Visible = true; } break; } }
/// <summary> /// Saves modified image data. /// </summary> /// <param name="name">Image name</param> /// <param name="extension">Image extension</param> /// <param name="mimetype">Image mimetype</param> /// <param name="title">Image title</param> /// <param name="description">Image description</param> /// <param name="binary">Image binary data</param> /// <param name="width">Image width</param> /// <param name="height">Image height</param> private void SaveImage(string name, string extension, string mimetype, string title, string description, byte[] binary, int width, int height) { LoadInfos(); // Save image data depending to image type switch (baseImageEditor.ImageType) { // Process attachment case ImageHelper.ImageTypeEnum.Attachment: if (ai != null) { // Save new data try { // Get the node TreeNode node = DocumentHelper.GetDocument(ai.AttachmentDocumentID, baseImageEditor.Tree); // Check Create permission when saving temporary attachment, check Modify permission else NodePermissionsEnum permissionToCheck = (ai.AttachmentFormGUID == Guid.Empty) ? NodePermissionsEnum.Modify : NodePermissionsEnum.Create; // Check permission if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(node, permissionToCheck) != AuthorizationResultEnum.Allowed) { baseImageEditor.ShowError(GetString("attach.actiondenied")); SavingFailed = true; return; } if (!IsNameUnique(name, extension)) { baseImageEditor.ShowError(GetString("img.namenotunique")); SavingFailed = true; return; } // Ensure automatic check-in/ check-out bool useWorkflow = false; bool autoCheck = false; WorkflowManager workflowMan = WorkflowManager.GetInstance(baseImageEditor.Tree); if (node != null) { // Get workflow info WorkflowInfo wi = workflowMan.GetNodeWorkflow(node); // Check if the document uses workflow if (wi != null) { useWorkflow = true; autoCheck = !wi.UseCheckInCheckOut(CurrentSiteName); } // Check out the document if (autoCheck) { VersionManager.CheckOut(node, node.IsPublished, true); VersionHistoryID = node.DocumentCheckedOutVersionHistoryID; } // Workflow has been lost, get published attachment if (useWorkflow && (VersionHistoryID == 0)) { ai = AttachmentInfoProvider.GetAttachmentInfo(ai.AttachmentGUID, CurrentSiteName); } // If extension changed update CMS.File extension if ((node.NodeClassName.ToLowerCSafe() == "cms.file") && (node.DocumentExtensions != extension)) { // Update document extensions if no custom are used if (!node.DocumentUseCustomExtensions) { node.DocumentExtensions = extension; } node.SetValue("DocumentType", extension); DocumentHelper.UpdateDocument(node, baseImageEditor.Tree); } } if (ai != null) { // Test all parameters to empty values and update new value if available if (name != "") { if (!name.EndsWithCSafe(extension)) { ai.AttachmentName = name + extension; } else { ai.AttachmentName = name; } } if (extension != "") { ai.AttachmentExtension = extension; } if (mimetype != "") { ai.AttachmentMimeType = mimetype; } ai.AttachmentTitle = title; ai.AttachmentDescription = description; if (binary != null) { ai.AttachmentBinary = binary; ai.AttachmentSize = binary.Length; } if (width > 0) { ai.AttachmentImageWidth = width; } if (height > 0) { ai.AttachmentImageHeight = height; } // Ensure object ai.MakeComplete(true); if (VersionHistoryID > 0) { VersionManager.SaveAttachmentVersion(ai, VersionHistoryID); } else { AttachmentInfoProvider.SetAttachmentInfo(ai); // Log the synchronization and search task for the document if (node != null) { // Update search index for given document if (DocumentHelper.IsSearchTaskCreationAllowed(node)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, TreeNode.OBJECT_TYPE, SearchFieldsConstants.ID, node.GetSearchID(), node.DocumentID); } DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, baseImageEditor.Tree); } } // Check in the document if ((autoCheck) && (VersionManager != null) && (VersionHistoryID > 0) && (node != null)) { VersionManager.CheckIn(node, null); } } } catch (Exception ex) { baseImageEditor.ShowError(GetString("img.errors.processing"), tooltipText: ex.Message); EventLogProvider.LogException("Image editor", "SAVEIMAGE", ex); SavingFailed = true; } } break; case ImageHelper.ImageTypeEnum.PhysicalFile: if (!String.IsNullOrEmpty(filePath)) { var currentUser = MembershipContext.AuthenticatedUser; if ((currentUser != null) && currentUser.IsGlobalAdministrator) { try { string physicalPath = Server.MapPath(filePath); string newPath = physicalPath; // Write binary data to the disk File.WriteAllBytes(physicalPath, binary); // Handle rename of the file if (!String.IsNullOrEmpty(name)) { newPath = DirectoryHelper.CombinePath(Path.GetDirectoryName(physicalPath), name); } if (!String.IsNullOrEmpty(extension)) { string oldExt = Path.GetExtension(physicalPath); newPath = newPath.Substring(0, newPath.Length - oldExt.Length) + extension; } // Move the file if (newPath != physicalPath) { File.Move(physicalPath, newPath); } } catch (Exception ex) { baseImageEditor.ShowError(GetString("img.errors.processing"), tooltipText: ex.Message); EventLogProvider.LogException("Image editor", "SAVEIMAGE", ex); SavingFailed = true; } } else { baseImageEditor.ShowError(GetString("img.errors.rights")); SavingFailed = true; } } break; // Process metafile case ImageHelper.ImageTypeEnum.Metafile: if (mf != null) { if (UserInfoProvider.IsAuthorizedPerObject(mf.MetaFileObjectType, mf.MetaFileObjectID, PermissionsEnum.Modify, CurrentSiteName, MembershipContext.AuthenticatedUser)) { try { // Test all parameters to empty values and update new value if available if (name.CompareToCSafe("") != 0) { if (!name.EndsWithCSafe(extension)) { mf.MetaFileName = name + extension; } else { mf.MetaFileName = name; } } if (extension.CompareToCSafe("") != 0) { mf.MetaFileExtension = extension; } if (mimetype.CompareToCSafe("") != 0) { mf.MetaFileMimeType = mimetype; } mf.MetaFileTitle = title; mf.MetaFileDescription = description; if (binary != null) { mf.MetaFileBinary = binary; mf.MetaFileSize = binary.Length; } if (width > 0) { mf.MetaFileImageWidth = width; } if (height > 0) { mf.MetaFileImageHeight = height; } // Save new data MetaFileInfoProvider.SetMetaFileInfo(mf); if (RefreshAfterAction) { if (String.IsNullOrEmpty(externalControlID)) { baseImageEditor.LtlScript.Text = ScriptHelper.GetScript("Refresh();"); } else { baseImageEditor.LtlScript.Text = ScriptHelper.GetScript(String.Format("InitRefresh({0}, false, false, '{1}', 'refresh')", ScriptHelper.GetString(externalControlID), mf.MetaFileGUID)); } } } catch (Exception ex) { baseImageEditor.ShowError(GetString("img.errors.processing"), tooltipText: ex.Message); EventLogProvider.LogException("Image editor", "SAVEIMAGE", ex); SavingFailed = true; } } else { baseImageEditor.ShowError(GetString("img.errors.rights")); SavingFailed = true; } } break; } }
private void SubmitForm() { if (ctrlProduct.ProductID > 0) { // Check permissions if (ctrlProduct.ProductSiteID > 0) { if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyProducts")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyProducts"); } } else { if (!ECommerceContext.IsUserAuthorizedForPermission("EcommerceGlobalModify")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } } // Update if (chkMarkDocAsProd.Checked) { ctrlProduct.Save(); } // Delete else { this.Node.NodeSKUID = 0; this.Node.Update(); // Update search index for node if ((this.Node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, this.Node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(this.Node, TaskTypeEnum.UpdateDocument, this.Node.TreeProvider); URLHelper.Redirect("Product_Selection.aspx?nodeid=" + this.NodeID); } } else { if (!IsAuthorizedToModifyDocument()) { RedirectToAccessDenied("CMS.Content", "Modify"); } // Use existing product if (radSelect.Checked) { if (skuElem.SKUID > 0) { this.Node.NodeSKUID = this.skuElem.SKUID; this.Node.Update(); // Update search index for node if ((this.Node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, this.Node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(this.Node, TaskTypeEnum.UpdateDocument, this.Node.TreeProvider); URLHelper.Redirect(String.Format("Product_Edit_Frameset.aspx?productid={0}&nodeid={1}&saved=1", this.Node.NodeSKUID, this.NodeID)); } else { lblError.Visible = true; lblError.Text = GetString("Products.EmptyList"); } } // Create new product else { ctrlProduct.Save(); } } }
protected void btnSave_Click(object sender, EventArgs e) { if ((nodeId > 0) && (node != null)) { LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(drpType.SelectedValue); // Check the permissions if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode")) { // Update the layout if (node.DocumentPageTemplateID > 0) { PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(node.DocumentPageTemplateID); if (pti != null) { // Get shared layout LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(pti.LayoutID); if (li != null) { // Update shared layout li.LayoutCode = txtLayout.Text; li.LayoutType = layoutType; LayoutInfoProvider.SetLayoutInfo(li); } else if (pti.PageTemplateLayoutCheckedOutByUserID <= 0) { // Update custom layout pti.PageTemplateLayout = txtLayout.Text; pti.PageTemplateLayoutType = layoutType; PageTemplateInfoProvider.SetPageTemplateInfo(pti); } } } } // Update fields node.NodeBodyElementAttributes = txtBodyCss.Text; node.NodeDocType = txtDocType.Text; node.NodeHeadTags = txtHeadTags.Value.ToString(); // Update the node node.Update(); // Update search index if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled)) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); } // Log synchronization DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree); lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); // Clear cache PageInfoProvider.RemoveAllPageInfosFromCache(); } }
public void RaisePostBackEvent(string eventArgument) { CurrentUserInfo currentUser = CMSContext.CurrentUser; // Current Node ID int nodeId = ValidationHelper.GetInteger(Param1, 0); TreeProvider tree = new TreeProvider(currentUser); EventLogProvider log = new EventLogProvider(); string documentName = ""; string action = Action.ToLower(); // Process the request switch (action) { case "moveup": case "movedown": // Move the document up (document order) try { if (nodeId == 0) { AddAlert(GetString("ContentRequest.ErrorMissingSource")); return; } // Get document to move TreeNode node = tree.SelectSingleNode(nodeId); // Check the permissions for document if (currentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed) { switch (action) { case "moveup": node = tree.MoveNodeUp(nodeId); break; case "movedown": node = tree.MoveNodeDown(nodeId); break; } string siteName = CMSContext.CurrentSiteName; if (SettingsKeyProvider.GetBoolValue(siteName + ".CMSStagingLogChanges")) { // Load all nodes under parent node if (node != null) { string parentPath = TreePathUtils.GetParentPath(node.NodeAliasPath); DataSet ds = tree.SelectNodes(siteName, parentPath.TrimEnd('/') + "/%", TreeProvider.ALL_CULTURES, true, null, null, null, 1); // Check if data source is not empty if (!DataHelper.DataSourceIsEmpty(ds)) { // Go through all nodes foreach (DataRow dr in ds.Tables[0].Rows) { // Update child nodes int logNodeId = ValidationHelper.GetInteger(dr["NodeID"], 0); string culture = ValidationHelper.GetString(dr["DocumentCulture"], ""); string className = ValidationHelper.GetString(dr["ClassName"], ""); TreeNode tn = tree.SelectSingleNode(logNodeId, culture, className); DocumentSynchronizationHelper.LogDocumentChange(tn, TaskTypeEnum.UpdateDocument, tree); } } } } // Move the node if (node != null) { documentName = node.DocumentName; treeContent.ExpandNodeID = node.NodeParentID; treeContent.NodeID = node.NodeID; } else { AddAlert(GetString("ContentRequest.MoveFailed")); } } else { AddAlert(GetString("ContentRequest.MoveDenied")); } } catch (Exception ex) { log.LogEvent(EventLogProvider.EVENT_TYPE_ERROR, DateTime.Now, "Content", "MOVE", currentUser.UserID, currentUser.UserName, nodeId, documentName, HTTPHelper.UserHostAddress, EventLogProvider.GetExceptionLogMessage(ex), CMSContext.CurrentSite.SiteID, HTTPHelper.GetAbsoluteUri()); AddAlert(GetString("ContentRequest.MoveFailed") + " : " + ex.Message); } break; case "delete": // Delete the document try { if (nodeId == 0) { AddAlert(GetString("DefineSiteStructure.ErrorMissingSource")); return; } // Get the node TreeNode node = tree.SelectSingleNode(nodeId); // Delete the node if (node != null) { treeContent.NodeID = node.NodeParentID; node.Delete(); // Delete search index for given node if (SearchIndexInfoProvider.SearchEnabled) { SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Delete, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID()); } if (node.NodeAliasPath == "/") { // Refresh root document treeContent.NodeID = node.NodeID; AddScript("SelectNode(" + node.NodeID + "); \n"); } else { AddScript("SelectNode(" + node.NodeParentID + "); \n"); } } } catch (Exception ex) { AddAlert(GetString("DefineSiteStructure.DeleteFailed") + " : " + ex.Message); } break; } }