예제 #1
0
        /// <summary>
        /// Populates the languages recursive.
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        private void PopulateLanguagesRecursive(int folderId)
        {
            Guid siteId = Guid.Empty;

            DataTable item = FileTreeItem.GetItemByIdDT(folderId);

            // We only care about pages
            if (item != null && item.Rows.Count > 0)
            {
                if ((bool)item.Rows[0]["IsFolder"])
                {
                    DataTable childItems = FileTreeItem.LoadItemByFolderIdDT(folderId);
                    foreach (DataRow childItem in childItems.Rows)
                    {
                        PopulateLanguagesRecursive((int)childItem["PageId"]);
                    }
                }
            }

            siteId = (Guid)item.Rows[0]["SiteId"];
            PageDocument pageDocument = null;

            //GET PUBLISHED VERSION
            int       statusId      = WorkflowStatus.GetLast();
            DataTable versionsTable = PageVersion.GetVersionByStatusIdDT(folderId, statusId);

            // Find page document
            int templateId = 0;
            int stateId    = 0;
            int langId     = 0;

            if (versionsTable != null && versionsTable.Rows.Count > 0)
            {
                foreach (DataRow versionRow in versionsTable.Rows)
                {
                    int versionId = 0;
                    int.TryParse(versionRow["VersionId"].ToString(), out versionId);
                    templateId = Int32.Parse(versionRow["templateid"].ToString());
                    PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider();
                    pageDocument = PageDocument.Open(versionId, OpenMode.View, Guid.Empty);
                    stateId      = Int32.Parse(versionRow["stateid"].ToString());
                    langId       = Int32.Parse(versionRow["LangId"].ToString());

                    // Found a non empty page document
                    if (pageDocument != null)
                    {
                        break;
                    }
                }
            }

            // Get list of languages
            SiteDto siteDto = SiteManager.GetSite(siteId);

            foreach (SiteDto.SiteLanguageRow langRow in siteDto.SiteLanguage)
            {
                IDataReader reader = Language.GetLangByName(langRow.LanguageCode);
                if (reader.Read())
                {
                    int currentLangId = (int)reader["LangId"];

                    // We skip the default page document language
                    if (currentLangId == langId)
                    {
                        reader.Close();
                        continue;
                    }

                    // If we already have a specified language define, skip it
                    IDataReader versionReader = PageVersion.GetVersionByLangId(folderId, langId);
                    if (!versionReader.Read())
                    {
                        versionReader.Close();
                        continue;
                    }

                    int versionId = PageVersion.AddPageVersion(folderId, templateId, currentLangId, ProfileContext.Current.UserId, stateId, String.Empty);
                    PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider();
                    PageDocument.PersistentDocumentStorage.Save(pageDocument, versionId, ProfileContext.Current.UserId);
                    versionReader.Close();
                }
                reader.Close();
            }
        }