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

New Plugin workflow_notification #92

Merged
merged 21 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 10 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
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ INSERT INTO `#__workflow_transitions` (`id`, `asset_id`, `published`, `ordering`
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(0, 'com_workflow', 'component', 'com_workflow', '', 1, 1, 0, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);

--
-- Creating Associations for existing content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ INSERT INTO "#__workflow_transitions" ("id", "asset_id", "published", "ordering"
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "checked_out", "checked_out_time", "ordering", "state") VALUES
(0, 'com_workflow', 'component', 'com_workflow', '', 1, 1, 0, 0, '', '{}', 0, '1970-01-01 00:00:00', 0, 0),
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);

(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);
--
-- Creating Associations for existing content
--
Expand Down
4 changes: 0 additions & 4 deletions administrator/language/en-GB/plg_content_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_DESC="Check that categories are fully
PLG_CONTENT_JOOMLA_FIELD_CHECK_CATEGORIES_LABEL="Check Category Deletion"
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_DESC="Email users if 'Send email' is on when there is a new article submitted via the Frontend."
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_FE_LABEL="Email on New Site Article"
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_STAGE_DESC="Email users if 'Send email' is on when there is a status change of an article."
PLG_CONTENT_JOOMLA_FIELD_EMAIL_NEW_STAGE_LABEL="Email on transition execution"
PLG_CONTENT_JOOMLA_ON_STAGE_CHANGE_MSG="The status of an article has been changed by '%1$s' entitled '%2$s'."
PLG_CONTENT_JOOMLA_ON_STAGE_CHANGE_SUBJECT="Status of article has changed"
PLG_CONTENT_JOOMLA_XML_DESCRIPTION="This plugin does category processing for core extensions; sends an email when new article is submitted in the Frontend or a transition is executed."
23 changes: 23 additions & 0 deletions administrator/language/en-GB/plg_workflow_notification.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_WORKFLOW_NOTIFICATION_FIELDSET_LABEL="Notification"
PLG_WORKFLOW_NOTIFICATION="Workflow - Notification"
PLG_WORKFLOW_NOTIFICATION_ADDTEXT="The state has changed"
PLG_WORKFLOW_NOTIFICATION_ADDTEXT_AUTHOR_DESC="You can localise the text by using a Language key and make language overrides."
PLG_WORKFLOW_NOTIFICATION_ADDTEXT_AUTHOR_LABEL="Additional Message to Author"
PLG_WORKFLOW_NOTIFICATION_ADDTEXT_DESC="You can localise the text by using a Language key and make language overrides."
PLG_WORKFLOW_NOTIFICATION_ADDTEXT_LABEL="Additional Message Text"
PLG_WORKFLOW_NOTIFICATION_EMAIL_AUTHOR_LABEL="Email the Author"
PLG_WORKFLOW_NOTIFICATION_ON_TRANSITION_SUBJECT="The status of an '%1$s' has been changed";
PLG_WORKFLOW_NOTIFICATION_ON_TRANSITION_MSG="Title: '%1$s', Changed by '%2$s', New State: '%3$s'."
PLG_WORKFLOW_NOTIFICATION_RECEIVERS_LABEL="More Receivers"
PLG_WORKFLOW_NOTIFICATION_RECEIVERS_SELECT="Select single receivers for the notification"
PLG_WORKFLOW_NOTIFICATION_SENDMAIL_LABEL="Send Notification"
PLG_WORKFLOW_NOTIFICATION_USERGROUP_DESC="The users in this usergroup get an E-Mail if this transition has been performed"
PLG_WORKFLOW_NOTIFICATION_USERGROUP_LABEL="Usergroups"
PLG_WORKFLOW_NOTIFICATION_USERGROUP_SELECT="Select usergroups"
PLG_WORKFLOW_NOTIFICATION_XML_DESCRIPTION="Send Notification if a Transition has been performed in a Workflow"

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_WORKFLOW_NOTIFICATION="Workflow - Notification"
PLG_WORKFLOW_NOTIFICATION_XML_DESCRIPTION="Send Notification for Transitions in Publishing Workflow"
3 changes: 2 additions & 1 deletion installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0);
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0);

-- Templates
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
Expand Down
3 changes: 2 additions & 1 deletion installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0);
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, 1, '', '{}', 0, NULL, 0, 0);

-- Templates
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "checked_out", "checked_out_time", "ordering", "state") VALUES
Expand Down
95 changes: 6 additions & 89 deletions plugins/content/joomla/joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,6 @@ public function onContentChangeState($context, $pks, $value)
return true;
}

// Check if this function is enabled.
if (!$this->params->def('email_new_stage', 0) || $context != 'com_content.article')
chmst marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}

$db = $this->db;
$query = $db->getQuery(true)
->select($db->quoteName('core_content_id'))
Expand All @@ -634,89 +628,6 @@ public function onContentChangeState($context, $pks, $value)
$cctable = new CoreContent($db);
$cctable->publish($ccIds, $value);

$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
->where($db->quoteName('sendEmail') . ' = 1')
->where($db->quoteName('block') . ' = 0');

$users = (array) $db->setQuery($query)->loadColumn();

if (empty($users))
{
return true;
}

$user = $this->app->getIdentity();

// Messaging for changed items
$default_language = ComponentHelper::getParams('com_languages')->get('administrator');
$debug = $this->app->get('debug_lang');

$article = new ArticleTable($db);

$workflow = new Workflow(['extension' => 'com_content.article']);

foreach ($pks as $pk)
{
if (!$article->load($pk))
{
continue;
}

$assoc = $workflow->getAssociation($pk);
$stageId = (int) $assoc->stage_id;

// Load new transitions
$query = $db->getQuery(true)
->select($db->quoteName('t.id'))
->from($db->quoteName('#__workflow_transitions', 't'))
->from($db->quoteName('#__workflow_stages', 's'))
->where($db->quoteName('t.from_stage_id') . ' = :stageid')
->where($db->quoteName('t.to_stage_id') . ' = ' . $db->quoteName('s.id'))
->where($db->quoteName('t.published') . ' = 1')
->where($db->quoteName('s.published') . ' = 1')
->order($db->quoteName('t.ordering'))
->bind(':stageid', $stageId, ParameterType::INTEGER);

$transitions = $db->setQuery($query)->loadObjectList();

foreach ($users as $user_id)
{
if ($user_id != $user->id)
{
// Check if the user has available transitions
$items = array_filter(
$transitions,
function ($item) use ($user)
{
return $user->authorise('core.execute.transition', 'com_content.transition.' . $item->id);
}
);

if (!count($items))
{
continue;
}

// Load language for messaging
$receiver = User::getInstance($user_id);
$lang = Language::getInstance($receiver->getParam('admin_language', $default_language), $debug);
$lang->load('plg_content_joomla');

$message = array(
'user_id_to' => $user_id,
'subject' => $lang->_('PLG_CONTENT_JOOMLA_ON_STAGE_CHANGE_SUBJECT'),
'message' => sprintf($lang->_('PLG_CONTENT_JOOMLA_ON_STAGE_CHANGE_MSG'), $user->name, $article->title),
);

$model_message = $this->app->bootComponent('com_messages')
->getMVCFactory()->createModel('Message', 'Administrator');
$model_message->save($message);
}
}
}

return true;
}

Expand All @@ -734,6 +645,12 @@ function ($item) use ($user)
*/
private function checkMenuItemBeforeSave($context, $table, $isNew, $data)
{
// Check if this function is enabled.
if ($context != 'com_content.article')
{
return true;
}

chmst marked this conversation as resolved.
Show resolved Hide resolved
// Check we are handling the frontend edit form.
if ($context === 'com_menus.item')
{
Expand Down
66 changes: 66 additions & 0 deletions plugins/workflow/notification/forms/workflow_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="options">
<fieldset name="notification">
<field
name="send_mail"
chmst marked this conversation as resolved.
Show resolved Hide resolved
type="radio"
label="PLG_WORKFLOW_NOTIFICATION_SENDMAIL_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
filter="boolean"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
chmst marked this conversation as resolved.
Show resolved Hide resolved
name="text"
type="textarea"
label="PLG_WORKFLOW_NOTIFICATION_ADDTEXT_LABEL"
description="PLG_WORKFLOW_NOTIFICATION_ADDTEXT_DESC"
rows="3"
filter="safehtml"
/>
<field
name="groups"
type="usergrouplist"
label="PLG_WORKFLOW_NOTIFICATION_USERGROUP_LABEL"
description="PLG_WORKFLOW_NOTIFICATION_USERGROUP_DESC"
multiple="true"
layout="joomla.form.field.list-fancy-select"
default="0"
/>
<field
name="receivers"
type="sql"
label="PLG_WORKFLOW_NOTIFICATION_RECEIVERS_LABEL"
desc="PLG_WORKFLOW_NOTIFICATION_RECEIVERS_DESC"
query="SELECT id, name FROM #__users WHERE block=0 ORDER BY name ASC"
key_field="id"
value_field="name"
multiple="true"
layout="joomla.form.field.list-fancy-select"
/>
<field
name="email-author"
type="radio"
label="PLG_WORKFLOW_NOTIFICATION_EMAIL_AUTHOR_LABEL"
layout="joomla.form.field.radio.switcher"
default="0"
filter="boolean"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
name="text_author"
type="textarea"
label="PLG_WORKFLOW_NOTIFICATION_ADDTEXT_AUTHOR_LABEL"
description="PLG_WORKFLOW_NOTIFICATION_ADDTEXT_AUTHOR_DESC"
rows="3"
filter="safehtml"
showon="email-author:1"
/>
</fieldset>
</fields>
</form>
Loading