Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing out edmund qs #9

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#1f6fd0",
"activityBar.background": "#1f6fd0",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#ee90bb",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#1f6fd0",
"statusBar.background": "#1857a4",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#1f6fd0",
"statusBarItem.remoteBackground": "#1857a4",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#1857a4",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#1857a499",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#1857a4"
}
7 changes: 7 additions & 0 deletions pantheon.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Put overrides to your pantheon.upstream.yml file here.
# For more information, see: https://pantheon.io/docs/pantheon-yml/
api_version: 1

workflows:
sync_code:
after:
- type: webphp
description: Test mail function.
script: private/scripts/multidev_alert/alert.php
119 changes: 119 additions & 0 deletions private/scripts/multidev_alert/alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/** QuickSilver script to notify NUS in the event of a multidev naming policy breach
*
* https://github.com/pantheon-systems/quicksilver-examples/blob/main/google_chat_notification/google_chat_notification.php
*
* @package MultidevPolicyAlert
*/

namespace QSAlert;

$qs_alert = new MultidevPolicyAlert();
$qs_alert->sendMail();

class MultidevPolicyAlert
{

public $site_name;
public $site_id;
public $site_env;

public function __construct()
{
$this->setQuicksilverVariables();
}

/**
* Set Quicksilver variables from ENV data.
*
* @return void
*/
public function setQuicksilverVariables()
{
$this->site_name = $this->getPantheonSiteName();
$this->site_id = $this->getPantheonSiteId();
$this->site_env = $this->getPantheonEnvironment();
}


/**
* Get the Pantheon site name.
*
* @return string|null
*/
public function getPantheonSiteName(): ?string
{
return ! empty($_ENV['PANTHEON_SITE_NAME']) ? $_ENV['PANTHEON_SITE_NAME'] : null;
}

/**
* Get the Pantheon siteId.
*
* @return string|null
*/
public function getPantheonSiteId(): ?string
{
return ! empty($_ENV['PANTHEON_SITE']) ? $_ENV['PANTHEON_SITE'] : null;
}
/**
* Get the Pantheon environment.
*
* @return string|null
*/
public function getPantheonEnvironment(): ?string
{
return ! empty($_ENV['PANTHEON_ENVIRONMENT']) ? $_ENV['PANTHEON_ENVIRONMENT'] : null;
}

/**
* Check if in the Quicksilver context.
*
* @return bool|void
*/
public function isQuicksilver()
{
if ($this->isPantheon() && ! empty($_POST['wf_type'])) {
return true;
}
die('No Pantheon Quicksilver environment detected.');
}

public function sendMail()
{
echo( 'Site ID ' . $this->site_id . PHP_EOL );
echo( 'Environment Name ' .$this->site_env . PHP_EOL );
echo( 'Site Name ' .$this->site_name . PHP_EOL );
$headers = [
'From' => 'WordPress <[email protected]>',
'X-Mailer' => 'PHP/' . phpversion(),
'Content-Type' => 'text/html; charset=UTF-8'
];
$email = '[email protected]';
$subject = "Code sync on $this->site_env Completed";
$message = "Code sync on $this->site_env has been created for the site $this->site_name with the SiteID $this->site_id";

$sendMail = mail($email, $subject, $message, $headers);


if ($sendMail) {
echo( 'Email Sent Successfully' . PHP_EOL) ;
} else {
echo( 'Mail Failed' );
}

}

/**
* Determine naming convention breach.
*
* @param string $site_env The environment name of the multidev
*/
public function namingConventionBreach(string $site_env)
{
if (preg_match('/^lando/', $site_env, $output_array)) {
return true;
} else {
return false;
}
}
}
Loading