Beispiel #1
0
        protected virtual void AddStatisticsFieldsWhenMissing(BulkLoadItem bulkItem, string language, int versionNumber = 1)
        {
            var user = global::Sitecore.Context.User.Name;

            if (bulkItem.GetField(FieldIDs.Created.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.Created.Guid, language, versionNumber, DateUtil.IsoNow, name: "__Created");
            }

            if (bulkItem.GetField(FieldIDs.CreatedBy.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.CreatedBy.Guid, language, versionNumber, user, name: "__Created by");
            }

            if (bulkItem.LoadAction == BulkLoadAction.Update || bulkItem.LoadAction == BulkLoadAction.UpdateExistingItem)
            {
                if (bulkItem.GetField(FieldIDs.UpdatedBy.Guid, language, versionNumber) == null)
                {
                    bulkItem.AddVersionedField(FieldIDs.UpdatedBy.Guid, language, versionNumber, user, name: "__Updated");
                }

                if (bulkItem.GetField(FieldIDs.Updated.Guid, language, versionNumber) == null)
                {
                    bulkItem.AddVersionedField(FieldIDs.Updated.Guid, language, versionNumber, DateUtil.IsoNowWithTicks, name: "__Updated by");
                }
            }
        }
        protected virtual void AddStatisticsFieldsWhenMissing(BulkLoadItem bulkItem, string language,
                                                              int versionNumber = 1)
        {
            var user = Sitecore.Context.User.Name;

            // Make sure revision is updated when item is created or updated so that smart publish works.
            // Unicorn doesn't track revisions, so we need to generate one ourselves.
            if (bulkItem.GetField(FieldIDs.Revision.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.Revision.Guid, language, versionNumber, Guid.NewGuid().ToString("D"), name: "__Revision",
                                           postProcessor: x => x.DependsOnCreate = x.DependsOnUpdate = true);
            }

            if (bulkItem.GetField(FieldIDs.Created.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.Created.Guid, language, versionNumber, DateUtil.IsoNow, name: "__Created",
                                           postProcessor: x => x.DependsOnCreate = true);
            }

            if (bulkItem.GetField(FieldIDs.CreatedBy.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.CreatedBy.Guid, language, versionNumber, user, name: "__Created by",
                                           postProcessor: x => x.DependsOnCreate = true);
            }

            if (bulkItem.GetField(FieldIDs.Updated.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.Updated.Guid, language, versionNumber, DateUtil.IsoNow, name: "__Updated",
                                           postProcessor: x => x.DependsOnCreate = x.DependsOnUpdate = true);
            }

            if (bulkItem.GetField(FieldIDs.UpdatedBy.Guid, language, versionNumber) == null)
            {
                bulkItem.AddVersionedField(FieldIDs.UpdatedBy.Guid, language, versionNumber, user, name: "__Updated by",
                                           postProcessor: x => x.DependsOnCreate = x.DependsOnUpdate = true);
            }
        }
        protected virtual void AddSyncField(BulkLoadContext context, BulkLoadItem bulkItem, IItemFieldValue itemField,
                                            string language = null, int versionNumber = 1)
        {
            var fieldId    = itemField.FieldId;
            var fieldValue = itemField.Value;
            var fieldName  = itemField.NameHint;
            var isBlob     = itemField.BlobId.HasValue;

            Func <Stream> blob = null;

            if (isBlob)
            {
                byte[] blobBytes;
                try
                {
                    blobBytes = Convert.FromBase64String(fieldValue);
                }
                catch (Exception ex)
                {
                    blobBytes = new byte[] { };
                    context.Log.Error(
                        $"Unable to read blob from field '{fieldId}' in item with id '{bulkItem.Id}', " +
                        $"item path '{bulkItem.ParentId}' and source info '{bulkItem.SourceInfo}', defaulting to empty value.",
                        ex);
                }
                blob = () => new MemoryStream(blobBytes);

                // Field value needs to be set to the blob id.
                fieldValue = itemField.BlobId.Value.ToString("B").ToUpper();
            }

            if (language == null)
            {
                bulkItem.AddSharedField(fieldId, fieldValue, blob, isBlob, fieldName);
            }
            else
            {
                bulkItem.AddVersionedField(fieldId, language, versionNumber, fieldValue, blob, isBlob, fieldName);
            }
        }