public UnicornOperationContext() { _sd = new SecurityDisabler(); _ed = new EventDisabler(); // events, e.g. indexing, et al. This is what Sitecore's serialization API uses, and it's a superset of BulkUpdateContext _fd = new ItemFilterDisabler(); // disable all item filtering (if we're running in live mode we need this to get unadulterated items) _tds = new TransparentSyncDisabler(); }
public void Dispose() { if (_securityDisabler != null) { _securityDisabler.Dispose(); _securityDisabler = null; } if (_siteContextSwitcher != null) { _siteContextSwitcher.Dispose(); _siteContextSwitcher = null; } if (_languageSwitcher != null) { _languageSwitcher.Dispose(); _languageSwitcher = null; } if (_databaseSwitcher != null) { _databaseSwitcher.Dispose(); _databaseSwitcher = null; } if (_userSwitcher != null) { _userSwitcher.Dispose(); _userSwitcher = null; } }
/// <summary> /// Initializes a new instance of the <see cref="ItemEditing"/> class. /// </summary> /// <param name="item">The item.</param> /// <param name="disableSecurity">if set to <c>true</c> [disable security].</param> public ItemEditing(Item item, bool disableSecurity) { _item = item; if (disableSecurity) _securityDisabler = new SecurityDisabler(); _item.Editing.BeginEdit(); }
public static void SitecoreContentImport(DataTable table, string language, string displayName) { var _sourceLanguage = LanguageManager.GetLanguage(language); var _masterDb = ScHelpers.GetDatabase(Constants.DatabaseNames.Master); foreach (DataRow row in table.Rows) { string text = row["ID"].ToString(); if (string.IsNullOrEmpty(text)) { return; } Item item = _masterDb.GetItem(text, _sourceLanguage); if (item == null) { return; } for (int i = 3; i < table.Columns.Count; i++) { string fieldName = table.Columns[i].ColumnName; Field val = item.Fields.Where(x => x.Name.Equals(fieldName)).FirstOrDefault(); if (val != null) { string value = row[val.Name].ToString(); using (SecurityDisabler val2 = new SecurityDisabler()) { try { item.Editing.BeginEdit(); val.Value = value; item.Editing.EndEdit(); } finally { val2?.Dispose(); } } } if (!string.IsNullOrEmpty(displayName) && displayName.ToLower().Equals("true")) { using (SecurityDisabler val3 = new SecurityDisabler()) { try { item.Editing.BeginEdit(); item.Appearance.DisplayName = row["Name"].ToString(); item.Editing.EndEdit(); } finally { val3?.Dispose(); } } } } } }
public void Setup() { _disabler = new SecurityDisabler(); _db = Sitecore.Configuration.Factory.GetDatabase("master"); _dataProvider = new GlassDataProvider("master", Context.DefaultContextName); _context = Context.Create(Utilities.CreateStandardResolver()); GlassDataProvider._setupComplete = false; InjectionDataProvider(_db, _dataProvider); }
public void Setup() { _disabler = new SecurityDisabler(); _db = Factory.GetDatabase("master"); _dataProvider = new GlassDataProvider("master", Context.DefaultContextName); _context = Context.Create(Utilities.CreateStandardResolver()); //GlassDataProvider._setupComplete = false; InjectionDataProvider(_db, _dataProvider); }
/// <summary> /// Initializes a new instance of the <see cref="ItemEditing"/> class. /// </summary> /// <param name="item">The item.</param> /// <param name="disableSecurity">if set to <c>true</c> [disable security].</param> public ItemEditing(Item item, bool disableSecurity) { _item = item; if (disableSecurity) { _securityDisabler = new SecurityDisabler(); } _item.Editing.BeginEdit(); }
/// <summary> /// Checks, if the specified item exist in Core DB. /// </summary> private bool ItemExist(Database database, string localPath) { bool flag; using (SecurityDisabler securityDisabler = new SecurityDisabler()) { Item item = database.GetItem(localPath) ?? this.GetAliasItem(database, localPath); flag = item != null; } return(flag); }
public ReportContext(string userName = "******", string siteName = "shell", string databaseName = "master", string language = null) { var user = User.FromName(userName, false); _userSwitcher = new UserSwitcher(user); _databaseSwitcher = new DatabaseSwitcher(Sitecore.Configuration.Factory.GetDatabase(databaseName)); if (!string.IsNullOrEmpty(language)) { _languageSwitcher = new LanguageSwitcher(language); } _siteContextSwitcher = new SiteContextSwitcher(SiteContextFactory.GetSiteContext(siteName)); _securityDisabler = new SecurityDisabler(); }
public virtual void Execute(ID formid, AdaptedResultList fields, object[] data = null) { SecurityDisabler securityDisabler = (SecurityDisabler)null; if (!this.CheckSecurity) securityDisabler = new SecurityDisabler(); try { this.CreateItemByFields(formid, fields); } finally { if (securityDisabler != null) securityDisabler.Dispose(); } }
public void Setup() { _db = new Db { }; _disabler = new SecurityDisabler(); _datebase = _db.Database; _dataProvider = new GlassDataProvider("master", Context.DefaultContextName); GlassDataProvider.GetSqlProviderFunc = providers => providers.FirstOrDefault(x => x is FakeDataProvider); _context = Context.Create(Utilities.CreateStandardResolver()); //GlassDataProvider._setupComplete = false; InjectionDataProvider(_datebase, _dataProvider); }
public void Setup() { _disabler = new SecurityDisabler(); //remove provider from database var db = Sitecore.Configuration.Factory.GetDatabase("master"); var providers = GetProviders(db); var toRemove = providers.Where(x => x is GlassDataProvider).ToList(); toRemove.ForEach(x => providers.Remove(x)); var path = "/sitecore/templates/glasstemplates"; var rootFolder = db.GetItem(path); if (rootFolder != null) rootFolder.Delete(); }
public void TearDown() { var providers = GetProviders(_db); var toRemove = providers.Where(x => x is GlassDataProvider).ToList(); toRemove.ForEach(x => providers.Remove(x)); var path = "/sitecore/templates/glasstemplates"; var rootFolder = _db.GetItem(path); if (rootFolder != null) rootFolder.Delete(); _disabler.Dispose(); _db = null; _dataProvider = null; _disabler = null; }
public virtual int Compare(Item x, Item y) { int num; if (x.ID == y.ID) { return(0); } using (SecurityDisabler securityDisabler = new SecurityDisabler()) { Item parent = x.Parent; if (parent.ID != y.ParentID) { string longID = x.Paths.LongID; string str = y.Paths.LongID; if (longID.StartsWith(str)) { num = -1; } else if (!str.StartsWith(longID)) { string[] strArrays = longID.Split(new char[] { '/' }); string[] strArrays1 = str.Split(new char[] { '/' }); int num1 = Math.Min((int)strArrays.Length, (int)strArrays1.Length) - 1; while (strArrays[num1] != strArrays1[num1]) { num1--; } ID d = ID.Parse(strArrays[num1]); Item item = x.Database.GetItem(ID.Parse(strArrays[num1 + 1])); Item item1 = x.Database.GetItem(ID.Parse(strArrays1[num1 + 1])); num = this.GetComparer(d, x.Database, null).Compare(item, item1); } else { num = 1; } } else { num = this.GetComparer(parent.ID, x.Database, parent).Compare(x, y); } } return(num); }
public void TearDown() { var providers = GetProviders(_db); var toRemove = providers.Where(x => x is GlassDataProvider).ToList(); toRemove.ForEach(x => providers.Remove(x)); var path = "/sitecore/templates/glasstemplates"; var rootFolder = _db.GetItem(path); if (rootFolder != null) { rootFolder.Delete(); } _disabler.Dispose(); _db = null; _dataProvider = null; _disabler = null; }
public virtual void Execute(ID formid, AdaptedResultList fields, object[] data = null) { SecurityDisabler securityDisabler = (SecurityDisabler)null; if (!this.CheckSecurity) { securityDisabler = new SecurityDisabler(); } try { this.CreateItemByFields(formid, fields); } finally { if (securityDisabler != null) { securityDisabler.Dispose(); } } }
public void Generate() { LoadSettings(); if (PushMenuSettings != null) { var list = GetSiteSettingsList(PushMenuSettings); if (list == null) { return; } using (var sd = new SecurityDisabler()) { foreach (var siteSettingItem in list) { Generate(siteSettingItem); } } } }
private Database[] GetTargets(Database db, string[] givenTargets) { Database[] array; using (SecurityDisabler securityDisabler = new SecurityDisabler()) { Item item1 = db.Items["/sitecore/system/publishing targets"]; if (item1 == null) { return new Database[0]; } else { ArrayList arrayLists = new ArrayList(); foreach (Item child in item1.Children) { string str = child["Target database"]; if (str.Length <= 0) { continue; } Database database = Factory.GetDatabase(str, false); if (database == null) { Log.Warn(string.Concat("Custom Workflow Unknown database in PublishAction: ", str), this); } else { if (givenTargets.Contains(str)) { arrayLists.Add(database); } } } array = arrayLists.ToArray(typeof(Database)) as Database[]; } } return array; }
private void DoScan(WriteScanningOptions options) { var language = options.TargetLanguageCode; var masterDb = Sitecore.Configuration.Factory.GetDatabase("master"); using (var disabler = new SecurityDisabler()) { ScanItem(options.RootPath); } void ScanItem(string path) { var rootContent = masterDb.GetItem(path, Language.Parse(options.SitecoreLanguageCode)); var enContent = masterDb.GetItem(path); if (enContent == null || rootContent == null) { CustomConsoleLogger.Log($"{path} must have a language version of {language}", ConsoleColor.Red); return; } if (!options.ShouldWrite(rootContent)) { goto NEXT; } rootContent.Fields.ReadAll(); enContent.Fields.ReadAll(); var includedFields = enContent.Fields.Where(f => options.ScanFieldTypes.Contains(f.Type) && !string.IsNullOrEmpty(f.Type) && !f.Name.StartsWith("__")).ToArray(); if (includedFields.Any()) { var fieldCount = 0; rootContent.Editing.BeginEdit(); foreach (var enField in includedFields) { var term = enField.Value; var translation = _termsRepository.GetTranslation(term, language); if (translation != null) { var matchingField = rootContent.Fields.FirstOrDefault(f => f.ID == enField.ID); if (matchingField != null) { fieldCount++; matchingField.Value = translation; } } } rootContent.Editing.EndEdit(); if (fieldCount > 0) { CustomConsoleLogger.Log( $"Updated content {rootContent.Paths.FullPath} found {fieldCount} fields", ConsoleColor.DarkMagenta); } } NEXT: foreach (Item child in rootContent.Children) { ScanItem(child.Paths.FullPath); } } Console.Write("Done"); }