diff --git a/pantheon.yml b/pantheon.yml index d94f16a1..919c1b50 100644 --- a/pantheon.yml +++ b/pantheon.yml @@ -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 diff --git a/private/scripts/multidev_alert/alert.php b/private/scripts/multidev_alert/alert.php new file mode 100755 index 00000000..c2fd1784 --- /dev/null +++ b/private/scripts/multidev_alert/alert.php @@ -0,0 +1,126 @@ +checkMail(); +$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 checkMail() + { + if (function_exists('mail')) { + echo( 'mail() is available' . PHP_EOL ); + } else { + echo( 'mail() has been disabled' . PHP_EOL ); + } + } + + 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 ); + $email = 'miriamgoldman@pantheon.io'; + $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); + + echo( 'Message: ' . $message . PHP_EOL ); + + if ($sendMail) { + echo( 'Email Sent Successfully' . PHP_EOL) ; + } else { + echo( 'Mail Failed' ); + } + echo( '$_ENV array output:' . PHP_EOL ); + var_dump($_ENV); + } + + /** + * 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; + } + } +}