Skip to content

Commit

Permalink
Merge PROJ-2779 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Aug 23, 2023
2 parents 46e61bd + 8e9a5fe commit 8ab93f4
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 191 deletions.
108 changes: 15 additions & 93 deletions CRM/Zoomzoom/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class CRM_Zoomzoom_Upgrader extends CRM_Zoomzoom_Upgrader_Base {

/**
* Example: Run an external SQL script when the module is installed.
*
public function install() {
$this->executeSqlFile('sql/myinstall.sql');
}
*/
// public function install() {
// $this->executeSqlFile('sql/myinstall.sql');
// }

/**
* Example: Work with entities usually not available during the install step.
Expand All @@ -24,15 +24,9 @@ public function install() {
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*/
// public function postInstall() {
// $customFieldId = civicrm_api3('CustomField', 'getvalue', array(
// 'return' => array("id"),
// 'name' => "customFieldCreatedViaManagedHook",
// ));
// civicrm_api3('Setting', 'create', array(
// 'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
// ));
// }
public function postInstall() {
CRM_Civirules_Utils_Upgrader::insertActionsFromJson(E::path('civirules.json'));
}

/**
* Example: Run an external SQL script when the module is uninstalled.
Expand All @@ -41,12 +35,9 @@ public function install() {
// $this->executeSqlFile('sql/myuninstall.sql');
// }

/**
* Example: Run a simple query when a module is enabled.
*/
// public function enable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
// }
public function enable() {
CRM_Civirules_Utils_Upgrader::insertActionsFromJson(E::path('civirules.json'));
}

/**
* Example: Run a simple query when a module is disabled.
Expand All @@ -55,81 +46,12 @@ public function install() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
// }

/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4200() {
// $this->ctx->log->info('Applying update 4200');
// CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
// CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
// return TRUE;
// }


/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4201() {
// $this->ctx->log->info('Applying update 4201');
// // this path is relative to the extension base dir
// $this->executeSqlFile('sql/upgrade_4201.sql');
// return TRUE;
// }


/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4202() {
// $this->ctx->log->info('Planning update 4202'); // PEAR Log interface

// $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
// $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
// $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
// return TRUE;
// }
// public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
// public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
// public function processPart3($arg5) { sleep(10); return TRUE; }
public function upgrade_10800() {
$this->ctx->log->info('Installing CiviRules Actions');

/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4203() {
// $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
CRM_Civirules_Utils_Upgrader::insertActionsFromJson(E::path('civirules.json'));

// $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
// $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
// for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
// $endId = $startId + self::BATCH_SIZE - 1;
// $title = E::ts('Upgrade Batch (%1 => %2)', array(
// 1 => $startId,
// 2 => $endId,
// ));
// $sql = '
// UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
// WHERE id BETWEEN %1 and %2
// ';
// $params = array(
// 1 => array($startId, 'Integer'),
// 2 => array($endId, 'Integer'),
// );
// $this->addTask($title, 'executeSql', $sql, $params);
// }
// return TRUE;
// }
return TRUE;
}

}
48 changes: 32 additions & 16 deletions CRM/Zoomzoom/Zoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

//https://marketplace.zoom.us/docs/api-reference/zoom-api/

use CRM_Zoomzoom_ExtensionUtil as E;

class CRM_Zoomzoom_Zoom {
static $zoom;

/**
* Initialise a Zoom object for API calls
*
* @return ZoomAPIWrapper|null
*/
static function getZoomObject() {
static $zoom;
if (is_null(self::$zoom)) {
$accountID = Civi::settings()->get('zoom_account_id');
$clientKey = Civi::settings()->get('zoom_client_key');
$clientSecret = Civi::settings()->get('zoom_client_secret');

if (!is_null($zoom)) {
return $zoom;
}
if (empty($clientKey) || empty($clientSecret)) {
return NULL;
}

$apiKey = Civi::settings()->get('zoom_api_key');
$apiSecret = Civi::settings()->get('zoom_api_secret');
require_once E::path('packages/ZoomAPIWrapper/ZoomAPIWrapper.php');

if (empty($apiKey) || empty($apiSecret)) {
return NULL;
self::$zoom = ZoomAPIWrapper::init($accountID, $clientKey, $clientSecret);
}

$extPath = Civi::resources()
->getPath(CRM_Zoomzoom_ExtensionUtil::LONG_NAME);
require_once $extPath . '/packages/ZoomAPIWrapper/ZoomAPIWrapper.php';

$zoom = new ZoomAPIWrapper($apiKey, $apiSecret);

return $zoom;

return self::$zoom;
}

/**
* Get the Zoom account owner for the current Zoom JWT
*
* OAuth scopes required: user:read:admin
*
* @return mixed
*/
Expand Down Expand Up @@ -66,6 +66,8 @@ static function getOwner() {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinars
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetings
*
* OAuth scopes required: {webinar,meeting}:read:admin
*
* @param string $api use values: meeting, webinar
* @param int $day_offset
Expand Down Expand Up @@ -113,6 +115,8 @@ static function getZooms($api, $day_offset = 0) {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarcreate
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate
*
* OAuth scopes required: {webinar,meeting}:write:admin
*
* @param string $params see Zoom documentation for parameters
*
Expand Down Expand Up @@ -162,6 +166,8 @@ static function createZoom($api, $params) {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarabsentees
* No Zoom API implementation for Meetings
*
* OAuth scopes required: webinar:read:admin
*
* @param string $api options meeting, webinar
* @param string $zoom_id Zoom ID
Expand Down Expand Up @@ -218,6 +224,8 @@ static function getAbsentees($zoom_id) {
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/pastmeetingparticipants
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/listwebinarparticipants
*
* OAuth scopes required: {webinar,meeting}:read:admin
*
* @param string $api options meeting, webinar
* @param string $zoom_id Zoom ID
*
Expand Down Expand Up @@ -433,6 +441,8 @@ static function getZoomIDFromCiviCRMZoomId($civicrm_zoom_id) {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarregistrantcreate
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingregistrantcreate
*
* OAuth scopes required: {webinar,meeting}:write:admin
*
* @param string $civicrm_zoom_id Zoom ID in format of m1234567 or
* w1234567
Expand Down Expand Up @@ -472,6 +482,8 @@ static function createZoomRegistration($civicrm_zoom_id, $participant_id, $param
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/deletewebinarregistrant
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingregistrantdelete
*
* OAuth scopes required: {webinar,meeting}:write:admin
*
* @param string $civicrm_zoom_id Zoom ID in format of m1234567 or
* w1234567
* @param string $registrant_id the Zoom Registrant ID
Expand All @@ -495,6 +507,8 @@ static function deleteZoomRegistration($civicrm_zoom_id, $registrant_id) {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingupdate
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarupdate
*
* OAuth scopes required: {webinar,meeting}:write:admin
*
* @param $civicrm_zoom_id Zoom ID in format of m1234567 or w1234567
* @param $params array values for the Zoom
Expand Down Expand Up @@ -528,6 +542,8 @@ static function updateZoom($civicrm_zoom_id, $params) {
* Zoom API documentation:
* https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingdelete
* https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinardelete
*
* OAuth scopes required: {webinar,meeting}:write:admin
*
* @param $civicrm_zoom_id Zoom ID in format of m1234567 or w1234567
*
Expand Down
84 changes: 59 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
# Zoom Zoom (au.com.agileware.zoomzoom)

This is just another [CiviCRM](https://civicrm.org) extension which integrates with [Zoom](https://zoom.us). Provides the following features:
This is just another [CiviCRM](https://civicrm.org) extension which integrates with
[Zoom](https://zoom.us). Provides the following features:

* CiviRule to create Zoom Webinar from Event and create Zoom Meeting from Event
* CiviRule to update Zoom details
* CiviRule to delete a Zoom
* CiviRule to add an Event Participant to a Zoom
* CiviRule to add an Event Participant to a Zoom
* CiviRule to delete a Participant from a Zoom
* Scheduled Job to import Zoom Webinars and Zoom Events as CiviCRM Events
* Scheduled Job to check CiviCRM Events linked to Zoom and import the Zoom registrations, attendees and absentees. Record as CiviCRM Participants and update Participant Status.
* Scheduled Job to import Zoom Webinars and Zoom Events as CiviCRM
Events
* Scheduled Job to check CiviCRM Events linked to Zoom and import the
Zoom registrations, attendees and absentees. Record as CiviCRM
Participants and update Participant Status.

The extension is licensed under [AGPL-3.0](LICENSE.txt).

## Getting Started
## Migrating from a JWT App

JWT Apps are deprecated on Zoom, so to ensure continued function this app has been converted to use
OAuth Server-to-Server. Existing installations configured to use a JWT App will need to create
and connect to a new app according to the instructions in the [Getting Started](#getting-started)
section below.

* Zoom JWT API credentials are required for this CiviCRM Extension. Create a Zoom JWT App in the [Zoom Marketplace](https://marketplace.zoom.us/develop/create).
* Ensure that the Zoom Account used for the Zoom JWT App has permissions to read/write Zooms. For more details read, [Zoom API, JSON Web Tokens (JWT)](https://marketplace.zoom.us/docs/guides/auth/jwt)
* In CiviCRM, go to the Zoom Settings page, Administer > Zoom Settings.
* Insert the **Zoom JWT API Key** and **Zoom JWT API Secret**.
* Set the other options on the Zoom Settings page, as required.
## Getting Started

* The following **Scheduled Jobs** are provided:
* **Import Zoom Webinars and Meetings** - Enable this Scheduled Job if you want to create CiviCRM Events from Zooms. Specify a day offset to process _Zooms_ with a start date either in the last X days (by providing a negative number) or from a future date. The default day_offset is -90 which will process Zooms with a start date in the last 90 days.
* **Import Zoom Registrations, Attendees, Absentees** - Enable this Scheduled Job if you want to create CiviCRM Participant records in CiviCRM from Zoom registrations, attendance and absentees. This job will only process CiviCRM Events which are linked to a Zoom. Specify a day offset to process _Events_ with a start date either in the last X days (by providing a negative number) or from a future date. The default day_offset is -90 which will process Events with a start date in the last 90 days. _Note: As this Scheduled Job checks CiviCRM Events linked to a Zoom, it is a good idea to run this job **after** the **Import Zoom Webinars and Meetings** job_.
1. Zoom OAuth Server-to-Server credentials are required for this Integration. Create an OAuth
Server-to-Server App in the [Zoom Marketplace](https://marketplace.zoom.us/develop/create).
1. Fill in the App Details
2. Move through to the Scopes tab and ensure that the App has the appropriate scope permissions:
* **View all user meetings** /meeting:read:admin
* **View and manage all user meetings** /meeting:write:admin
* **View all user information** /user:read:admin
* **View all user Webinars** /webinar:read:admin
* **View and manage all user Webinars** /webinar:write:admin
![Screenshot of appropriate scope configuration](images/zoom-app-scopes.png)
3. Continue to Activation and Activate your app
4. Load the App Credentials tab to get the **Account ID**, **Client ID** and **Client Secret**
2. In CiviCRM, go to the Zoom Settings page, Administer / Zoom Settings.
* Insert the **Account ID**, **Client ID** and **Client Secret** from above.
* Set the other options on the Zoom Settings page, as required.
3. The following **Scheduled Jobs** are provided:
* **Import Zoom Webinars and Meetings** - Enable this Scheduled Job if you want to create CiviCRM
Events from Zooms. Specify a day offset to process _Zooms_ with a start date either in the last
X days (by providing a negative number) or from a future date. The default day_offset is -90
which will process Zooms with a start date in the last 90 days.
* **Import Zoom Registrations, Attendees, Absentees** - Enable this Scheduled Job if you want to
create CiviCRM Participant records in CiviCRM from Zoom registrations, attendance and
absentees. This job will only process CiviCRM Events which are linked to a Zoom. Specify a day
offset to process _Events_ with a start date either in the last X days (by providing a negative
number) or from a future date. The default day_offset is -90 which will process Events with a
start date in the last 90 days. _Note: As this Scheduled Job checks CiviCRM Events linked to a
Zoom, it is a good idea to run this job **after** the **Import Zoom Webinars and Meetings**
job_.

## Credits and acknowledgements

Credit to Lighthouse Consulting and Design, Inc for developing [https://github.com/lcdservices/biz.lcdservices.civizoom](https://github.com/lcdservices/biz.lcdservices.civizoom) which was used as the basis for this new extension.
Credit to Veda Consulting for developing [https://github.com/veda-consulting-company/ncn-civi-zoom](https://github.com/veda-consulting-company/ncn-civi-zoom) which was used as reference for the CiviRules implementation.
Credit to Lighthouse Consulting and Design, Inc for developing
[https://github.com/lcdservices/biz.lcdservices.civizoom](https://github.com/lcdservices/biz.lcdservices.civizoom)
which was used as the basis for this new extension. Credit to Veda Consulting for developing
[https://github.com/veda-consulting-company/ncn-civi-zoom](https://github.com/veda-consulting-company/ncn-civi-zoom)
which was used as reference for the CiviRules implementation.

## Requirements

Expand All @@ -36,12 +69,13 @@ Credit to Veda Consulting for developing [https://github.com/veda-consulting-com

## Installation (Web UI)

Learn more about installing CiviCRM extensions in the [CiviCRM Sysadmin Guide](https://docs.civicrm.org/sysadmin/en/latest/customize/extensions/).
Learn more about installing CiviCRM extensions in the [CiviCRM Sysadmin
Guide](https://docs.civicrm.org/sysadmin/en/latest/customize/extensions/).

## Installation (CLI, Zip)

Sysadmins and developers may download the `.zip` file for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
Sysadmins and developers may download the `.zip` file for this extension and install it with the
command-line tool [cv](https://github.com/civicrm/cv).

```bash
cd <extension-dir>
Expand All @@ -50,8 +84,8 @@ cv dl au.com.agileware.zoomzoom@https://github.com/agileware/au.com.agileware.zo

## Installation (CLI, Git)

Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this
extension and install it with the command-line tool [cv](https://github.com/civicrm/cv).

```bash
git clone https://github.com/agileware/au.com.agileware.zoomzoom.git
Expand All @@ -63,8 +97,8 @@ cv en zoomzoom
This CiviCRM extension was developed by the team at
[Agileware](https://agileware.com.au).

[Agileware](https://agileware.com.au) provide a range of CiviCRM services
including:
[Agileware](https://agileware.com.au) provide a range of CiviCRM
services including:

* CiviCRM migration
* CiviCRM integration
Expand All @@ -73,7 +107,7 @@ including:
* CiviCRM hosting
* CiviCRM remote training services

Support your Australian [CiviCRM](https://civicrm.org) developers, [contact
Agileware](https://agileware.com.au/contact) today!
Support your Australian [CiviCRM](https://civicrm.org) developers,
[contact Agileware](https://agileware.com.au/contact) today!

![Agileware](logo/agileware-logo.png)
![Agileware](logo/agileware-logo.png)
Binary file added images/zoom-app-scopes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ab93f4

Please sign in to comment.