Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Oct 7, 2018
1 parent 59ce6dc commit f623421
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 50 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.3.3 - Unreleased
### Changed
- Improved how elements are output in exported CSV file

### Fixed
- Fixed a bug in which a completed sendout could be marked as pending if complained or bounced contacts existed in the selected mailing lists
- Fixed a bug in which an exception could be thrown if a logged-in user was not found when trying to import contacts

## 1.3.2 - 2018-09-28
### Added
- Added warning to general settings and preflight if `@web` alias is used in the base URL of any site or volume
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-campaign",
"description": "Send and manage email campaigns, contacts and mailing lists.",
"version": "1.3.2",
"version": "1.3.3",
"type": "craft-plugin",
"homepage": "https://craftcampaign.com/",
"license": "proprietary",
Expand Down
4 changes: 3 additions & 1 deletion src/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ public function maxPowerLieutenant()
* @param array $params
* @param string|null $category
*/
public function logUserAction(string $message, array $params, string $category = 'Campaign')
public function logUserAction(string $message, array $params, string $category = null)
{
$category = $category ?? 'Campaign';

$params['username'] = Craft::$app->getUser()->getIdentity()->username;

Craft::warning(Craft::t('campaign', $message, $params), $category);
Expand Down
13 changes: 9 additions & 4 deletions src/base/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ abstract class BaseModel extends Model
*
* @return Model
*/
public static function populateModel($values, $safeOnly = true): Model
public static function populateModel($values, bool $safeOnly = null): Model
{
$safeOnly = $safeOnly ?? true;

// If an instance of a Yii model
if ($values instanceof \yii\base\Model) {
$values = $values->getAttributes();
Expand All @@ -56,18 +58,21 @@ public static function populateModel($values, $safeOnly = true): Model
*
* @return array
*/
public static function populateModels(array $data, $safeOnly = true, $indexBy = null): array
public static function populateModels(array $data, bool $safeOnly = null, string $indexBy = null): array
{
$safeOnly = $safeOnly ?? true;

$models = [];

if (\is_array($data))
{
foreach ($data as $values)
{
$model = static::populateModel($values, $safeOnly);
if ($indexBy)

if ($indexBy !== null)
{
$models[$model->$indexBy] = $model;
$models[$model->{$indexBy}] = $model;
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/SegmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ public function actionSaveSegment()
// Sort or conditions by keys
ksort($orCondition);
}

// Unset variable reference to avoid possible side-effects
unset($orCondition);
}

// Unset variable reference to avoid possible side-effects
unset($andCondition);
}

// JSON encode conditions
Expand Down
6 changes: 4 additions & 2 deletions src/elements/CampaignElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,18 @@ public function afterSave(bool $isNew)
/**
* Returns the campaign's body
*
* @param string $templateType
* @param string|null $templateType
* @param ContactElement|null $contact
* @param SendoutElement|null $sendout
*
* @return string
* @throws InvalidConfigException
* @throws Exception
*/
private function _getBody($templateType = 'html', ContactElement $contact = null, SendoutElement $sendout = null): string
private function _getBody(string $templateType = null, ContactElement $contact = null, SendoutElement $sendout = null): string
{
$templateType = $templateType ?? 'html';

if ($contact === null) {
$contact = new ContactElement();
}
Expand Down
12 changes: 8 additions & 4 deletions src/elements/ContactElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,14 @@ public function afterSave(bool $isNew)
/**
* Returns the number of mailing lists that this contact is in
*
* @param string|null
* @param string|null $subscriptionStatus
*
* @return int
*/
private function _getMailingListCount(string $subscriptionStatus = ''): int
private function _getMailingListCount(string $subscriptionStatus = null): int
{
$subscriptionStatus = $subscriptionStatus ?? '';

$condition = ['contactId' => $this->id];

if ($subscriptionStatus) {
Expand All @@ -737,12 +739,14 @@ private function _getMailingListCount(string $subscriptionStatus = ''): int
/**
* Returns the mailing lists that this contact is in
*
* @param string|null
* @param string|null $subscriptionStatus
*
* @return MailingListElement[]
*/
private function _getMailingLists(string $subscriptionStatus = ''): array
private function _getMailingLists(string $subscriptionStatus = null): array
{
$subscriptionStatus = $subscriptionStatus ?? '';

$mailingLists = [];

$condition = ['contactId' => $this->id];
Expand Down
6 changes: 4 additions & 2 deletions src/elements/MailingListElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,14 @@ public function afterSave(bool $isNew)
/**
* Returns the number of contacts in this mailing list
*
* @param string|null
* @param string|null $subscriptionStatus
*
* @return int
*/
private function _getContactCount(string $subscriptionStatus = ''): int
private function _getContactCount(string $subscriptionStatus = null): int
{
$subscriptionStatus = $subscriptionStatus ?? '';

$condition = ['mailingListId' => $this->id];

if ($subscriptionStatus) {
Expand Down
12 changes: 10 additions & 2 deletions src/elements/SendoutElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ public function getPendingRecipients(): array
/** @var MailingListElement $mailingList */
$contacts = $mailingList->getSubscribedContacts();
foreach ($contacts as $contact) {
// If contact has complained or bounced
if ($contact->complained !== null OR $contact->bounced !== null) {
continue;
}

// If contact has not yet been added
/** @var ContactElement $contact */
if (empty($recipients[$contact->id])) {
Expand Down Expand Up @@ -777,11 +782,14 @@ public function getPendingRecipients(): array
/**
* Returns the sendout's sent recipient ID's
*
* @param bool $todayOnly
* @param bool|null $todayOnly
*
* @return array
*/
public function getSentRecipientIds($todayOnly = false): array
public function getSentRecipientIds(bool $todayOnly = null): array
{
$todayOnly = $todayOnly ?? false;

$query = ContactCampaignRecord::find()
->select('contactId')
->where(['sendoutId' => $this->id])
Expand Down
6 changes: 4 additions & 2 deletions src/elements/db/MailingListElementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ public function syncedUserGroupId($value)
/**
* Sets the [[synced]] property.
*
* @param bool $value The property value
* @param bool|null $value The property value
*
* @return static self reference
*/
public function synced(bool $value = true)
public function synced(bool $value = null)
{
$value = $value ?? true;

$this->synced = $value;

return $this;
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class StringHelper extends \craft\helpers\StringHelper
*
* @return string
*/
public static function uniqueId(string $prefix = ''): string
public static function uniqueId(string $prefix = null): string
{
$prefix = $prefix ?? '';

return uniqid($prefix, false).self::randomString(3);
}

Expand Down
6 changes: 4 additions & 2 deletions src/services/CampaignTypesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ public function getCampaignTypeByHandle(string $campaignTypeHandle)
* Saves a campaign type.
*
* @param CampaignTypeModel $campaignType The campaign type to be saved
* @param bool $runValidation Whether the campaign type should be validated
* @param bool|null $runValidation Whether the campaign type should be validated
*
* @return bool Whether the campaign type was saved successfully
* @throws NotFoundHttpException if $campaignType->id is invalid
* @throws \Throwable if reasons
*/
public function saveCampaignType(CampaignTypeModel $campaignType, bool $runValidation = true): bool
public function saveCampaignType(CampaignTypeModel $campaignType, bool $runValidation = null): bool
{
$runValidation = $runValidation ?? true;

$isNew = $campaignType->id === null;

// Fire a before event
Expand Down
21 changes: 20 additions & 1 deletion src/services/ExportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace putyourlightson\campaign\services;

use craft\base\Element;
use craft\elements\db\ElementQuery;
use putyourlightson\campaign\Campaign;
use putyourlightson\campaign\events\ExportEvent;
use putyourlightson\campaign\models\ExportModel;
Expand Down Expand Up @@ -79,7 +81,24 @@ public function exportFile(ExportModel $export): bool
// Populate row with contact fields
$row = [];
foreach ($export->fields as $field) {
$row[] = $contact->$field;
$value = $contact->$field;

if ($value instanceof ElementQuery) {
$elements = $value->all();

// Use the string representation of each element
/** @var Element $element */
foreach ($elements as &$element) {
$element = $element->__toString();
}

// Unset variable reference to avoid possible side-effects
unset($element);

$value = implode(',', $elements);
}

$row[] = $value;
}

// Write contact fields to file
Expand Down
4 changes: 3 additions & 1 deletion src/services/ImportsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ public function getColumns(ImportModel $import): array
*
* @return array
*/
public function getRows(ImportModel $import, int $offset = 0, int $length = null): array
public function getRows(ImportModel $import, int $offset = null, int $length = null): array
{
$offset = $offset ?? 0;

$rows = [];

// If CSV file
Expand Down
6 changes: 4 additions & 2 deletions src/services/MailingListTypesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public function getMailingListTypeByHandle(string $mailingListTypeHandle)
* Saves a mailing list type.
*
* @param MailingListTypeModel $mailingListType The mailing list type to be saved
* @param bool $runValidation Whether the mailing list type should be validated
* @param bool|null $runValidation Whether the mailing list type should be validated
*
* @return bool Whether the mailing list type was saved successfully
* @throws \Throwable if reasons
*/
public function saveMailingListType(MailingListTypeModel $mailingListType, bool $runValidation = true): bool
public function saveMailingListType(MailingListTypeModel $mailingListType, bool $runValidation = null): bool
{
$runValidation = $runValidation ?? true;

$isNew = $mailingListType->id === null;

// Fire a before event
Expand Down
6 changes: 5 additions & 1 deletion src/services/MailingListsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public function getMailingListById(int $mailingListId)
* @param string|null $source
* @param bool|null $verify
*/
public function addContactInteraction(ContactElement $contact, MailingListElement $mailingList, string $interaction, $sourceType = '', $source = '', $verify = false)
public function addContactInteraction(ContactElement $contact, MailingListElement $mailingList, string $interaction, string $sourceType = null, string $source = null, bool $verify = null)
{
$sourceType = $sourceType ?? '';
$source = $source ?? '';
$verify = $verify ?? false;

// Ensure that interaction exists
if (!\in_array($interaction, ContactMailingListModel::INTERACTIONS, true)) {
return;
Expand Down
Loading

0 comments on commit f623421

Please sign in to comment.