diff --git a/bluem.php b/bluem.php index 1b2e530..43627ac 100644 --- a/bluem.php +++ b/bluem.php @@ -38,6 +38,7 @@ require __DIR__ . '/vendor/autoload.php'; use Bluem\BluemPHP\Bluem; +use Bluem\Wordpress\Observability\BluemActivationNotifier; use Bluem\Wordpress\Observability\SentryLogger; @@ -358,7 +359,8 @@ function bluem_plugin_activation() { $bluem_registration['tech_contact']['email'] = $tech_email; // Sent registration notify email - bluem_registration_report_email(); + (new BluemActivationNotifier())->reportActivatedPlugin(); + // Update Bluem options update_option('bluem_woocommerce_options', $bluem_options); @@ -1373,81 +1375,7 @@ function bluem_error_report_email( $data = [] ): bool { return false; } -/** - * Registration reporting email functionality - * @return bool - */ -function bluem_registration_report_email( $data = [] ): bool -{ - $bluem_options = get_option( 'bluem_woocommerce_options' ); - $bluem_registration = get_option( 'bluem_woocommerce_registration' ); - - $dependency_bluem_php_version = get_composer_dependency_version('bluem-development/bluem-php'); - - $activation_report_id = date( "Ymdhis" ) . '_' . rand( 0, 512 ); - - $data = (object) $data; - $data->activation_report_id = $activation_report_id; - $data->{'Bluem SenderID'} = $bluem_options['senderID'] ?? ''; - $data->{'Website name'} = get_bloginfo( 'name' ); - $data->{'Website URL'} = get_bloginfo( 'url' ); - $data->{'Company name'} = $bluem_registration['company']['name']; - $data->{'Company telephone'} = $bluem_registration['company']['telephone']; - $data->{'Company email'} = $bluem_registration['company']['email']; - $data->{'Tech name'} = $bluem_registration['tech_contact']['name']; - $data->{'Tech telephone'} = $bluem_registration['tech_contact']['telephone']; - $data->{'Tech email'} = $bluem_registration['tech_contact']['email']; - $data->{'WooCommerce version'} = class_exists('WooCommerce') ? WC()->version : __('WooCommerce not installed', 'bluem'); - $data->{'WordPress version'} = get_bloginfo( 'version' ); - $data->{'Bluem PHP-library'} = $dependency_bluem_php_version; - $data->{'Plug-in version'} = $bluem_options['bluem_plugin_version'] ?? '0'; - $data->{'PHP version'} = phpversion(); - - if ( is_null( $data ) ) { - return false; - } - - $author_name = "Administratie van " . get_bloginfo( 'name' ); - $author_email = esc_attr( - get_option( "admin_email" ) - ); - - $to = "pluginsupport@bluem.nl"; - - $subject = "[" . get_bloginfo( 'name' ) . "] "; - $subject .= "WordPress plug-in activation"; - $message = "
WordPress plug-in activation.
$author_name <$author_email>,
Data:
" . json_encode( $data ) . "
Ga naar de site op " . home_url() . " om dit verzoek in detail te bekijken.
"; diff --git a/scripts/.env.sample b/scripts/.env.sample new file mode 100644 index 0000000..063f964 --- /dev/null +++ b/scripts/.env.sample @@ -0,0 +1,2 @@ +MAILJET_API_KEY= +MAILJET_SECRET_KEY= diff --git a/scripts/loadenv.sh b/scripts/loadenv.sh new file mode 100755 index 0000000..4abc168 --- /dev/null +++ b/scripts/loadenv.sh @@ -0,0 +1,11 @@ +#!/bin/bash +EMAIL=d.rijpkema@bluem.nl +export $(cat .env | xargs) +echo "Loaded keys: ${MAILJET_API_KEY} ${MAILJET_SECRET_KEY}" +curl -s \ + -X POST \ + --user "$MAILJET_API_KEY:$MAILJET_SECRET_KEY" \ + "https://api.mailjet.com/v3.1/send" \ + -H "Content-Type: application/json" \ + -d '{"Messages":[{"From":{"Email":"d.rijpkema@bluem.nl","Name":"Your Name"},"To":[{"Email":"pluginsupport@bluem.nl","Name":"Pluginsupport"}],"Subject":"Release Completed","TextPart":"Release $(NEW_TAG) of $(PLUGIN_SLUG) has been completed. (test)"}]}' \ + && echo "\nNotification email sent to $EMAIL}" diff --git a/src/Observability/BluemActivationNotifier.php b/src/Observability/BluemActivationNotifier.php new file mode 100644 index 0000000..6e544f3 --- /dev/null +++ b/src/Observability/BluemActivationNotifier.php @@ -0,0 +1,111 @@ +createReportData(); + + $author_name = "Administratie van " . esc_attr(get_bloginfo('name')); + $author_email = esc_attr( + get_option("admin_email") + ); + + $to = self::NOTIFICATION_EMAIL; + + $subject = "[" . get_bloginfo('name') . "] WordPress plug-in activation"; + + $message = sprintf("WordPress plug-in activation (door %s <%s>),
", $author_name, $author_email); + $message .= sprintf("Data:
%s
Raw Data:
%s