Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Twitter/X workflow task to match updated view names #15930

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
66864b5
Rename workflow task to match updated view names to resolve missing s…
davidpuplava Apr 30, 2024
62af19b
Add data migration to update existing workflows to use updated Twiite…
davidpuplava May 2, 2024
ae4d618
Refactor content item migrations to match how it's done in Lucene Sea…
davidpuplava May 3, 2024
b3dd976
Refactor unnecessary method call inline to calling method to remove w…
davidpuplava May 8, 2024
c55b807
Merge branch 'main' into davidpuplava/update-x-status-task-shape-not-…
MikeAlhayek May 16, 2024
5ba3d09
Merge branch 'main' into davidpuplava/update-x-status-task-shape-not-…
Piedone Jun 20, 2024
41e5642
Merge tag 'before-formatting
davidpuplava Aug 15, 2024
b95fec7
Format code
davidpuplava Aug 16, 2024
7941494
Merge tag 'formatting'
davidpuplava Aug 16, 2024
17160a6
Refactor Twitter to X migration to simplify database logic; edited na…
davidpuplava Aug 16, 2024
7133943
Merge remote-tracking branch 'upstream/main' into davidpuplava/update…
davidpuplava Aug 16, 2024
2916586
Simplify using expressions for database operations
davidpuplava Aug 16, 2024
43419a9
Merge remote-tracking branch 'upstream/main' into davidpuplava/update…
davidpuplava Aug 17, 2024
ba89043
Rename types/classes/ids back to before X/Twitter rebrand; removed mi…
davidpuplava Aug 17, 2024
e1679a4
Update X/Twitter documentation links in Admin UI
davidpuplava Aug 19, 2024
9a1d3d4
Merge remote-tracking branch 'upstream/main' into davidpuplava/update…
davidpuplava Aug 19, 2024
14e60dc
Remove reference to YesSql project previously added when Migration ex…
davidpuplava Aug 20, 2024
c9cecb0
Remove unused using statement
davidpuplava Aug 20, 2024
84542b9
Fix typo in documentation link to X/Twitter integration docs
davidpuplava Aug 20, 2024
31100c5
Merge remote-tracking branch 'upstream/main' into davidpuplava/update…
davidpuplava Aug 20, 2024
a4504f3
Remove another unused using statement
davidpuplava Aug 20, 2024
8d16b9d
Merge branch 'main' into davidpuplava/update-x-status-task-shape-not-…
hishamco Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Dapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Descriptor.Models;
using OrchardCore.Environment.Shell.Scope;
using YesSql;

namespace OrchardCore.Twitter.Migrations;

public class TwitterMigrations : DataMigration
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly ShellDescriptor _shellDescriptor;

public TwitterMigrations(ShellDescriptor shellDescriptor)
{
_shellDescriptor = shellDescriptor;
}

public int Create()
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
if (_shellDescriptor.WasFeatureAlreadyInstalled("OrchardCore.Twitter"))
{
ShellScope.AddDeferredTask(async scope =>
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
var session = scope.ServiceProvider.GetRequiredService<ISession>();
var dbConnectionAccessor = scope.ServiceProvider.GetService<IDbConnectionAccessor>();
var logger = scope.ServiceProvider.GetService<ILogger<TwitterMigrations>>();
var tablePrefix = session.Store.Configuration.TablePrefix;
var documentTableName = session.Store.Configuration.TableNameConvention.GetDocumentTable();
var table = $"{session.Store.Configuration.TablePrefix}{documentTableName}";

logger.LogDebug("Updating Twitter/X Workflow Items");

await using var connection = dbConnectionAccessor.CreateConnection();
await connection.OpenAsync();
await using var transaction = await connection.BeginTransactionAsync(session.Store.Configuration.IsolationLevel);
var dialect = session.Store.Configuration.SqlDialect;

try
{
var quotedTableName = dialect.QuoteForTableName(table, session.Store.Configuration.Schema);
var quotedContentColumnName = dialect.QuoteForColumnName("Content");
var quotedTypeColumnName = dialect.QuoteForColumnName("Type");

var updateCmd = $"UPDATE {quotedTableName} SET {quotedContentColumnName} = REPLACE({quotedContentColumnName}, 'UpdateTwitterStatusTask', 'UpdateXStatusTask') WHERE {quotedTypeColumnName} = 'OrchardCore.Workflows.Models.WorkflowType, OrchardCore.Workflows.Abstractions'";

await transaction.Connection.ExecuteAsync(updateCmd, null, transaction);

await transaction.CommitAsync();
}
catch (Exception e)
{
await transaction.RollbackAsync();
logger.LogError(e, "An error occurred while updating Twitter/X Workflow Items");

throw;
}
});
}

return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement.Abstractions\OrchardCore.ContentManagement.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Data.Abstractions\OrchardCore.Data.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Data.YesSql\OrchardCore.Data.YesSql.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Twitter/Startup.cs
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Http.Resilience;
using Microsoft.Extensions.Options;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using OrchardCore.Recipes;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using OrchardCore.Twitter.Drivers;
using OrchardCore.Twitter.Migrations;
using OrchardCore.Twitter.Recipes;
using OrchardCore.Twitter.Services;
using OrchardCore.Twitter.Settings;
Expand Down Expand Up @@ -60,6 +62,7 @@ public override void ConfigureServices(IServiceCollection services)
}
})
);
services.AddDataMigration<TwitterMigrations>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using OrchardCore.Workflows.ViewModels
@using OrchardCore.Twitter.Workflows.Activities

@model ActivityViewModel<UpdateTwitterStatusTask>
@model ActivityViewModel<UpdateXStatusTask>

<header>
<h4><i class="fa-brands fa-x-twitter" aria-hidden="true"></i>@Model.Activity.GetTitleOrDefault(() => T["Update X Status"])</h4>
Expand Down
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

namespace OrchardCore.Twitter.Workflows.Activities
{
public class UpdateTwitterStatusTask : TaskActivity<UpdateTwitterStatusTask>
public class UpdateXStatusTask : TaskActivity<UpdateXStatusTask>
{
private readonly TwitterClient _twitterClient;
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
protected readonly IStringLocalizer S;

public UpdateTwitterStatusTask(
public UpdateXStatusTask(
TwitterClient twitterClient,
IWorkflowExpressionEvaluator expressionEvaluator,
IStringLocalizer<UpdateTwitterStatusTask> localizer
IStringLocalizer<UpdateXStatusTask> localizer
)
{
_twitterClient = twitterClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace OrchardCore.Twitter.Workflows.Drivers
{
public class UpdateTwitterStatusTaskDisplayDriver : ActivityDisplayDriver<UpdateTwitterStatusTask, UpdateTwitterStatusTaskViewModel>
public class UpdateTwitterStatusTaskDisplayDriver : ActivityDisplayDriver<UpdateXStatusTask, UpdateTwitterStatusTaskViewModel>
{
protected override void EditActivity(UpdateTwitterStatusTask activity, UpdateTwitterStatusTaskViewModel model)
protected override void EditActivity(UpdateXStatusTask activity, UpdateTwitterStatusTaskViewModel model)
{
model.StatusTemplate = activity.StatusTemplate.Expression;
}

protected override void UpdateActivity(UpdateTwitterStatusTaskViewModel model, UpdateTwitterStatusTask activity)
protected override void UpdateActivity(UpdateTwitterStatusTaskViewModel model, UpdateXStatusTask activity)
{
activity.StatusTemplate = new WorkflowExpression<string>(model.StatusTemplate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Data.Migration;
davidpuplava marked this conversation as resolved.
Show resolved Hide resolved
using OrchardCore.Modules;
using OrchardCore.Twitter.Migrations;
using OrchardCore.Twitter.Workflows.Activities;
using OrchardCore.Twitter.Workflows.Drivers;
using OrchardCore.Workflows.Helpers;
Expand All @@ -11,7 +13,7 @@ public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddActivity<UpdateTwitterStatusTask, UpdateTwitterStatusTaskDisplayDriver>();
services.AddActivity<UpdateXStatusTask, UpdateTwitterStatusTaskDisplayDriver>();
}
}
}