Skip to content

Commit

Permalink
Merge pull request #9 from greenpeace-cee/gp-20469-fix-ci-and-misc
Browse files Browse the repository at this point in the history
GP-45362 GP-43955 GP-20469 Skip API4 permission checks, upgrade civix and add CI via GitHub Actions and fix tests
  • Loading branch information
pfigel authored Aug 22, 2024
2 parents dc276c8 + 7404ecc commit df1cdf5
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 1,012 deletions.
143 changes: 0 additions & 143 deletions .circleci/config.yml

This file was deleted.

86 changes: 86 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Run unit tests"

on:
push:
branches:
- master
tags:
pull_request:

env:
CIVI_CI_CIVICRM: ${{ vars.CIVI_CI_CIVICRM || '["5.69", "master"]' }}
CIVI_CI_MYSQL: ${{ vars.CIVI_CI_MYSQL || '["8.0"]' }}
CIVI_CI_OS: ${{ vars.CIVI_CI_OS || '["ubuntu-22.04"]' }}
CIVI_CI_PHP: ${{ vars.CIVI_CI_PHP || '["7.4", "8.0", "8.1"]' }}
CIVI_CI_BUILD_TYPE: ${{ vars.CIVI_CI_BUILD_TYPE || '["drupal-clean"]' }}
CIVI_CI_EXCLUDES: ${{ vars.CIVI_CI_EXCLUDES || '' }}

jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}
steps:
- id: setup-matrix
uses: druzsan/setup-matrix@v2
with:
matrix: |
civicrm: ${{ env.CIVI_CI_CIVICRM }}
mysql: ${{ env.CIVI_CI_MYSQL }}
os: ${{ env.CIVI_CI_OS }}
php: ${{ env.CIVI_CI_PHP }}
build-type: ${{ env.CIVI_CI_BUILD_TYPE }}
exclude: ${{ env.CIVI_CI_EXCLUDES }}
run-tests:
needs: setup-matrix
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
runs-on: "${{ matrix.os }}"

services:
mysql:
image: "mysql:${{ matrix.mysql }}"
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- "3306:3306"
options: >-
--health-cmd="mysqladmin ping"
--health-interval="10s"
--health-timeout="5s"
--health-retries="3"
steps:
- id: clone-repo
name: "Clone the repository"
uses: "actions/checkout@v4"
with:
path: "at.greenpeace.mailingwork"
- id: build-ci
uses: greenpeace-cee/civi-ci@main
with:
extension: at.greenpeace.mailingwork
civicrm: ${{ matrix.civicrm }}
php: ${{ matrix.php }}
build-type: ${{ matrix.build-type }}
- id: install-extension
name: "Install Extension"
env:
EXT_DIR: ${{ steps.build-ci.outputs.ext-dir }}
run: |
PATH="/home/runner/buildkit/bin:$PATH"
cd "$EXT_DIR"
cp -R "$GITHUB_WORKSPACE/at.greenpeace.mailingwork" "$EXT_DIR/at.greenpeace.mailingwork"
git clone https://github.com/systopia/de.systopia.identitytracker.git "$EXT_DIR/de.systopia.identitytracker"
composer install --working-dir="$EXT_DIR/at.greenpeace.mailingwork"
cv en at.greenpeace.mailingwork
- id: run-tests
name: "Run Tests"
env:
EXT_DIR: ${{ steps.build-ci.outputs.ext-dir }}
run: |
PATH="/home/runner/buildkit/bin:$PATH"
cd "$EXT_DIR/at.greenpeace.mailingwork"
CIVICRM_UF="UnitTests" phpunit9
24 changes: 12 additions & 12 deletions CRM/Mailingwork/Processor/Greenpeace/Clicks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function import() {
'completed' => $this->getOrCreateOptionValue('mailingwork_mailing_sync_status', 'completed'),
];

$mailingQuery = Api4\MailingworkMailing::get()
$mailingQuery = Api4\MailingworkMailing::get(FALSE)
->addSelect('*', 'click_sync_status_id:name')
->addWhere('recipient_sync_status_id', 'IN', [
$syncStatuses['in_progress'],
Expand Down Expand Up @@ -84,7 +84,7 @@ public function import() {
private function getActivityContactID(int $mailingID, int $contactID) {
$activityTargetOptValue = $this->getOrCreateOptionValue('activity_contacts', 'Activity Targets');

$activityQuery = Api4\Activity::get()
$activityQuery = Api4\Activity::get(FALSE)
->addSelect('activity_contact.id')
->addJoin(
'ActivityContact AS activity_contact', 'INNER', ['id', '=', 'activity_contact.activity_id']
Expand Down Expand Up @@ -152,7 +152,7 @@ private function importMailingClicks(array $mailing) {
if (self::isDuplicateClick($click->date, $activityContactID, $linkID)) {
Civi::log()->info('[Mailingwork/Clicks] Found click with existing MailingworkClick, skipping');
} else {
Api4\MailingworkClick::create()
Api4\MailingworkClick::create(FALSE)
->addValue('activity_contact_id', $activityContactID)
->addValue('click_date', $click->date)
->addValue('link_id', $linkID)
Expand Down Expand Up @@ -189,15 +189,15 @@ private function importMailingLinks($mailing) {

foreach ($links as $link) {

$linksQuery = Api4\MailingworkLink::get()
$linksQuery = Api4\MailingworkLink::get(FALSE)
->addSelect('id')
->addWhere('mailing_id', '=', $mailing['id'])
->addWhere('mailingwork_id', '=', $link->id)
->setLimit(1)
->execute();

if ($linksQuery->count() < 1) {
$createdLink = Api4\MailingworkLink::create()
$createdLink = Api4\MailingworkLink::create(FALSE)
->addValue('mailing_id', $mailing['id'])
->addValue('mailingwork_id', $link->id)
->addValue('url', $link->url)
Expand All @@ -214,7 +214,7 @@ private function importMailingLinks($mailing) {

private function importLinkInterests(int $linkID, array $interests) {
foreach ($interests as $interest) {
$linkInterestsQuery = Api4\MailingworkLinkInterest::get()
$linkInterestsQuery = Api4\MailingworkLinkInterest::get(FALSE)
->addJoin(
'MailingworkInterest AS mailingwork_interest',
'LEFT',
Expand All @@ -227,7 +227,7 @@ private function importLinkInterests(int $linkID, array $interests) {

if ($linkInterestsQuery->count() > 0) continue;

$interestsQuery = Api4\MailingworkInterest::get()
$interestsQuery = Api4\MailingworkInterest::get(FALSE)
->addSelect('id')
->addWhere('mailingwork_id', '=', $interest->id)
->setLimit(1)
Expand All @@ -237,7 +237,7 @@ private function importLinkInterests(int $linkID, array $interests) {
$interestID = $interestExists ? $interestsQuery->first()['id'] : NULL;

if (!$interestExists) {
$createdInterest = Api4\MailingworkInterest::create()
$createdInterest = Api4\MailingworkInterest::create(FALSE)
->addValue('mailingwork_id', $interest->id)
->addValue('name', $interest->name)
->execute()
Expand All @@ -246,7 +246,7 @@ private function importLinkInterests(int $linkID, array $interests) {
$interestID = $createdInterest['id'];
}

$createLinkInterestResult = Api4\MailingworkLinkInterest::create()
$createLinkInterestResult = Api4\MailingworkLinkInterest::create(FALSE)
->addValue('interest_id', $interestID)
->addValue('link_id', $linkID)
->execute();
Expand All @@ -270,22 +270,22 @@ private function updateMailingClickSyncStatus(int $mailingID, string $lastClickD
'in_progress'
);

Api4\MailingworkMailing::update()
Api4\MailingworkMailing::update(FALSE)
->addWhere('id', '=', $mailingID)
->addValue('click_sync_date', $lastClickDate)
->addValue('click_sync_status_id', $statusInProgress)
->execute();
}

private static function setMailingClicksCompleted($mailingID) {
Api4\MailingworkMailing::update()
Api4\MailingworkMailing::update(FALSE)
->addValue('click_sync_status_id:name', 'completed')
->addWhere('id', '=', $mailingID)
->execute();
}

private static function isDuplicateClick($clickDate, $activityContactID, $linkID) {
$count = Api4\MailingworkClick::get()
$count = Api4\MailingworkClick::get(FALSE)
->addWhere('activity_contact_id', '=', $activityContactID)
->addWhere('click_date', '=', $clickDate)
->addWhere('link_id', '=', $linkID)
Expand Down
6 changes: 3 additions & 3 deletions CRM/Mailingwork/Processor/Greenpeace/Openings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ private function importMailingOpenings($mailing) {
Civi::log()->warning('[Mailingwork/Openings] Ignoring opening without matching activity');
continue;
}
$dupeOpening = MailingworkOpening::get()
$dupeOpening = MailingworkOpening::get(FALSE)
->addSelect('id')
->addWhere('activity_contact_id', '=', $parent_activity['activity_contact_id'])
->addWhere('opening_date', '=', $opening['date'])
->execute()
->first();
if (!empty($dupeOpening)) {
Civi::log()->info('[Mailingwork/Openings] Found opening with existing MailingworkOpening, merging');
$apiOpening = MailingworkOpening::update()
$apiOpening = MailingworkOpening::update(FALSE)
->addWhere('id', '=', $dupeOpening['id']);
}
else {
$apiOpening = MailingworkOpening::create();
$apiOpening = MailingworkOpening::create(FALSE);
$stored_count++;
}
$apiOpening->addValue('activity_contact_id', $parent_activity['activity_contact_id'])
Expand Down
9 changes: 4 additions & 5 deletions CRM/Mailingwork/Processor/Greenpeace/Optouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function removeGroups(array $contacts, array $groups_to_remove, array $o
->addValue('optout_information.optout_item', $optout[self::EMAIL_FIELD])
->addValue('subject', "Opt-Out from \"{$group_title}\" via Mailingwork")
->addValue('source_record_id', $groupContact['group_id'])
->addChain('activity_contact', ActivityContact::create()
->addChain('activity_contact', ActivityContact::create(FALSE)
->addValue('activity_id', '$id')
->addValue('contact_id', $groupContact['contact_id'])
->addValue('record_type_id', 3)
Expand Down Expand Up @@ -204,7 +204,7 @@ private function setSuppression(array $contacts, $suppression, array $optout, ar
$suppressedContacts = Contact::get(FALSE)
->addWhere('id', 'IN', $contacts)
->addWhere($suppression, '=', 0)
->addChain('set_suppression', Contact::update()
->addChain('set_suppression', Contact::update(FALSE)
->addWhere('id', '=', '$id')
->addValue($suppression, 1)
)
Expand Down Expand Up @@ -235,7 +235,7 @@ private function setSuppression(array $contacts, $suppression, array $optout, ar
->addValue('optout_information.optout_identifier', $mailing['id'])
->addValue('optout_information.optout_item', $optout[self::EMAIL_FIELD])
->addValue('subject', "Added \"{$suppression_title}\" via Mailingwork")
->addChain('activity_contact', ActivityContact::create()
->addChain('activity_contact', ActivityContact::create(FALSE)
->addValue('activity_id', '$id')
->addValue('contact_id', $contact['id'])
->addValue('record_type_id', 3)
Expand Down Expand Up @@ -265,9 +265,8 @@ private function setSuppression(array $contacts, $suppression, array $optout, ar
}

private function prepareGroupCache() {
$groups = Group::get()
$groups = Group::get(FALSE)
->addSelect('id', 'title')
->setCheckPermissions(FALSE)
->execute();
foreach ($groups as $group) {
$this->groups[$group['id']] = $group['title'];
Expand Down
Loading

0 comments on commit df1cdf5

Please sign in to comment.