Updated CMS:

Extract email service as a library.
Updated modules to use the email library.
Fixed compilation issue with database_connection_null.e
This commit is contained in:
jvelilla
2015-06-24 11:17:17 -03:00
parent fa5efede2c
commit 7c0032ada4
6 changed files with 23 additions and 4 deletions

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="email_service" uuid="261DC9D5-C3A0-498D-A063-0BB6C80423CC" library_target="email_service">
<target name="email_service">
<root all_classes="true"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms_app_env" location="..\app_env\app_env-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,102 @@
note
description: "Basic Email Service"
date: "$Date: 2015-04-30 05:45:25 -0300 (ju. 30 de abr. de 2015) $"
revision: "$Revision: 97218 $"
class
EMAIL_SERVICE
inherit
SHARED_ERROR
SHARED_LOGGER
create
make
feature {NONE} -- Initialization
make (a_params: like parameters)
-- Create instance of {EMAIL_SERVICE} with smtp_server `a_params.smtp_server'.
-- Using `a_params.admin_email' as admin email.
do
parameters := a_params
initialize
end
initialize
-- Initialize service.
local
l_address_factory: INET_ADDRESS_FACTORY
do
admin_email := parameters.admin_email
-- Get local host name needed in creation of SMTP_PROTOCOL.
create l_address_factory
create smtp_protocol.make (parameters.smtp_server, l_address_factory.create_localhost.host_name)
set_successful
end
parameters: EMAIL_SERVICE_PARAMETERS
-- Associated parameters.
admin_email: IMMUTABLE_STRING_8
-- Site admin's email.
smtp_protocol: SMTP_PROTOCOL
-- SMTP protocol.
feature -- Basic Operations
send_internal_email (a_content: READABLE_STRING_GENERAL)
do
send_message (admin_email, admin_email, "Notification Contact", a_content)
end
send_email_internal_server_error (a_content: READABLE_STRING_GENERAL)
do
send_message (admin_email, admin_email, "Internal Server Error", a_content)
end
send_message (a_from_address, a_to_address: READABLE_STRING_8; a_subjet: READABLE_STRING_GENERAL; a_content: READABLE_STRING_GENERAL)
local
l_email: EMAIL
utf: UTF_CONVERTER
do
write_debug_log (generator + ".send_message: [from:" + a_from_address + ", to:" + a_to_address + ", subject:" + a_subjet + ", content:" + a_content)
create l_email.make_with_entry (a_from_address, a_to_address)
l_email.set_message (utf.escaped_utf_32_string_to_utf_8_string_8 (a_content))
l_email.add_header_entry ({EMAIL_CONSTANTS}.H_subject, utf.escaped_utf_32_string_to_utf_8_string_8 (a_subjet))
l_email.add_header_entry ("MIME-Version:", "1.0")
l_email.add_header_entry ("Content-Type", "text/html; charset=utf-8")
send_email (l_email)
end
feature {NONE} -- Implementation
send_email (a_email: EMAIL)
-- Send the email represented by `a_email'.
local
l_retried: BOOLEAN
do
if not l_retried then
write_information_log (generator + ".send_email Process send email.")
smtp_protocol.initiate_protocol
smtp_protocol.transfer (a_email)
smtp_protocol.close_protocol
write_information_log (generator + ".send_email Email sent.")
if smtp_protocol.error then
set_last_error ("smtp_protocol reported an error", generator + ".send_email")
else
set_successful
end
else
write_error_log (generator + ".send_email Email not send " + last_error_message )
end
rescue
set_last_error_from_exception (generator + ".send_email")
l_retried := True
retry
end
end

View File

@@ -0,0 +1,20 @@
note
description: "Basic Email Service customized for cms site"
author: ""
date: "$Date: 2015-01-16 07:17:14 -0300 (vi. 16 de ene. de 2015) $"
revision: "$Revision: 96467 $"
deferred class
EMAIL_SERVICE_PARAMETERS
feature -- Access
smtp_server: IMMUTABLE_STRING_8
deferred
end
admin_email: IMMUTABLE_STRING_8
deferred
end
end

View File

@@ -23,9 +23,9 @@ feature -- Initialization
-- Create a database handler for ODBC with common settings.
do
create database_error_handler.make
create db_application.login (username, password)
db_application.set_hostname (hostname)
db_application.set_data_source (database_name)
create db_application.login (default_username, default_password)
db_application.set_hostname (default_username)
db_application.set_data_source (default_database_name)
db_application.set_base
create db_control.make
end