Skip to content

Commit

Permalink
SS5 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rafatairnz authored and Shane Watters committed Apr 21, 2024
1 parent 6f36ceb commit ab79555
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 83 deletions.
1 change: 0 additions & 1 deletion _config/ubiquity.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
Name: ubiquityconfig
---

SilverStripe\SiteConfig\SiteConfig:
extensions:
- Ubiquity\Extensions\UbiquitySiteConfigExtension
Expand Down
22 changes: 10 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dnadesign/silverstripe-ubiquity",
"description": "Implements Ubiquity extensions for User Defined Forms",
"type": "silverstripe-vendormodule",
"type": "silverstripe-module",
"keywords": ["silverstripe", "ubiquity", "newsletter"],
"license": "MIT",
"authors": [{
Expand All @@ -10,16 +10,14 @@
}],
"minimum-stability": "dev",
"require": {
"silverstripe/framework": "^4",
"silverstripe/cms": "^4",
"silverstripe/userforms": "^5",
"symbiote/silverstripe-gridfieldextensions": "^3",
"silverstripe/display-logic" : "^2"
"silverstripe/framework": "^5",
"silverstripe/cms": "^5",
"silverstripe/userforms": "^6"
},
"require-dev": {
"phpunit/phpunit": "7.5.x"
},
"extra": {
"installer-name": "silverstripe-ubiquity"
}
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"extra": {
"installer-name": "silverstripe-ubiquity"
}
}
1 change: 0 additions & 1 deletion src/Extensions/UbiquityEditableFormFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Ubiquity\Extensions;

use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
Expand Down
1 change: 0 additions & 1 deletion src/Extensions/UbiquityEditableOptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Ubiquity\Extensions;

use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
Expand Down
34 changes: 31 additions & 3 deletions src/Extensions/UbiquityFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,41 @@ public function updateCMSFields(FieldList $fields)
->setEmptyString('-- Select one --');

// Ubiquity allows submitting data to a form as well, usually tied to the Ubiquity database
$formID = TextField::create('UbiquityFormID', 'Ubiquity Form ID')
->setDescription('ID of the form used to send the data to.');
// By populating the Sucess Form ID, you can automatically trigger an email response to
// be sent to the user, as if the Form was submitted directly.
$formID = TextField::create('UbiquitySuccessFormID', 'Ubiquity Success Form ID')
->setDescription('ID of the form that will be used to send confirmation email once the user has signed up.');

// To trigger emails of the form, you must define which field the form needs to have the email sent.
$formFieldID = TextField::create('UbiquitySuccessFormEmailTriggerID', 'Ubiquity Success Form Field ID')
->setDescription('ID of the field that will be used to send the form action (ususally named EmailTrigger)');

// Ubiquity forms can send different emails, define the Action that will send the email
$formAction = TextField::create('UbiquitySuccessFormAction', 'Ubiquity Success Form Action')
->setDescription('Name of the Email that should be sent.');

// Allows Ubiquity to track the soure of the submission, eg newsletter signup, event form, feedback form
// Define the FieldID of the Ubiquity Field
$sourceID = TextField::create('UbiquitySourceFieldID', 'Ubiquity Source Field ID')
->setDescription('ID of the field that will be use as primary source for the user.');

// Define the Name of the source to populate the above field
$sourceName = TextField::create('UbiquitySourceName', 'Ubiquity Source Name')
->setDescription('Reference of this form as source.');

// Submit the source even if a T&C's field is included yet is not checked
$submitSource = CheckboxField::create('UbiquitySubmitSource', 'Submit Source')
->setDescription('Submit the source data even if a T&C\'s field exists but is not ticked');

$fields->addFieldsToTab('Root.Ubiquity', [
$enabled,
$database,
$formID
$formID,
$formFieldID,
$formAction,
$sourceID,
$sourceName,
$submitSource
]);
}
}
3 changes: 1 addition & 2 deletions src/Extensions/UbiquityMultipleOptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function updateCMSFields(FieldList $fields)
'callback' => function ($record, $column, $grid) {
return TextField::create($column);
}
],
],
'AllowOverride' => [
'title' => 'Allow Override Ubiquity DB',
'callback' => function ($record, $column, $grid) {
Expand Down
9 changes: 8 additions & 1 deletion src/Extensions/UbiquityUserFormControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Ubiquity\Extensions;

use SilverStripe\Control\Director;
use SilverStripe\Core\Extension;

namespace Ubiquity\Extensions;

use Exception;
use Psr\Log\LoggerInterface;
use SilverStripe\Control\Director;
Expand Down Expand Up @@ -106,7 +111,7 @@ public function formatData()
->Fields()
->exclude('UbiquityFieldID', ['', NULL]);

// not all fields are set to update ubiquity
// not fields are set to update ubiquity
if (empty($fields)) {
return $data;
}
Expand Down Expand Up @@ -212,5 +217,7 @@ public function exitWithError(Exception $e)
}

Injector::inst()->get(LoggerInterface::class)->error($e->getMessage());
SS_Log::log($e->getMessage(), SS_Log::WARN);
exit();
}
}
1 change: 0 additions & 1 deletion src/Forms/EditableSignupField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Ubiquity\Forms\Fields;

use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/UbiquityDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class UbiquityDatabase extends DataObject
{
private static $table_name = 'UbiquityDatabase';
private static $table_name = "UbiquityDatabase";

private static $db = [
'Title' => 'Varchar(255)',
Expand Down
106 changes: 106 additions & 0 deletions src/Services/UbiquityService.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<?php
namespace Ubiquity\Services;

namespace Ubiquity\Services;

use Exception;
use GuzzleHttp\Client;
<<<<<<< HEAD
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\ArrayList;
use SilverStripe\SiteConfig\SiteConfig;
use Ubiquity\Models\UbiquityDatabase;
=======
use SilverStripe\Core\Config\Config;
use SilverStripe\SiteConfig\SiteConfig;
>>>>>>> 9ffaf6d (SS5 upgrade)

class UbiquityService
{
Expand Down Expand Up @@ -165,7 +171,11 @@ public function call($method = null, string $uri = null, $query = null, $data =

$options = $this->getDefaultOptions();

<<<<<<< HEAD
if ($query && is_array($query)) {
=======
if ($query) {
>>>>>>> 9ffaf6d (SS5 upgrade)
$options['query'] = array_merge($options['query'], $query);
}

Expand Down Expand Up @@ -194,7 +204,11 @@ public function getContact($params)
}

// get the email address submitted
<<<<<<< HEAD
$email = (isset($params['value'])) ? $params['value'] : null;
=======
$email = (isset($emailData['value'])) ? $emailData['value'] : null;
>>>>>>> 9ffaf6d (SS5 upgrade)

// check the email address is valid
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
Expand All @@ -205,6 +219,10 @@ public function getContact($params)
'filter' => $this->buildFilterQueryString(array($params))
];

<<<<<<< HEAD
=======
//self::get()?
>>>>>>> 9ffaf6d (SS5 upgrade)
$response = $this->call(self::METHOD_GET, 'database/contacts', $query);

if ($response->getStatusCode() !== 200) {
Expand Down Expand Up @@ -252,6 +270,59 @@ public function getEmailData(array $data)
}

/**
<<<<<<< HEAD
=======
* @param $fields SS_List list of fields assigned an ubiquity ID
* @param $options SS_List list of EditableOption assigned an ubiquity ID
* @param $data Array submitted data (merged with source data)
*/
public function createOrUpdateContact($data)
{
// Check if contact already exists given the email form field
$emailData = $this->getEmailData($data);

$contact = $this->getContact($emailData);

$uri = 'database/contacts';

if ($contact) {
// update an existing contact
$id = $contact['referenceID'];
$uri .= '/' . $id;
$data = $this->filterUpdateData($data, $contact);
$method = self::METHOD_PUT;
} else {
$method = self::METHOD_POST;
}

// If there is no data to update, exit here
if (empty($data)) {
return true;
}

$response = $this->call($method, $uri, null, $data);

if ($contact) {
if ($response->getStatusCode() !== 200) {
throw new Exception('An ubiquity API error occured (update)');
}

$result = $this->decodeResponse($response);

// creating a new contect needs to return the referenceID
return $result['referenceID'];
} else {
if ($response->getStatusCode() !== 201) {
throw new Exception('An ubiquity API error occured (c)reate');
}

// updating an existing contact needs to return true if successful
return true;
}
}

/**
>>>>>>> 9ffaf6d (SS5 upgrade)
* Send data to a Ubiquity Form
* Usually to trigger an email being sent from their end.
*/
Expand Down Expand Up @@ -333,4 +404,39 @@ public function filterUpdateData($data, $contact)

return array_values($updatedData);
}
<<<<<<< HEAD
=======

/**
* Determine if ubiquity analytis is enabled
*
* @return boolean
*/
public static function get_ubiquity_analytics_enabled()
{
return SiteConfig::current_site_config()->UbiquityAnalyticsEnabled;
}

/**
* Helper to get the Analytics keys
*/
public static function get_analytics_keys()
{
$analyticsKeys = [];

if (!self::get_ubiquity_analytics_enabled()) {
return $analyticsKeys;
}

$keys = Config::inst()->get('UbiquityService', 'analytics_keys');

if ($keys && is_array($keys)) {
foreach ($keys as $key) {
array_push($analyticsKeys, ['Key' => $key]);
}
}

return $analyticsKeys;
}
>>>>>>> 9ffaf6d (SS5 upgrade)
}
59 changes: 0 additions & 59 deletions src/Tasks/SS4UbiquityMigrationTask.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Tasks/UbiquityFieldsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use SilverStripe\Dev\BuildTask;
use Ubiquity\Models\UbiquityDatabase;
use Ubiquity\Services\UbiquityService;

class UbiquityFieldsList extends BuildTask
{
Expand Down

0 comments on commit ab79555

Please sign in to comment.