Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriyLeman committed Aug 4, 2018
1 parent 945fb60 commit 40a089a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ protected override void DoUpdate(IProviderUpdateContext context, SitecoreIndexab
}

Item[] versions;
using (new SitecoreCachesDisabler())
// Sitecore.Support.155383. Switched from SitecoreCachesDisabler() to WriteCachesDisabler()
using (new WriteCachesDisabler())
{
versions = !latestVersion.IsFallback
? latestVersion.Versions.GetVersions(false)
Expand Down Expand Up @@ -126,34 +127,40 @@ internal SitecoreIndexableItem PrepareIndexableVersion(Item item, IProviderUpdat
return indexable;
}

// Sitecore.Support.127177. LanguageFallback context was added to take the index language fallback configuration into account.
protected override SitecoreIndexableItem GetIndexableAndCheckDeletes(IIndexableUniqueId indexableUniqueId)
{
ItemUri itemUri = indexableUniqueId as SitecoreItemUniqueId;

using (new SecurityDisabler())
using (new LanguageFallbackItemSwitcher(index.EnableItemLanguageFallback))
{
Item item;
using (new WriteCachesDisabler())
{
item = GetItem(itemUri);
}
ItemUri itemUri = indexableUniqueId as SitecoreItemUniqueId;

if (item != null)
using (new SecurityDisabler())
{
var latestItemUri = new ItemUri(itemUri.ItemID, itemUri.Language, Sitecore.Data.Version.Latest, itemUri.DatabaseName);
var latestItem = GetItem(latestItemUri);

Sitecore.Data.Version[] versions;
Item item;
using (new WriteCachesDisabler())
{
versions = latestItem.Versions.GetVersionNumbers() ?? new Sitecore.Data.Version[0];
item = GetItem(itemUri);
}

if (itemUri.Version != Sitecore.Data.Version.Latest && versions.All(v => v.Number != itemUri.Version.Number))
item = null;
}
if (item != null)
{
var latestItemUri = new ItemUri(itemUri.ItemID, itemUri.Language, Sitecore.Data.Version.Latest,
itemUri.DatabaseName);
var latestItem = GetItem(latestItemUri);

return item;
Sitecore.Data.Version[] versions;
using (new WriteCachesDisabler())
{
versions = latestItem.Versions.GetVersionNumbers() ?? new Sitecore.Data.Version[0];
}

if (itemUri.Version != Sitecore.Data.Version.Latest &&
versions.All(v => v.Number != itemUri.Version.Number))
item = null;
}

return item;
}
}
}

Expand Down Expand Up @@ -302,15 +309,78 @@ private void UpdatePreviousVersion(Item item, IProviderUpdateContext context)
}
}

#region Fix For 96740
protected override void UpdateDependents(IProviderUpdateContext context, SitecoreIndexableItem indexable)
{
foreach (var uniqueId in GetIndexingDependencies(indexable).Where(i => !this.IsExcludedFromIndex(i, true)))
{
if (!this.CircularReferencesIndexingGuard.IsInProcessedList(uniqueId, this, context))
this.Update(context, uniqueId);
}
}
#endregion

public override void Delete(IProviderUpdateContext context, IIndexableUniqueId indexableUniqueId, IndexingOptions indexingOptions = IndexingOptions.Default)
{
base.Delete(context, indexableUniqueId, indexingOptions);
//base.Delete(context, indexableUniqueId, indexingOptions);
// Extract from Base and patch below to fix 127177

if (!ShouldStartIndexing(indexingOptions))
return;

context.Index.Locator.GetInstance<IEvent>().RaiseEvent("indexing:deleteitem", this.index.Name, indexableUniqueId);
this.Operations.Delete(indexableUniqueId, context);

var deleteDependencies = this.GetIndexablesToUpdateOnDelete(indexableUniqueId);
var deleteDependencyIndexables = deleteDependencies.Select(this.GetIndexable).Where(i => i != null);

IndexEntryOperationContext operationContext = new IndexEntryOperationContext
{
NeedUpdateAllLanguages = false,
NeedUpdateAllVersions = false,
NeedUpdateChildren = false
};

// Sitecore.Support.127177. Takes into account LanguageFallback configuration of the index.
if (context.Index.EnableItemLanguageFallback)
{
this.DoUpdateFallbackField(context, indexableUniqueId);
foreach (var deleteDependencyIndexable in deleteDependencyIndexables)
{
this.DoUpdate(context, deleteDependencyIndexable, operationContext);
}

this.DeleteFallbackItem(indexableUniqueId, context);
}
}

private void DoUpdateFallbackField(IProviderUpdateContext context, IIndexableUniqueId indexableUniqueId)
{
var indexableItem = this.GetIndexable(indexableUniqueId) as SitecoreIndexableItem;
if (indexableItem == null)
{
return;
}
indexableItem.Item.Fields.ReadAll();
var fields = indexableItem.Item.Fields;
if (fields.Any(e => e.SharedLanguageFallbackEnabled))
{
var fallbackItems = this.GetDependentLanguages(indexableItem.Item.Language, indexableItem.Item.Database, indexableItem.Item.ID)
.SelectMany(
language =>
{
var item1 = indexableItem.Item.Database.GetItem(indexableItem.Item.ID, language);
return item1 != null ? item1.Versions.GetVersions() : new Item[0];
});

foreach (var fallbackItem in fallbackItems)
{
var valueToConsider = new SitecoreItemUniqueId(fallbackItem.Uri);
this.Update(context, valueToConsider);
}
}
}

/// <summary>
/// When perform a version deletion operation,
/// Make sure that all the fallback language version deleted if it is the last item of main language.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sitecore.Support</RootNamespace>
<AssemblyName>Sitecore.Support.127177.155383</AssemblyName>
<AssemblyName>Sitecore.Support.96740.127177.155383</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
Expand Down Expand Up @@ -64,9 +64,6 @@
<Compile Include="ContentSearch\SitecoreItemCrawler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\zzz\Sitecore.Support.127177.155383.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="web.config" />
Expand Down

0 comments on commit 40a089a

Please sign in to comment.