-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCategory.cs
812 lines (713 loc) · 31.1 KB
/
Category.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
// <copyright file="Category.cs" company="Engage Software">
// Engage: Publish
// Copyright (c) 2004-2013
// by Engage Software ( http://www.engagesoftware.com )
// </copyright>
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace Engage.Dnn.Publish
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Xml.Serialization;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Controllers;
using Engage.Dnn.Publish.Data;
using Engage.Dnn.Publish.Util;
using Localize = DotNetNuke.Services.Localization.Localization;
/// <summary>
/// A grouping of <see cref="Item"/>s (i.e. Articles and other Categories)
/// </summary>
[XmlRoot(ElementName = "category", IsNullable = false)]
public class Category : Item
{
// [XmlAttribute(AttributeName="noNamespaceSchemaLocation", Namespace="http://www.w3.org/2001/XMLSchema-instance")]
// public string noNamespaceSchemaLocation = "Content.Publish.xsd";
private int childDisplayTabId = -1;
private string childDisplayTabName = string.Empty;
private int sortOrder = 5;
public Category()
{
// this type is always a Category
this.ItemTypeId = ItemType.Category.GetId();
}
[XmlElement(Order = 40)]
public int ChildDisplayTabId
{
get { return this.childDisplayTabId; }
set { this.childDisplayTabId = value; }
}
[XmlElement(Order = 41)]
public string ChildDisplayTabName
{
get
{
if (this.childDisplayTabName.Length == 0)
{
using (IDataReader dr = DataProvider.Instance().GetPublishTabName(this.childDisplayTabId, this.PortalId))
{
if (dr.Read())
{
this.childDisplayTabName = dr["TabName"].ToString();
}
}
}
return this.childDisplayTabName;
}
set
{
this.childDisplayTabName = value;
}
}
public override string EmailApprovalBody
{
get
{
return Localize.GetString(
"EMAIL_APPROVAL_BODY", "~" + Utility.DesktopModuleFolderName + "categorycontrols/App_LocalResources/categoryedit");
}
}
public override string EmailApprovalSubject
{
get
{
return Localize.GetString(
"EMAIL_STATUSCHANGE_SUBJECT", "~" + Utility.DesktopModuleFolderName + "categorycontrols/App_LocalResources/categoryedit");
}
}
public override string EmailStatusChangeBody
{
get
{
return Localize.GetString(
"EMAIL_STATUSCHANGE_BODY", "~" + Utility.DesktopModuleFolderName + "categorycontrols/App_LocalResources/categoryedit");
}
}
public override string EmailStatusChangeSubject
{
get
{
return Localize.GetString(
"EMAIL_APPROVAL_SUBJECT", "~" + Utility.DesktopModuleFolderName + "categorycontrols/App_LocalResources/categoryedit");
}
}
[XmlElement(Order = 39)]
public int SortOrder
{
get { return this.sortOrder; }
set { this.sortOrder = value; }
}
public static void AddCategoryVersion(int itemVersionId, int itemId, int sortOrder, int childDisplayTabId)
{
DataProvider.Instance().AddCategoryVersion(itemVersionId, itemId, sortOrder, childDisplayTabId);
}
public static void AddCategoryVersion(IDbTransaction trans, int itemVersionId, int itemId, int sortOrder, int childDisplayTabId)
{
DataProvider.Instance().AddCategoryVersion(trans, itemVersionId, itemId, sortOrder, childDisplayTabId);
}
/// <summary>
/// Creates an empty Category object
/// </summary>
/// <param name="portalId">The Portal ID of the portal this category belongs to.</param>
/// <returns>A <see cref="Category" /> with the assigned values.</returns>
public static Category Create(int portalId)
{
var i = new Category
{
PortalId = portalId
};
return i;
}
/// <summary>
/// Creates a Category object that you can continue to modify or save back into the database.,
/// </summary>
/// <param name="name">Name of the Category to be created.</param>
/// <param name="description">The description/abstract of the category to be created.</param>
/// <param name="authorUserId">The ID of the author of this category.</param>
/// <param name="moduleId">The moduleid for where this category will most likely be displayed.</param>
/// <param name="portalId">The Portal ID of the portal this category belongs to.</param>
/// <param name="displayTabId">The Tab ID of the page this Category should be displayed on.</param>
/// <returns>A <see cref="Category" /> with the assigned values.</returns>
public static Category Create(string name, string description, int authorUserId, int moduleId, int portalId, int displayTabId)
{
var c = new Category
{
Name = name,
Description = description,
AuthorUserId = authorUserId
};
// default to the top level item type of category
var irel = new ItemRelationship
{
RelationshipTypeId = RelationshipType.ItemToParentCategory.GetId(),
ParentItemId = TopLevelCategoryItemType.Category.GetId()
};
c.Relationships.Add(irel);
c.StartDate = c.LastUpdated = c.CreatedDate = DateTime.Now.ToString(CultureInfo.InvariantCulture);
c.PortalId = portalId;
c.ModuleId = moduleId;
c.ApprovalStatusId = ApprovalStatus.Approved.GetId();
c.NewWindow = false;
return c;
}
/// <summary>
/// Creates a Category object that you can continue to modify or save back into the database. You should use the Category.Create method instead of this.
/// </summary>
/// <param name="name">Name of the Category to be created.</param>
/// <param name="description">The description/abstract of the category to be created.</param>
/// <param name="authorUserId">The ID of the author of this category.</param>
/// <param name="moduleId">The moduleid for where this category will most likely be displayed.</param>
/// <param name="portalId">The Portal ID of the portal this category belongs to.</param>
/// <param name="displayTabId">The Tab ID of the page this Category should be displayed on.</param>
/// <returns>A <see cref="Category" /> with the assigned values.</returns>
[Obsolete("This method should not be used, please use Category.Create. Example: Create(string name, string description, int authorUserId, int moduleId, int portalId, int displayTabId).", false)]
public static Category CreateCategory(string name, string description, int authorUserId, int moduleId, int portalId, int displayTabId)
{
return Create(name, description, authorUserId, moduleId, portalId, displayTabId);
}
public static DataTable GetAllChildCategories(int parentItemId, int portalId)
{
// return DataProvider.Instance().GetAllChildCategories(parentItemId, portalId);
string cacheKey = Utility.CacheKeyPublishAllChildCategories + parentItemId.ToString(CultureInfo.InvariantCulture);
DataTable dt;
if (ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
dt = (DataTable)o;
}
else
{
dt = DataProvider.Instance().GetAllChildCategories(parentItemId, portalId);
}
if (dt != null)
{
DataCache.SetCache(cacheKey, dt, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
dt = DataProvider.Instance().GetAllChildCategories(parentItemId, portalId);
}
return dt;
}
public static DataTable GetCategories(int portalId)
{
return DataProvider.Instance().GetCategories(portalId);
}
public static DataTable GetCategoriesByModuleId(int moduleId)
{
return DataProvider.Instance().GetCategoriesByModuleId(moduleId);
}
public static DataTable GetCategoriesByPortalId(int portalId)
{
return DataProvider.Instance().GetCategoriesByPortalId(portalId);
}
public static DataTable GetCategoriesHierarchy(int portalId)
{
return DataProvider.Instance().GetCategoriesHierarchy(portalId);
}
public static Category GetCategory(string categoryName, int portalId)
{
int itemId = DataProvider.Instance().GetCategoryItemId(categoryName, portalId);
Category c = GetCategory(itemId, portalId);
return c;
}
public static Category GetCategory(int itemId)
{
return GetCategory(itemId, false, false);
}
public static Category GetCategory(int itemId, bool loadRelationships, bool loadTags)
{
return GetCategory(itemId, loadRelationships, loadTags, false);
}
public static Category GetCategory(int itemId, bool loadRelationships, bool loadTags, bool loadItemVersionSettings)
{
// cache?
var c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
if (c != null)
{
c.CorrectDates();
if (loadRelationships)
{
c.LoadRelationships();
}
if (loadTags && ModuleBase.AllowTagsForPortal(c.PortalId))
{
c.LoadTags();
}
if (loadItemVersionSettings)
{
c.LoadItemVersionSettings();
}
}
return c;
}
public static Category GetCategory(int itemId, int portalId, bool loadRelationships, bool loadTags, bool loadItemVersionSettings)
{
return GetCategory(itemId, portalId, loadRelationships, loadTags, loadItemVersionSettings, false);
}
public static Category GetCategory(int itemId, int portalId, bool loadRelationships, bool loadTags, bool loadItemVersionSettings, bool ignoreCache)
{
// cache?
// var c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
// if (c != null)
// {
// c.CorrectDates();
// if (loadRelationships)
// {
// c.LoadRelationships();
// }
// if (loadTags && ModuleBase.AllowTagsForPortal(c.PortalId))
// {
// c.LoadTags();
// }
// if (loadItemVersionSettings)
// {
// c.LoadItemVersionSettings();
// }
// }
string cacheKey = Utility.CacheKeyPublishCategory + itemId.ToString(CultureInfo.InvariantCulture) + "loadRelationships" +
loadRelationships + "loadTags" + loadTags + "loadItemVersionSettings" + loadItemVersionSettings;
Category c;
if (!ignoreCache && ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
c = (Category)o;
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
if (c != null)
{
c.CorrectDates();
if (loadRelationships)
{
c.LoadRelationships();
}
if (loadTags && ModuleBase.AllowTagsForPortal(c.PortalId))
{
c.LoadTags();
}
if (loadItemVersionSettings)
{
c.LoadItemVersionSettings();
}
DataCache.SetCache(cacheKey, c, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
if (c != null)
{
c.CorrectDates();
if (loadRelationships)
{
c.LoadRelationships();
}
if (loadTags && ModuleBase.AllowTagsForPortal(c.PortalId))
{
c.LoadTags();
}
if (loadItemVersionSettings)
{
c.LoadItemVersionSettings();
}
}
}
return c;
}
public static Category GetCategory(int itemId, int portalId)
{
return GetCategory(itemId, portalId, false);
}
public static Category GetCategory(int itemId, int portalId, bool ignoreCache)
{
string cacheKey = Utility.CacheKeyPublishCategory + itemId.ToString(CultureInfo.InvariantCulture);
Category c;
if (!ignoreCache && ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
c = (Category)o;
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
if (c != null)
{
c.CorrectDates();
DataCache.SetCache(cacheKey, c, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategory(itemId), typeof(Category));
if (c != null)
{
c.CorrectDates();
}
}
return c;
}
[SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Justification = "Not a reusable library")]
public static List<Article> GetCategoryArticles(int itemId, int portalId)
{
DataTable children =
GetAllChildren(
ItemType.Article.GetId(),
itemId,
RelationshipType.ItemToParentCategory.GetId(),
RelationshipType.ItemToRelatedCategory.GetId(),
portalId).Tables[0];
var articles = new List<Article>(children.Rows.Count);
foreach (DataRow row in children.Rows)
{
articles.Add(Article.GetArticle((int)row["ItemId"], portalId));
}
return articles;
}
public static IDataReader GetCategoryListing(int parentItemId, int portalId)
{
return DataProvider.Instance().GetCategoryListing(parentItemId, portalId);
}
public static Category GetCategoryVersion(int itemVersionId, int portalId)
{
return GetCategoryVersion(itemVersionId, portalId, false);
}
public static Category GetCategoryVersion(int itemVersionId, int portalId, bool ignoreCache)
{
string cacheKey = Utility.CacheKeyPublishCategoryVersion + itemVersionId.ToString(CultureInfo.InvariantCulture);
Category c;
if (!ignoreCache && ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
c = (Category)o;
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategoryVersion(itemVersionId, portalId), typeof(Category));
if (c != null)
{
c.CorrectDates();
}
}
if (c != null)
{
DataCache.SetCache(cacheKey, c, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
c = (Category)CBO.FillObject(DataProvider.Instance().GetCategoryVersion(itemVersionId, portalId), typeof(Category));
if (c != null)
{
c.CorrectDates();
}
}
return c;
}
public static DataTable GetChildCategories(int parentItemId, int portalId)
{
// return DataProvider.Instance().GetChildCategories(parentItemId, portalId);
string cacheKey = Utility.CacheKeyPublishChildCategories + parentItemId.ToString(CultureInfo.InvariantCulture);
DataTable dt;
if (ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
dt = (DataTable)o;
}
else
{
dt = DataProvider.Instance().GetChildCategories(parentItemId, portalId);
}
if (dt != null)
{
DataCache.SetCache(cacheKey, dt, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
dt = DataProvider.Instance().GetChildCategories(parentItemId, portalId);
}
return dt;
}
public static DataTable GetChildCategories(int parentItemId, int portalId, int itemTypeId)
{
// return DataProvider.Instance().GetChildCategories(parentItemId, portalId, itemTypeId);
string cacheKey = Utility.CacheKeyPublishChildCategoriesItemType + parentItemId.ToString(CultureInfo.InvariantCulture) + "_" +
itemTypeId.ToString(CultureInfo.InvariantCulture);
DataTable dt;
if (ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
dt = (DataTable)o;
}
else
{
dt = DataProvider.Instance().GetChildCategories(parentItemId, portalId, itemTypeId);
}
if (dt != null)
{
DataCache.SetCache(cacheKey, dt, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
dt = DataProvider.Instance().GetChildCategories(parentItemId, portalId, itemTypeId);
}
return dt;
}
public static DataTable GetChildrenInCategoryPaging(
int categoryId,
int childTypeId,
int maxItems,
int portalId,
bool customSort,
bool customSortDirection,
string sortOrder,
int index,
int pageSize)
{
return DataProvider.Instance().GetChildrenInCategoryPaging(
categoryId, childTypeId, maxItems, portalId, customSort, customSortDirection, sortOrder, index, pageSize);
}
public static int GetOldCategoryId(int itemId)
{
return DataProvider.Instance().GetOldCategoryId(itemId);
}
public static int GetParentCategory(int childItemId, int portalId)
{
int parentId;
string cacheKey = Utility.CacheKeyPublishItemParentCategoryId + childItemId.ToString(CultureInfo.InvariantCulture); // +"PageId";
if (ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
parentId = o != null ? Convert.ToInt32(o.ToString()) : DataProvider.Instance().GetParentCategory(childItemId, portalId);
if (parentId != -1)
{
DataCache.SetCache(cacheKey, parentId, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
parentId = DataProvider.Instance().GetParentCategory(childItemId, portalId);
}
return parentId;
}
/// <summary>
/// Returns a dataset of the top level categories available for a specific portal
/// </summary>
/// <param name="portalId">The Portal ID that we want to return data for.</param>
/// <returns>A <see cref="DataSet" /> with the categories available.</returns>
public static DataSet GetTopLevelCategories(int portalId)
{
string cacheKey = Utility.CacheKeyPublishTopLevelCategories + portalId.ToString(CultureInfo.InvariantCulture);
DataSet ds;
if (ModuleBase.UseCachePortal(portalId))
{
object o = DataCache.GetCache(cacheKey);
if (o != null)
{
ds = (DataSet)o;
}
else
{
ds = DataProvider.Instance().GetTopLevelCategories(portalId);
}
if (ds != null)
{
DataCache.SetCache(cacheKey, ds, DateTime.Now.AddMinutes(ModuleBase.CacheTimePortal(portalId)));
Utility.AddCacheKey(cacheKey, portalId);
}
}
else
{
ds = DataProvider.Instance().GetTopLevelCategories(portalId);
}
return ds;
}
/// <summary>
/// Updates the <see cref="Item.DisplayTabId"/> and <see cref="ChildDisplayTabId"/> settings of all children of this <see cref="Category"/> (and their children's children, etc.)
/// </summary>
/// <param name="revisingUser">The revising user.</param>
/// <returns>The number of affected <see cref="Item"/>s</returns>
public int CascadeChildDisplayTab(int revisingUser)
{
int count = 0;
foreach (DataRow itemRow in GetAllChildren(this.ItemId, RelationshipType.ItemToParentCategory.GetId(), this.PortalId).Tables[0].Rows)
{
Item childItem;
var itemId = (int)itemRow["itemId"];
if (GetItemTypeId(itemId) == ItemType.Article.GetId())
{
childItem = Article.GetArticle(itemId, this.PortalId, true, true, true);
}
else
{
childItem = GetCategory(itemId, true, true);
}
childItem.DisplayTabId = this.ChildDisplayTabId;
var childCategory = childItem as Category;
if (childCategory != null)
{
childCategory.ChildDisplayTabId = this.ChildDisplayTabId;
}
Setting displayOnCurrentPageSetting = Setting.ArticleSettingCurrentDisplay;
displayOnCurrentPageSetting.PropertyValue = false.ToString(CultureInfo.InvariantCulture);
childItem.VersionSettings.Add(new ItemVersionSetting(displayOnCurrentPageSetting));
childItem.Save(revisingUser);
count++;
}
return count;
}
/// <summary>
/// This method is invoked by the Import mechanism and has to take this instance of a Category and resolve
/// all the id's using the names supplied in the export. hk
/// </summary>
public override void Import(int currentModuleId, int portalId)
{
// The very first thing is that PortalID needs to be changed to the current portal where content is being
// imported. Several methods resolving Id's is expecting the correct PortalId (current). hk
this.PortalId = portalId;
this.ResolveIds(currentModuleId);
}
public override void Save(int authorId)
{
IDbConnection newConnection = DataProvider.Instance().GetConnection();
IDbTransaction trans = newConnection.BeginTransaction();
// int relationTypeId = RelationshipType.ItemToParentCategory.GetId();
// create a transaction
// get a connection
try
{
this.SaveInfo(trans, authorId);
UpdateItem(trans, this.ItemId, this.ModuleId);
// TODO: only do the following if admin
this.UpdateApprovalStatus(trans);
// update category version now
AddCategoryVersion(trans, this.ItemVersionId, this.ItemId, this.SortOrder, this.ChildDisplayTabId);
this.SaveRelationships(trans);
trans.Commit();
}
catch
{
trans.Rollback();
// rollback and throw an error
this.ItemVersionId = this.OriginalItemVersionId;
throw;
}
finally
{
// clean up connection stuff
newConnection.Close();
}
// Save Tags
this.SaveTags();
this.SaveItemVersionSettings();
Utility.ClearPublishCache(this.PortalId);
}
public override void UpdateApprovalStatus()
{
IDbConnection newConnection = DataProvider.Instance().GetConnection();
IDbTransaction trans = newConnection.BeginTransaction();
try
{
this.UpdateApprovalStatus(trans);
trans.Commit();
Utility.ClearPublishCache(this.PortalId);
}
catch
{
trans.Rollback();
throw;
}
finally
{
// clean up connection stuff
newConnection.Close();
}
}
protected override void ResolveIds(int currentModuleId)
{
base.ResolveIds(currentModuleId);
// display tab
using (IDataReader dr = DataProvider.Instance().GetPublishTabId(this.ChildDisplayTabName, this.PortalId))
{
if (dr.Read())
{
this.childDisplayTabId = (int)dr["TabId"];
}
else
{
// Default to setting for module
string settingName = Utility.PublishDefaultDisplayPage + this.PortalId.ToString(CultureInfo.InvariantCulture);
string setting = HostController.Instance.GetString(settingName);
if (!int.TryParse(setting, NumberStyles.Integer, CultureInfo.InvariantCulture, out this.childDisplayTabId))
{
throw new InvalidOperationException("Default Display Page setting must be set in order to import items");
}
}
}
// For situations where the user is importing content from another system (file not generated from Publish)
// they have no way of knowing what the top level category GUIDS are nor to include the entries in the
// relationships section of the file. Note, the stored procedure verifies the relationship doesn't exist
// before inserting a new row.
var relationship = new ItemRelationship
{
RelationshipTypeId = RelationshipType.CategoryToTopLevelCategory.GetId(),
ParentItemId = TopLevelCategoryItemType.Category.GetId()
};
this.Relationships.Add(relationship);
bool save = false;
// now the Unique Id's
// Does this ItemVersion exist in my db?
using (IDataReader dr = DataProvider.Instance().GetItemVersion(this.ItemVersionIdentifier, this.PortalId))
{
if (dr.Read())
{
// this item already exists
// update some stuff???
}
else
{
// this version does not exist.
this.ItemId = -1;
this.ItemVersionId = -1;
this.ModuleId = currentModuleId;
save = true;
}
}
if (save)
{
this.Save(this.RevisingUserId);
}
}
}
}