Question:

Other language field values not published when published with code

Grayson: 2 weeks ago

When I create a new item in the Thai version & publish it by code, the item gets created in the web database, but the fields are empty. There is no error & also no issue when publishing the English version.
During debug, the sourceItem is from Thai version & I can also see the field values.
What am i doing wrong here.
Using Sitecore 8.2

public static PublishResult PublishItem(Item sourceItem, string targetDatabaseName, 
                                         bool publishSubItems)
{
   PublishResult publishResult = null;

   if (sourceItem != null)
   {
      Database targetDatabase = GetDatabase(targetDatabaseName);

      if (targetDatabase != null)
      {
        PublishOptions publishOptions = new PublishOptions(Databases.masterDb, 
targetDatabase, PublishMode.SingleItem, sourceItem.Language, System.DateTime.Now);

        if (publishOptions != null)
        {
           publishOptions.UserName = Sitecore.Context.User.Name;
           MyPublisher publisher = new MyPublisher(publishOptions);

           if (publisher != null)
           {
             publisher.Options.RootItem = sourceItem;
             publisher.Options.Deep = publishSubItems;

             using (new SecurityDisabler())
             {
               using (new EventDisabler())
               {
                  publishResult = publisher.PublishWithResult();                                    
               }
             }

             sourceItem.Publishing.ClearPublishingCache();
         }
      }
     }
   }

   return publishResult;
}

Mypublisher.cs

public class MyPublisher : Publisher
    {
        public MyPublisher(PublishOptions options) : base(options)
        {
        }

        public MyPublisher(PublishOptions options, IEnumerable<Language> languages) : base(options, languages)
        {
        }

        public override PublishResult PublishWithResult()
        {
            object publishLock = GetPublishLock();
            lock (publishLock)
            {
                try
                {
                    using (new SecurityDisabler())
                    {
                        AssertState();
                        PublishResult result = PerformPublishWithResult();
                        UpdateLastPublish();
                        return result;
                    }
                }
                catch (Exception ex)
                {
                    NotifyFailure(ex);
                    throw;
                }
            }
        }
    }

Also, strangely there is no user name mentioned after publish. If I publish the English item, I can see the logged in username (sitecore\admin).

enter image description here

Answer:
Aurora: 2 weeks ago

The solution suggested by @Gobinath Saminathan worked for me, which is to remove EventDisabler()

Now my code is

using (new SecurityDisabler())
{
  publishResult = publisher.PublishWithResult(); 
}

and it works