Tuesday, April 26, 2016

ES6 reduce function cheatsheet

[3,6,7,9,10].reduce((a,b,i,all) => {console.log(a + " " + b + " " + i + " " + all);return a+b;})

3 6 1 3,6,7,9,10
9 7 2 3,6,7,9,10
16 9 3 3,6,7,9,10
25 10 4 3,6,7,9,10
> 35

Wednesday, April 20, 2016

Cleaning up the publication target in proper way

We have some components marked as published to publication targets, but the publication target does not exist anymore.

This causes problem when you want to delete the pages that are published to this target (maybe because of data migration, they still think they are living on a remote server) :)

We cannot delete them, as they marked as published!

Possible solution:
First I played a bit with  the core services.

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" maxReceivedMessageSize="10485760"">
          <readerQuotas maxStringContentLength="10485760" maxArrayLength="10485760"/>
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="wsHttp" transactionFlow="true" maxReceivedMessageSize="10485760">
          <readerQuotas maxStringContentLength="10485760" maxArrayLength="10485760"/>
          <security mode="Message">
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint name="Basic_CoreServiceDev"
          address="http://yourtridionserver/webservices/CoreService2013.svc/basicHttp"
          binding="basicHttpBinding"
          bindingConfiguration="basicHttp"
          contract="Tridion.ContentManager.CoreService.Client.ICoreService"/>
      <endpoint name="CoreServiceDev"
          address="http://yourtridionserver/webservices/CoreService2013.svc/wsHttp"
          binding="wsHttpBinding"
          bindingConfiguration="wsHttp"
          contract="Tridion.ContentManager.CoreService.Client.ISessionAwareCoreService"/>
    </client>
  </system.serviceModel>

Then I used this code to clean:
using (var client = new SessionAwareCoreServiceClient("CoreServiceDev"))
           {
               if (client.ClientCredentials != null)
                   client.ClientCredentials.Windows.ClientCredential = 
                       new System.Net.NetworkCredential(
                           ConfigurationManager.AppSettings["Username"],
                           ConfigurationManager.AppSettings["Password"]);
 
               client.SetSessionTransactionTimeout(60 * 30); //30 minutes
               Console.WriteLine("Please enter the tcm-id of the publication");
               var tcmid = Console.ReadLine();
               try
               {
 
                   Console.WriteLine("Started");
                   client.DecommissionPublicationTarget(tcmid);
                   Console.WriteLine("Completed");
                   client.SetSessionTransactionTimeout(60);
               }
               catch (Exception ex)
               {
                   Console.ForegroundColor = ConsoleColor.Red;
                   Console.WriteLine("Error: " + ex.Message);
                   Console.ResetColor();
               }
           }

The result was still a time-out!

At the end, running the powershell on the server was a better option: (tcm id is the publication target's tcm-id):
PS C:\Windows\system32> Import-Module Tridion.ContentManager.Automation
PS C:\Windows\system32> Clear-TcmPublicationTarget tcm:0-2-12345