diff --git a/RMuseum/DbContext/RMuseumDbContext.cs b/RMuseum/DbContext/RMuseumDbContext.cs index 02f66715..ef497ca7 100644 --- a/RMuseum/DbContext/RMuseumDbContext.cs +++ b/RMuseum/DbContext/RMuseumDbContext.cs @@ -229,7 +229,12 @@ namespace RMuseum.DbContext /// PoemMusicTracks /// public DbSet GanjoorPoemMusicTracks { get; set; } - + + /// + /// Ganjoor Comments + /// + public DbSet GanjoorComments { get; set; } + } } diff --git a/RMuseum/Models/Ganjoor/GanjoorComment.cs b/RMuseum/Models/Ganjoor/GanjoorComment.cs index 216ec0cc..82179b3f 100644 --- a/RMuseum/Models/Ganjoor/GanjoorComment.cs +++ b/RMuseum/Models/Ganjoor/GanjoorComment.cs @@ -17,12 +17,12 @@ namespace RMuseum.Models.Ganjoor /// /// Ganjoor Poem Id /// - public int GanjoorPoemId { get; set; } + public int PoemId { get; set; } /// /// Ganjoor Poem Id /// - public GanjoorPoem GanjoorPoem { get; set; } + public GanjoorPoem Poem { get; set; } /// /// user id @@ -52,7 +52,7 @@ namespace RMuseum.Models.Ganjoor /// /// author IP address (MySql imported field) /// - public string AutherIpAddress { get; set; } + public string AuthorIpAddress { get; set; } /// /// comment date @@ -67,12 +67,12 @@ namespace RMuseum.Models.Ganjoor /// /// In Reply to Other Comment /// - public virtual GanjoorComment ReferenceComment { get; set; } + public virtual GanjoorComment InReplyTo { get; set; } /// /// Reference Comment Id /// - public Guid? ReferenceCommentId { get; set; } + public Guid? InReplyToId { get; set; } /// /// publish status diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index cd6f1309..3b055249 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1283,6 +1283,11 @@ PoemMusicTracks + + + Ganjoor Comments + + Items or pictures status @@ -3539,12 +3544,12 @@ Id - + Ganjoor Poem Id - + Ganjoor Poem Id @@ -3574,7 +3579,7 @@ author url (MySql imported field) - + author IP address (MySql imported field) @@ -3589,12 +3594,12 @@ comment - + In Reply to Other Comment - + Reference Comment Id diff --git a/RMuseum/Services/Implementation/GanjoorService-Imports/GanjoorService-MySqlImports.cs b/RMuseum/Services/Implementation/GanjoorService-Imports/GanjoorService-MySqlImports.cs index da5feebd..c701093c 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Imports/GanjoorService-MySqlImports.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Imports/GanjoorService-MySqlImports.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using MySql.Data.MySqlClient; using RMuseum.DbContext; +using RMuseum.Models.Artifact; using RMuseum.Models.Ganjoor; using RMuseum.Models.MusicCatalogue; using RSecurityBackend.Models.Generic; @@ -40,6 +41,12 @@ namespace RMuseum.Services.Implementation var job = (await jobProgressServiceEF.NewJob("GanjoorService:ImportFromMySql", "pre open connection")).Result; + var resComments = await _ImportCommentsDataFromMySql(context, jobProgressServiceEF, job); + if(resComments.Result)//temporary + { + return; + } + MusicCatalogueService catalogueService = new MusicCatalogueService(Configuration, context); RServiceResult musicCatalogueRes = await catalogueService.ImportFromMySql(jobProgressServiceEF, job); @@ -468,6 +475,96 @@ namespace RMuseum.Services.Implementation } + private async Task> _ImportCommentsDataFromMySql(RMuseumDbContext context, LongRunningJobProgressServiceEF jobProgressServiceEF, RLongRunningJobStatus job) + { + try + { + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, "phase comments - pre mysql data fetch")).Result; + + string connectionString = + $"server={Configuration.GetSection("AudioMySqlServer")["Server"]};uid={Configuration.GetSection("AudioMySqlServer")["Username"]};pwd={Configuration.GetSection("AudioMySqlServer")["Password"]};database={Configuration.GetSection("AudioMySqlServer")["Database"]};charset=utf8;convert zero datetime=True"; + + using (MySqlConnection connection = new MySqlConnection + ( + connectionString + )) + { + connection.Open(); + using (MySqlDataAdapter src = new MySqlDataAdapter( + "SELECT comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved FROM ganja_comments WHERE comment_type <> 'pingback' ORDER BY comment_ID", + connection)) + { + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, "phase comments - mysql")).Result; + using (DataTable data = new DataTable()) + { + await src.FillAsync(data); + + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, "phase comments - processing approved poem songs")).Result; + + int count = data.Rows.Count; + int i = 0; + + int percent = -1; + + foreach (DataRow row in data.Rows) + { + GanjoorComment comment = new GanjoorComment() + { + PoemId = int.Parse(row["comment_post_ID"].ToString()), + AuthorName = row["comment_author"].ToString(), + AuthorEmail = row["comment_author_email"].ToString(), + AuthorUrl = row["comment_author_url"].ToString(), + AuthorIpAddress = row["comment_author_IP"].ToString(), + CommentDate = (DateTime)row["comment_date"], + HtmlComment = row["comment_content"].ToString(), + Status = row["comment_approved"].ToString() == "1" ? PublishStatus.Published : PublishStatus.Awaiting + }; + + + context.GanjoorComments.Add(comment); + + await context.SaveChangesAsync(); //keeping original order of comments by saving things here + + i++; + + if(i * 100 / count > percent) + { + percent = i * 100 / count; + + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, $"phase comments - {i} of {count}")).Result; + } + } + + } + + } + } + + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, "phase comments - assigning comments to users")).Result; + foreach (var user in await context.Users.ToListAsync()) + { + foreach(var comment in await context.GanjoorComments.Where(u => u.AuthorEmail == user.Email).ToListAsync()) + { + comment.UserId = user.Id; + context.GanjoorComments.Update(comment); + } + } + await context.SaveChangesAsync(); + + + job = (await jobProgressServiceEF.UpdateJob(job.Id, 0, "phase comments - finished")).Result; + + + return new RServiceResult(true); + } + catch(Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + + + private List _extractVersesFromPoemHtmlText(string poemtext) { List verses = new List();