Skip to content

Commit

Permalink
Merge branch 'bugfix/github-actions' of https://github.com/mettle/sen…
Browse files Browse the repository at this point in the history
…dportal-core into bugfix/github-actions
  • Loading branch information
JonoB committed Apr 18, 2024
2 parents 77842cf + 6609f52 commit 7180d14
Show file tree
Hide file tree
Showing 72 changed files with 160 additions and 159 deletions.
2 changes: 1 addition & 1 deletion database/factories/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TemplateFactory extends Factory
{
/** @var string */
protected $model = Template::class;

public function definition(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public function up()

DB::table('sendportal_campaign_statuses')
->insert([
['name' => 'Draft'],
['name' => 'Queued'],
['name' => 'Sending'],
['name' => 'Sent'],
['name' => 'Draft'],
['name' => 'Queued'],
['name' => 'Sending'],
['name' => 'Sent'],
]);
}
}
2 changes: 1 addition & 1 deletion database/migrations/2020_10_16_092234_prefix_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up()
continue;
}

if (!Schema::hasTable("{$table}")) {
if (! Schema::hasTable("{$table}")) {
continue;
}

Expand Down
13 changes: 5 additions & 8 deletions src/Adapters/PostalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,38 @@

use DomainException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Postal\Client;
use Postal\SendMessage;
use Sendportal\Base\Services\Messages\MessageTrackingOptions;
use Symfony\Component\HttpFoundation\Response;

class PostalAdapter extends BaseMailAdapter
{

/**
* @throws TypeException
* @throws \Throwable
*/
public function send(string $fromEmail, string $fromName, string $toEmail, string $subject, MessageTrackingOptions $trackingOptions, string $content): string
{
$client = new Client('https://' . Arr::get($this->config, 'postal_host'), Arr::get($this->config, 'key'));

$message = new SendMessage($client);
$message->to($toEmail);
$message->from($fromName.' <'.$fromEmail.'>');
$message->subject($subject);
$message->htmlBody($content);
$response = $message->send();

return $this->resolveMessageId($response);
}



protected function resolveMessageId($response): string
{
foreach ($response->recipients() as $email => $message) {
return (string) $message->id();
return (string) $message->id();
}

throw new DomainException('Unable to resolve message ID');
}
}
2 changes: 1 addition & 1 deletion src/Adapters/SendgridMailAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function send(string $fromEmail, string $fromName, string $toEmail, strin
$response = $this->resolveClient()->send($email);

throw_if(
!in_array($response->statusCode(), [Response::HTTP_OK, Response::HTTP_ACCEPTED]),
! in_array($response->statusCode(), [Response::HTTP_OK, Response::HTTP_ACCEPTED]),
new DomainException($response->body(), $response->statusCode())
);

Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/SmtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function resolveTransport(): EsmtpTransport

$encryption = Arr::get($this->config, 'encryption');

$scheme = !is_null($encryption) && $encryption === 'tls'
$scheme = ! is_null($encryption) && $encryption === 'tls'
? ((Arr::get($this->config, 'port') == 465) ? 'smtps' : 'smtp')
: '';

Expand Down
4 changes: 3 additions & 1 deletion src/Events/MessageDispatchEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

class MessageDispatchEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/**
* @var Message
Expand Down
4 changes: 3 additions & 1 deletion src/Events/SubscriberAddedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

class SubscriberAddedEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/** @var Subscriber */
public $subscriber;
Expand Down
4 changes: 3 additions & 1 deletion src/Events/Webhooks/MailgunWebhookReceived.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

class MailgunWebhookReceived
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

/** @var array */
public $payload;
Expand Down
1 change: 0 additions & 1 deletion src/Facades/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Helper extends Facade
{

/**
* @return string
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Factories/MailAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use InvalidArgumentException;
use Sendportal\Base\Adapters\MailgunMailAdapter;
use Sendportal\Base\Adapters\MailjetAdapter;
use Sendportal\Base\Adapters\PostalAdapter;
use Sendportal\Base\Adapters\PostmarkMailAdapter;
use Sendportal\Base\Adapters\SendgridMailAdapter;
use Sendportal\Base\Adapters\SesMailAdapter;
use Sendportal\Base\Adapters\SmtpAdapter;
use Sendportal\Base\Adapters\PostalAdapter;
use Sendportal\Base\Interfaces\MailAdapterInterface;
use Sendportal\Base\Models\EmailService;
use Sendportal\Base\Models\EmailServiceType;
Expand Down Expand Up @@ -57,13 +57,13 @@ private function cache(MailAdapterInterface $adapter, EmailService $emailService
*/
private function resolve(EmailService $emailService): MailAdapterInterface
{
if (!$emailServiceType = EmailServiceType::resolve($emailService->type_id)) {
throw new InvalidArgumentException("Unable to resolve mail provider type from ID [$emailService->type_id].");
if (! $emailServiceType = EmailServiceType::resolve($emailService->type_id)) {
throw new InvalidArgumentException("Unable to resolve mail provider type from ID [{$emailService->type_id}].");
}

$adapterClass = self::$adapterMap[$emailService->type_id] ?? null;

if (!$adapterClass) {
if (! $adapterClass) {
throw new InvalidArgumentException("Mail adapter type [{$emailServiceType}] is not supported.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Sendportal\Base\Http\Controllers\Api\Webhooks;

use Illuminate\Support\Arr;

use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;
use Sendportal\Base\Events\Webhooks\PostalWebhookReceived;
Expand All @@ -20,7 +18,7 @@ public function handle(): Response
Log::info('Postal webhook received');

event(new PostalWebhookReceived($payload));


return response('OK');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function handle(): Response

$payloadType = $payload['Type'] ?? null;

if (!in_array($payloadType, ['SubscriptionConfirmation', 'Notification'], true)) {
if (! in_array($payloadType, ['SubscriptionConfirmation', 'Notification'], true)) {
return response('OK (not processed).');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

class RegisterController extends Controller
{
use RegistersUsers,
ChecksInvitations;
use RegistersUsers;
use ChecksInvitations;

/** @var AcceptInvitation */
private $acceptInvitation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function cancel(int $campaignId)
$campaign = $this->campaignRepository->find(Sendportal::currentWorkspaceId(), $campaignId, ['status']);
$originalStatus = $campaign->status;

if (!$campaign->canBeCancelled()) {
if (! $campaign->canBeCancelled()) {
throw ValidationException::withMessages([
'campaignStatus' => "{$campaign->status->name} campaigns cannot be cancelled.",
])->redirectTo(route('sendportal.campaigns.index'));
}

if ($campaign->save_as_draft && !$campaign->allDraftsCreated()) {
if ($campaign->save_as_draft && ! $campaign->allDraftsCreated()) {
throw ValidationException::withMessages([
'messagesPendingDraft' => __('Campaigns that save draft messages cannot be cancelled until all drafts have been created.'),
])->redirectTo(route('sendportal.campaigns.index'));
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Campaigns/CampaignDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function confirm(int $id)
{
$campaign = $this->campaigns->find(Sendportal::currentWorkspaceId(), $id);

if (!$campaign->draft) {
if (! $campaign->draft) {
return redirect()->route('sendportal.campaigns.index')
->withErrors(__('Unable to delete a campaign that is not in draft status'));
}
Expand All @@ -49,7 +49,7 @@ public function destroy(Request $request): RedirectResponse
{
$campaign = $this->campaigns->find(Sendportal::currentWorkspaceId(), $request->get('id'));

if (!$campaign->draft) {
if (! $campaign->draft) {
return redirect()->route('sendportal.campaigns.index')
->withErrors(__('Unable to delete a campaign that is not in draft status'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function send(CampaignDispatchRequest $request, int $id): RedirectRespons
return redirect()->route('sendportal.campaigns.status', $id);
}

if (!$campaign->email_service_id) {
if (! $campaign->email_service_id) {
return redirect()->route('sendportal.campaigns.edit', $id)
->withErrors(__('Please select an Email Service'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Campaigns/CampaignTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handle(CampaignTestRequest $request, int $campaignId): RedirectR
{
$messageId = $this->dispatchTestMessage->handle(Sendportal::currentWorkspaceId(), $campaignId, $request->get('recipient_email'));

if (!$messageId) {
if (! $messageId) {
return redirect()->route('sendportal.campaigns.preview', $campaignId)
->withInput()
->with(['error', __('Failed to dispatch test email.')]);
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Campaigns/CampaignsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function preview(int $id)
$campaign = $this->campaigns->find(Sendportal::currentWorkspaceId(), $id);
$subscriberCount = $this->subscribers->countActive(Sendportal::currentWorkspaceId());

if (!$campaign->draft) {
if (! $campaign->draft) {
return redirect()->route('sendportal.campaigns.status', $id);
}

Expand Down Expand Up @@ -205,7 +205,7 @@ private function handleCheckboxes(array $input): array
];

foreach ($checkboxFields as $checkboxField) {
if (!isset($input[$checkboxField])) {
if (! isset($input[$checkboxField])) {
$input[$checkboxField] = false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Sendportal\Base\Http\Controllers\EmailServices;

use Exception;
Expand Down Expand Up @@ -45,7 +44,7 @@ public function store(int $emailServiceId, EmailServiceTestRequest $request, Dis
try {
$messageId = $dispatchTestMessage->testService(Sendportal::currentWorkspaceId(), $emailService, $options);

if (!$messageId) {
if (! $messageId) {
return redirect()
->back()
->with(['error', __('Failed to dispatch test email.')]);
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function show(int $messageId): View
*/
public function send(): RedirectResponse
{
if (!$message = $this->messageRepo->find(
if (! $message = $this->messageRepo->find(
Sendportal::currentWorkspaceId(),
request('id'),
['subscriber']
Expand All @@ -128,7 +128,7 @@ public function send(): RedirectResponse
*/
public function delete(): RedirectResponse
{
if (!$message = $this->messageRepo->find(
if (! $message = $this->messageRepo->find(
Sendportal::currentWorkspaceId(),
request('id')
)) {
Expand Down Expand Up @@ -161,7 +161,7 @@ public function sendSelected(): RedirectResponse
return redirect()->back()->withErrors(__('No messages selected'));
}

if (!$messages = $this->messageRepo->getWhereIn(
if (! $messages = $this->messageRepo->getWhereIn(
Sendportal::currentWorkspaceId(),
request('messages'),
['subscriber']
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Subscribers/SubscribersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function update(SubscriberRequest $request, int $id): RedirectResponse
$data = $request->validated();

// updating subscriber from subscribed -> unsubscribed
if (!$request->has('subscribed') && !$subscriber->unsubscribed_at) {
if (! $request->has('subscribed') && ! $subscriber->unsubscribed_at) {
$data['unsubscribed_at'] = now();
$data['unsubscribe_event_id'] = UnsubscribeEventType::MANUAL_BY_ADMIN;
} // updating subscriber from unsubscribed -> subscribed
Expand All @@ -123,7 +123,7 @@ public function update(SubscriberRequest $request, int $id): RedirectResponse
$data['unsubscribe_event_id'] = null;
}

if (!$request->has('tags')) {
if (! $request->has('tags')) {
$data['tags'] = [];
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public function export()
{
$subscribers = $this->subscriberRepo->all(Sendportal::currentWorkspaceId(), 'id');

if (!$subscribers->count()) {
if (! $subscribers->count()) {
return redirect()->route('sendportal.subscribers.index')->withErrors(__('There are no subscribers to export'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function store(SubscribersImportRequest $request): RedirectResponse
'updated' => 0
];

(new FastExcel)->import(Storage::disk('local')->path($path), function (array $line) use ($request, &$counter) {
(new FastExcel())->import(Storage::disk('local')->path($path), function (array $line) use ($request, &$counter) {
$data = Arr::only($line, ['id', 'email', 'first_name', 'last_name']);

$data['tags'] = $request->get('tags') ?? [];
Expand Down Expand Up @@ -109,7 +109,7 @@ protected function validateCsvContents(string $path): ViewErrorBag

$row = 1;

(new FastExcel)->import($path, function (array $line) use ($errors, &$row) {
(new FastExcel())->import($path, function (array $line) use ($errors, &$row) {
$data = Arr::only($line, ['id', 'email', 'first_name', 'last_name']);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/EmailServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function rules()
'name' => ['required']
];

if (!$this->route('id')) {
if (! $this->route('id')) {
$rules['type_id'] = ['required', 'integer'];
}

Expand Down
1 change: 0 additions & 1 deletion src/Http/Requests/EmailServiceTestRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Sendportal\Base\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
Expand Down
4 changes: 3 additions & 1 deletion src/Interfaces/BaseEloquentInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Sendportal\Base\Interfaces;
<?php

namespace Sendportal\Base\Interfaces;

interface BaseEloquentInterface
{
Expand Down
Loading

0 comments on commit 7180d14

Please sign in to comment.