var AllPlaceholders: TCatalogPlaceHolders; procedure ConvertVersionSet(AMainVersion: TCatalogItem); var ACatItems: TCatalogItems; APlaceholders: TCatalogPlaceHolders; APh: TCatalogPlaceHolder; AStackID: String; i: Integer; AVersion: TCatalogItem; AMarkers: Integer; begin { 1. Retrieve all items in the set 2. Retrieve the placeholders used in this version set 3. Destroy the version set 4. Create a new stack } ACatItems := TCatalogItems.Create(TCatalogItem, ''); APlaceholders := TCatalogPlaceHolders.Create(TCatalogPlaceHolder, ''); try PublicCatalog.EnumVersionsForItem(AMainVersion, ACatItems); PublicCatalog.EnumPlaceHoldersForMainVersion(APlaceholders, AMainVersion.GUID, True); APlaceholders.Disconnect; { ACatItems now contains the versions. Add the main version so that ACatItems contains the full set of catalog items that need to become a stack } ACatItems.Disconnect; // disconnect from the dataset so that we // can use it independently of the database AMainVersion.CopyTo(ACatItems, False); // add the main version...in other // words: the last item is always // the old main version. // reset all the stack markers for i := 0 to ACatItems.Count - 1 do begin AVersion := ACatItems.Items[i]; AVersion.GroupMarkers := 0; end; //Say2(AMainVersion.FileName, IntToStr(ACatItems.Count) + '-->' + IntToStr(APlaceholders.Count)); // create the stack AStackID := NewGUID; PublicCatalog.StackItems(ACatItems, AStackID, AMainVersion); // set the main version as the // for every version that had a placeholder, determine the stack markers for i := 0 to APlaceholders.Count - 1 do begin APh := AllPlaceholders.FindItem(APlaceholders.Items[i].GUID); if Assigned(APh) and (APh.idOrder <> -1) then begin AVersion := ACatItems.FindItem(APlaceholders.Items[i]._VersionGUID); if Assigned(AVersion) then begin AMarkers := AVersion.GroupMarkers; Include(AMarkers, APh.idOrder); AVersion.GroupMarkers := AMarkers; end; end; end; // update the stack markers for i := 0 to ACatItems.Count - 1 do begin AVersion := ACatItems.Items[i]; if AVersion.GroupMarkers <> 0 then begin //Say2(AVersion.FileName, IntToStr(AVersion.GroupMarkers)); PublicCatalog.UpdateItemGroupMarkers(AVersion.GUID, AVersion.GroupMarkers); end; end; // destroy the version set PublicCatalog.DestroyVersionSetForItem(AMainVersion); finally APlaceholders.Free; ACatItems.Free; end; end; procedure MapPlaceHolders; var APh: TCatalogPlaceHolder; i: Integer; begin for i := 0 to AllPlaceholders.Count - 1 do begin APh := AllPlaceholders.Items[i]; if APh.PlaceHolderType = vptAlbumDisplay then APh.idOrder := sMarkerWhite else if APh.PlaceHolderType = vptWebDisplay then APh.idOrder := sMarkerRed else if APh.PlaceHolderType = vptSlideDisplay then APh.idOrder := sMarkerOrange else if APh.PlaceHolderType = vptEmail then APh.idOrder := sMarkerYellow else if APh.PlaceHolderType = vptPrint then APh.idOrder := sMarkerAqua else if i <= sMarkerBlack then APh.idOrder := i else APh.idOrder := -1; end; end; procedure ConvertVersionSets(AMainVersions: TCatalogItems); var AProgress: TxomProgress; i: Integer; AOld: Boolean; begin AOld := PublicOptions.AutoQuickSync; PublicOptions.AutoQuickSync := False; AProgress := TxomProgress.Create(nil); AllPlaceholders := TCatalogPlaceHolders.Create(TCatalogPlaceHolder, ''); try PublicCatalog.EnumPlaceHolders(AllPlaceholders, False); // map the place holders MapPlaceHolders; AProgress.Caption := 'Convert version sets to stacks'; AProgress.Max := AMainVersions.Count; AProgress.Pos := 0; AProgress.CanCancel := True; for i := 0 to AMainVersions.Count - 1 do begin AProgress.Pos := i + 1; if AProgress.Cancel then begin Say('Cancelled.'); break; end; ConvertVersionSet(AMainVersions.Items[i]); end; finally AllPlaceholders.Free; AProgress.Free; PublicOptions.AutoQuickSync := AOld; end; end; var AMainVersions: TCatalogItems; begin AMainVersions := TCatalogItems.Create(TCatalogItem, ''); try PublicCatalog.EnumAllMainVersions(AMainVersions); if AMainVersions.Count = 0 then Say('No version sets found.') else if AskYN('Are you sure you want to convert your ' + IntToStr(AMainVersions.Count) + ' Version Set' + iif(AMainVersions.Count = 1, '', 's') + ' to Stacks?') then ConvertVersionSets(AMainVersions); finally AMainVersions.Free; end; end;