PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/CompositeC1/Composite.Workflows/C1Console/Scheduling/DataUnpublishSchedulerWorkflow.cs

#
C# | 104 lines | 65 code | 21 blank | 18 comment | 4 complexity | 280b49ec6282bc0828068ff4c14ddc00 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /*
  2. * The contents of this web application are subject to the Mozilla Public License Version
  3. * 1.1 (the "License"); you may not use this web application except in compliance with
  4. * the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/.
  5. *
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. * for the specific language governing rights and limitations under the License.
  9. *
  10. * The Original Code is owned by and the Initial Developer of the Original Code is
  11. * Composite A/S (Danish business reg.no. 21744409). All Rights Reserved
  12. *
  13. * Section 11 of the License is EXPRESSLY amended to include a provision stating
  14. * that any dispute, including but not limited to disputes related to the enforcement
  15. * of the License, to which Composite A/S as owner of the Original Code, as Initial
  16. * Developer or in any other role, becomes a part to shall be governed by Danish law
  17. * and be initiated before the Copenhagen City Court ("K�benhavns Byret")
  18. */
  19. using System.ComponentModel;
  20. using System.Globalization;
  21. using Composite.C1Console.Security;
  22. using Composite.Core;
  23. using Composite.Core.Types;
  24. using Composite.Data;
  25. using Composite.Data.ProcessControlled;
  26. using Composite.Data.ProcessControlled.ProcessControllers.GenericPublishProcessController;
  27. using Composite.Data.PublishScheduling;
  28. using Composite.Data.Transactions;
  29. namespace Composite.C1Console.Scheduling
  30. {
  31. public sealed class DataUnpublishSchedulerWorkflow : BaseSchedulerWorkflow
  32. {
  33. private static readonly string LogTitle = typeof(DataUnpublishSchedulerWorkflow).Name;
  34. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  35. public string DataType { get; set; }
  36. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  37. public string DataId { get; set; }
  38. protected override void Execute()
  39. {
  40. var type = TypeManager.GetType(DataType);
  41. using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName)))
  42. {
  43. DataEntityToken dataEntityToken;
  44. using (var transaction = TransactionsFacade.CreateNewScope())
  45. {
  46. var unpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(type, DataId, LocaleName);
  47. Verify.IsNotNull(unpublishSchedule, "Missing an unpublish data schedule record");
  48. DataFacade.Delete(unpublishSchedule);
  49. var deletePublished = false;
  50. var data = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId);
  51. Verify.IsNotNull(data, "The data with the id {0} does not exist", DataId);
  52. dataEntityToken = data.GetDataEntityToken();
  53. var transitions = ProcessControllerFacade.GetValidTransitions(data).Keys;
  54. if (transitions.Contains(GenericPublishProcessController.Draft))
  55. {
  56. data.PublicationStatus = GenericPublishProcessController.Draft;
  57. DataFacade.Update(data);
  58. deletePublished = true;
  59. }
  60. else
  61. {
  62. Log.LogWarning(LogTitle, "Scheduled unpublishing of data with label '{0}' could not be done because the data is not in a unpublisheble state", data.GetLabel());
  63. }
  64. if (deletePublished)
  65. {
  66. using (new DataScope(DataScopeIdentifier.Public))
  67. {
  68. var deletedData = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId);
  69. if (deletedData != null)
  70. {
  71. DataFacade.Delete(deletedData, CascadeDeleteType.Disable);
  72. Log.LogVerbose(LogTitle, "Scheduled unpublishing of data with label '{0}' is complete", deletedData.GetLabel());
  73. }
  74. }
  75. }
  76. transaction.Complete();
  77. }
  78. EntityTokenCacheFacade.ClearCache(dataEntityToken);
  79. PublishControlledHelper.ReloadDataElementInConsole(dataEntityToken);
  80. }
  81. }
  82. }
  83. }